mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 06:41:42 +08:00
next_thread_id to use atomics, not locks
We have multiple places where we use std::atomic<uint64_t>, so let's use it in next_thread_id too.
This commit is contained in:
parent
fe334bf620
commit
b7e892d545
|
@ -490,9 +490,10 @@ bool make_detached_pthread(void_func_t &&func) {
|
|||
|
||||
static uint64_t next_thread_id() {
|
||||
// Note 0 is an invalid thread id.
|
||||
static owning_lock<uint64_t> s_last_thread_id{};
|
||||
auto tid = s_last_thread_id.acquire();
|
||||
return ++*tid;
|
||||
// Note fetch_add is a CAS which returns the value *before* the modification.
|
||||
static std::atomic<uint64_t> s_last_thread_id{};
|
||||
uint64_t res = 1 + s_last_thread_id.fetch_add(1, std::memory_order_relaxed);
|
||||
return res;
|
||||
}
|
||||
|
||||
uint64_t thread_id() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user