@@ -130,25 +130,27 @@ impl Thread {
130
130
}
131
131
}
132
132
133
- #[ cfg( target_os = "linux" ) ]
133
+ #[ cfg( any ( target_os = "linux" , target_os = "freebsd" , target_os = "dragonfly" ) ) ]
134
134
pub fn set_name ( name : & CStr ) {
135
- const TASK_COMM_LEN : usize = 16 ;
136
-
137
135
unsafe {
138
- // Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20.
139
- let name = truncate_cstr :: < { TASK_COMM_LEN } > ( name) ;
136
+ cfg_if:: cfg_if! {
137
+ if #[ cfg( target_os = "linux" ) ] {
138
+ // Linux limits the allowed length of the name.
139
+ const TASK_COMM_LEN : usize = 16 ;
140
+ let name = truncate_cstr:: <{ TASK_COMM_LEN } >( name) ;
141
+ } else {
142
+ // FreeBSD and DragonFly BSD do not enforce length limits.
143
+ }
144
+ } ;
145
+ // Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
146
+ // FreeBSD 12.2 and 13.0, and DragonFly BSD 6.0.
140
147
let res = libc:: pthread_setname_np ( libc:: pthread_self ( ) , name. as_ptr ( ) ) ;
141
148
// We have no good way of propagating errors here, but in debug-builds let's check that this actually worked.
142
149
debug_assert_eq ! ( res, 0 ) ;
143
150
}
144
151
}
145
152
146
- #[ cfg( any(
147
- target_os = "freebsd" ,
148
- target_os = "dragonfly" ,
149
- target_os = "openbsd" ,
150
- target_os = "nuttx"
151
- ) ) ]
153
+ #[ cfg( any( target_os = "openbsd" , target_os = "nuttx" ) ) ]
152
154
pub fn set_name ( name : & CStr ) {
153
155
unsafe {
154
156
libc:: pthread_set_name_np ( libc:: pthread_self ( ) , name. as_ptr ( ) ) ;
0 commit comments