Skip to content

Commit

Permalink
moar comments and removed unwrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Nov 12, 2024
1 parent 30bda2a commit 1b4be1c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion profiling/src/profiling/thread_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub fn join_timeout(handle: JoinHandle<()>, timeout: Duration, impact: &str) {
}

thread_local! {
/// This is a cache for the thread name. It will not change after the thread has been
/// created, as SAPI's do not change thread names and ext-pthreads / ext-parallel do not
/// provide an interface for renaming a thread.
static THREAD_NAME: OnceCell<String> = const { OnceCell::new() };
}

Expand Down Expand Up @@ -106,7 +109,7 @@ pub fn get_current_thread_name() -> String {
// If successful, convert the result to a Rust String
let cstr =
unsafe { std::ffi::CStr::from_ptr(name.as_ptr() as *const c_char) };
let str_slice: &str = cstr.to_str().unwrap();
let str_slice: &str = cstr.to_str().unwrap_or_default();
if !str_slice.is_empty() {
thread_name.push_str(": ");
thread_name.push_str(str_slice);
Expand Down

0 comments on commit 1b4be1c

Please sign in to comment.