Skip to content

Commit

Permalink
set_thread_name! fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
den-mentiei committed Jan 31, 2024
1 parent a7360b5 commit d2de912
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `#[capture]` attribute to instrument main added.
- `#[instrument("prefix")]` is now supported.
- `emit_alloc!` & `emit_free!` to track allocations.
- memory example

### Fixed

Expand Down
36 changes: 24 additions & 12 deletions tracy-gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,40 @@ pub use plot::*;
/// });
/// ```
#[macro_export]
#[cfg(any(doc, feature = "enabled"))]
macro_rules! set_thread_name {
($name:literal) => {
// @Bug It doesn't work this way.
#[cfg(feature = "enabled")]
// SAFETY: We null-terminate the string.
unsafe {
$crate::details::set_thread_name(concat!($name, '\0').as_ptr());
}
};

($format:literal, $($args:expr),*) => {
// @Bug It doesn't work this way.
#[cfg(feature = "enabled")]
{
let name = format!(concat!($format, '\0'), $($args),*).into_bytes();
// SAFETY: We null-terminated the string during formatting.
unsafe {
let name = std::ffi::CString::from_vec_with_nul_unchecked(name);
$crate::details::set_thread_name(name.as_ptr().cast());
}
($format:literal, $($args:expr),*) => {{
let name = format!(concat!($format, '\0'), $($args),*).into_bytes();
// SAFETY: We null-terminated the string during formatting.
unsafe {
let name = std::ffi::CString::from_vec_with_nul_unchecked(name);
$crate::details::set_thread_name(name.as_ptr().cast());
}
}};
}

#[macro_export]
#[cfg(all(not(doc), not(feature = "enabled")))]
macro_rules! set_thread_name {
($name:literal) => {
// Silence unused expression warning.
_ = $name;
};

($format:literal, $($args:expr),*) => {{
// Silence unused expression warnings.
_ = $format;
$(
_ = $args;
)*
}};
}

/// Sends a message to Tracy's log.
Expand Down

0 comments on commit d2de912

Please sign in to comment.