Skip to main content

luaur_common/functions/
create_thread.rs

1//! Source: `Common/src/TimeTrace.cpp:125-132` (hand-ported)
2//! C++:
3//! ```cpp
4//! uint32_t createThread(GlobalContext& context, ThreadContext* threadContext)
5//! {
6//!     std::scoped_lock lock(context.mutex);
7//!     context.threads.push_back(threadContext);
8//!     return ++context.nextThreadId;
9//! }
10//! ```
11use crate::records::global_context::{GlobalContext, ThreadPtr};
12use crate::records::thread_context::ThreadContext;
13
14pub fn create_thread(context: &GlobalContext, thread_context: *mut ThreadContext) -> u32 {
15    let mut state = context
16        .state
17        .lock()
18        .expect("TimeTrace GlobalContext mutex poisoned");
19
20    state.threads.push(ThreadPtr(thread_context));
21
22    state.next_thread_id += 1;
23    state.next_thread_id
24}