-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_tid.h
More file actions
33 lines (25 loc) · 789 Bytes
/
test_tid.h
File metadata and controls
33 lines (25 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <dispenso/platform.h>
// Note that this header is intended for direct inclusion into test cpps that require the
// functionality. tids are essentially independent for tranlation units (don't expect
// coordinated/sane behavior if used from multiple cpps in the same binary).
namespace {
std::atomic<int> g_nextTid(0);
DISPENSO_THREAD_LOCAL int g_tid = -1;
inline void resetTestTid() {
g_tid = -1;
g_nextTid.store(0);
}
inline int getTestTid() {
if (g_tid < 0) {
g_tid = g_nextTid.fetch_add(1, std::memory_order_relaxed);
}
return g_tid;
}
} // namespace