Skip to content

Commit 8e0041c

Browse files
authored
Fix log::init when feature origin-thread is enabled. (#102)
`current_thread_id()` in `log::init` should be `current_id()` after commit 0d4b978. And `current_id` is simplified to avoid redundant checking `raw > 0`.
1 parent 42124c8 commit 8e0041c

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

src/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ fn init() {
3131
log::trace!(
3232
target: "origin::thread",
3333
"Main Thread[{:?}] initialized",
34-
crate::thread::current_thread_id().as_raw_nonzero()
34+
crate::thread::current_id().as_raw_nonzero()
3535
);
3636
}

src/thread/linux_raw.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -950,19 +950,14 @@ pub fn current() -> Thread {
950950
#[inline]
951951
#[must_use]
952952
pub fn current_id() -> ThreadId {
953+
// Don't use the `id` function here because it returns an `Option` to
954+
// handle the case where the thread has exited. We're querying the current
955+
// thread which we know is still running because we're on it.
953956
// SAFETY: All threads have been initialized, including the main thread
954957
// with `initialize_main`, so `current()` returns a valid pointer.
955-
unsafe {
956-
// Don't use the `thread_id` function here because it returns an
957-
// `Option` to handle the case where the thread has exited. We're
958-
// querying the current thread which we know is still running because
959-
// we're on it.
960-
let raw = current().0.as_ref().thread_id.load(SeqCst);
961-
debug_assert!(raw > 0);
962-
let tid = ThreadId::from_raw_unchecked(raw);
963-
debug_assert_eq!(tid, gettid(), "`current_id` disagrees with `gettid`");
964-
tid
965-
}
958+
let tid = unsafe { ThreadId::from_raw_unchecked(current().0.as_ref().thread_id.load(SeqCst)) };
959+
debug_assert_eq!(tid, gettid(), "`current_id` disagrees with `gettid`");
960+
tid
966961
}
967962

968963
/// Set the current thread id, after a `fork`.

0 commit comments

Comments
 (0)