mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 04:41:14 -03: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:
@@ -490,9 +490,10 @@ bool make_detached_pthread(void_func_t &&func) {
|
|||||||
|
|
||||||
static uint64_t next_thread_id() {
|
static uint64_t next_thread_id() {
|
||||||
// Note 0 is an invalid thread id.
|
// Note 0 is an invalid thread id.
|
||||||
static owning_lock<uint64_t> s_last_thread_id{};
|
// Note fetch_add is a CAS which returns the value *before* the modification.
|
||||||
auto tid = s_last_thread_id.acquire();
|
static std::atomic<uint64_t> s_last_thread_id{};
|
||||||
return ++*tid;
|
uint64_t res = 1 + s_last_thread_id.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t thread_id() {
|
uint64_t thread_id() {
|
||||||
|
|||||||
Reference in New Issue
Block a user