std::thread: set_name implementation proposal for vxWorks. · patricklam/verify-rust-std@14fe723 (original) (raw)

`@@ -3,7 +3,12 @@ use crate::mem::{self, ManuallyDrop};

`

3

3

`use crate::num::NonZero;

`

4

4

`#[cfg(all(target_os = "linux", target_env = "gnu"))]

`

5

5

`use crate::sys::weak::dlsym;

`

6

``

`-

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]

`

``

6

`+

#[cfg(any(

`

``

7

`+

target_os = "solaris",

`

``

8

`+

target_os = "illumos",

`

``

9

`+

target_os = "nto",

`

``

10

`+

target_os = "vxworks"

`

``

11

`+

))]

`

7

12

`use crate::sys::weak::weak;

`

8

13

`use crate::sys::{os, stack_overflow};

`

9

14

`use crate::time::Duration;

`

`@@ -212,17 +217,38 @@ impl Thread {

`

212

217

`}

`

213

218

`}

`

214

219

``

``

220

`+

#[cfg(target_os = "vxworks")]

`

``

221

`+

pub fn set_name(name: &CStr) {

`

``

222

`+

// FIXME(libc): adding real STATUS, ERROR type eventually.

`

``

223

`+

weak! {

`

``

224

`+

fn taskNameSet(

`

``

225

`+

libc::TASK_ID, *mut libc::c_char

`

``

226

`+

) -> libc::c_int

`

``

227

`+

}

`

``

228

+

``

229

`+

// We can't assume taskNameSet is necessarily available.

`

``

230

`+

// VX_TASK_NAME_LEN can be found set to 31,

`

``

231

`+

// however older versions can be set to only 10.

`

``

232

`+

// FIXME(vxworks): if the minimum supported VxWorks is >= 7, the maximum length can be changed to 31.

`

``

233

`+

if let Some(f) = taskNameSet.get() {

`

``

234

`+

const VX_TASK_NAME_LEN: usize = 10;

`

``

235

+

``

236

`+

let name = truncate_cstr::<{ VX_TASK_NAME_LEN }>(name);

`

``

237

`+

let status = unsafe { f(libc::taskIdSelf(), name.as_mut_ptr()) };

`

``

238

`+

debug_assert_eq!(res, libc::OK);

`

``

239

`+

}

`

``

240

`+

}

`

``

241

+

215

242

`#[cfg(any(

`

216

243

` target_env = "newlib",

`

217

244

` target_os = "l4re",

`

218

245

` target_os = "emscripten",

`

219

246

` target_os = "redox",

`

220

``

`-

target_os = "vxworks",

`

221

247

` target_os = "hurd",

`

222

248

` target_os = "aix",

`

223

249

`))]

`

224

250

`pub fn set_name(_name: &CStr) {

`

225

``

`-

// Newlib, Emscripten, and VxWorks have no way to set a thread name.

`

``

251

`+

// Newlib and Emscripten have no way to set a thread name.

`

226

252

`}

`

227

253

``

228

254

`#[cfg(not(target_os = "espidf"))]

`

`@@ -291,6 +317,7 @@ impl Drop for Thread {

`

291

317

` target_os = "nto",

`

292

318

` target_os = "solaris",

`

293

319

` target_os = "illumos",

`

``

320

`+

target_os = "vxworks",

`

294

321

` target_vendor = "apple",

`

295

322

`))]

`

296

323

`fn truncate_cstr(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] {

`