Skip to main content

luaur_common/functions/
release_thread.rs

1//! Source: `Common/src/TimeTrace.cpp:134-140` (hand-ported)
2//! C++:
3//! ```cpp
4//! void releaseThread(GlobalContext& context, ThreadContext* threadContext)
5//! {
6//!     std::scoped_lock lock(context.mutex);
7//!     if (auto it = std::find(context.threads.begin(), context.threads.end(), threadContext); it != context.threads.end())
8//!         context.threads.erase(it);
9//! }
10//! ```
11use crate::records::global_context::GlobalContext;
12use crate::records::thread_context::ThreadContext;
13
14pub fn release_thread(context: &GlobalContext, thread_context: *mut ThreadContext) {
15    let mut state = context
16        .state
17        .lock()
18        .expect("TimeTrace GlobalContext mutex poisoned");
19
20    if let Some(pos) = state.threads.iter().position(|t| t.0 == thread_context) {
21        state.threads.remove(pos);
22    }
23}