forked from khizmax/libcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhp_thread_local.cpp
54 lines (44 loc) · 1.6 KB
/
hp_thread_local.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2020-2020 Alexander Gaev
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <cds/gc/hp.h>
#include <map>
namespace cds { namespace gc { namespace hp { namespace details {
#ifdef CDS_DISABLE_CLASS_TLS_INLINE
// MSVC
namespace {
// for DefaultTLS Manager
thread_local thread_data* default_tls_manager_ = nullptr;
} // namespace
/*static*/ CDS_EXPORT_API thread_data* DefaultTLSManager::getTLS() noexcept
{
return default_tls_manager_;
}
/*static*/ CDS_EXPORT_API void DefaultTLSManager::setTLS( thread_data* td ) noexcept
{
default_tls_manager_ = td;
}
#else
// GCC, CLang
thread_local thread_data* DefaultTLSManager::tls_ = nullptr;
#endif
// for StrangeTLSManager
thread_local std::pair<thread_data *, thread_data *> *tls2_ = new std::pair<thread_data *, thread_data *>(
nullptr,
nullptr);
/*static*/ CDS_EXPORT_API thread_data *StrangeTLSManager::getTLS() {
if ((uintptr_t) cds::OS::get_current_thread_id() % 2 == 0) { // % 2 with ThreadId structure?
return tls2_->second;
} else {
return tls2_->first;
}
}
/*static*/ CDS_EXPORT_API void StrangeTLSManager::setTLS(thread_data *new_tls) {
if ((uintptr_t) cds::OS::get_current_thread_id() % 2 == 0) { // % 2 with ThreadId structure?
tls2_->second = new_tls;
} else {
tls2_->first = new_tls;
}
}
}}}} // namespace cds::gc::hp::details