File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
88
99- Added ` IPV6_V6ONLY ` sockopt.
1010 (#[ 1470] ( https://github.com/nix-rust/nix/pull/1470 ) )
11+ - Added ` pthread_kill ` .
12+ (#[ 1472] ( https://github.com/nix-rust/nix/pull/1472 ) )
1113
1214### Changed
1315
Original file line number Diff line number Diff line change 1+ #[ cfg( not( target_os = "redox" ) ) ]
2+ use crate :: errno:: Errno ;
3+ #[ cfg( not( target_os = "redox" ) ) ]
4+ use crate :: Result ;
5+ #[ cfg( not( target_os = "redox" ) ) ]
6+ use crate :: sys:: signal:: Signal ;
17use libc:: { self , pthread_t} ;
28
39pub type Pthread = pthread_t ;
@@ -11,3 +17,19 @@ pub type Pthread = pthread_t;
1117pub fn pthread_self ( ) -> Pthread {
1218 unsafe { libc:: pthread_self ( ) }
1319}
20+
21+ /// Send a signal to a thread (see [`pthread_kill(3)`]).
22+ ///
23+ /// If `signal` is `None`, `pthread_kill` will only preform error checking and
24+ /// won't send any signal.
25+ ///
26+ /// [`pthread_kill(3)`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html
27+ #[ cfg( not( target_os = "redox" ) ) ]
28+ pub fn pthread_kill < T : Into < Option < Signal > > > ( thread : Pthread , signal : T ) -> Result < ( ) > {
29+ let sig = match signal. into ( ) {
30+ Some ( s) => s as libc:: c_int ,
31+ None => 0 ,
32+ } ;
33+ let res = unsafe { libc:: pthread_kill ( thread, sig) } ;
34+ Errno :: result ( res) . map ( drop)
35+ }
Original file line number Diff line number Diff line change @@ -13,3 +13,10 @@ fn test_pthread_self() {
1313 let tid = pthread_self ( ) ;
1414 assert ! ( tid != 0 ) ;
1515}
16+
17+ #[ test]
18+ #[ cfg( not( target_os = "redox" ) ) ]
19+ fn test_pthread_kill_none ( ) {
20+ pthread_kill ( pthread_self ( ) , None )
21+ . expect ( "Should be able to send signal to my thread." ) ;
22+ }
You can’t perform that action at this time.
0 commit comments