dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
thread_id.cpp
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#include <dispenso/thread_id.h>
9
10namespace dispenso {
11
12std::atomic<uint64_t> nextThread{0};
13constexpr uint64_t kInvalidThread = std::numeric_limits<uint64_t>::max();
14DISPENSO_THREAD_LOCAL uint64_t currentThread = kInvalidThread;
15
16uint64_t threadId() {
17 if (currentThread == kInvalidThread) {
18 currentThread = nextThread.fetch_add(uint64_t{1}, std::memory_order_relaxed);
19 }
20 return currentThread;
21}
22
23} // namespace dispenso