File tree 3 files changed +31
-0
lines changed 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
11
11
12
12
- Added ` IPV6_V6ONLY ` sockopt.
13
13
(#[ 1470] ( https://github.com/nix-rust/nix/pull/1470 ) )
14
+ - Added ` pthread_kill ` .
15
+ (#[ 1472] ( https://github.com/nix-rust/nix/pull/1472 ) )
14
16
15
17
### Changed
16
18
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 ;
1
7
use libc:: { self , pthread_t} ;
2
8
3
9
pub type Pthread = pthread_t ;
@@ -11,3 +17,19 @@ pub type Pthread = pthread_t;
11
17
pub fn pthread_self ( ) -> Pthread {
12
18
unsafe { libc:: pthread_self ( ) }
13
19
}
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() {
13
13
let tid = pthread_self ( ) ;
14
14
assert ! ( tid != 0 ) ;
15
15
}
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