aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/actor/thread_extra.h
blob: e4f37a976048f2d61c9813e5de8f9f240173237b (plain) (blame)
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
#pragma once

#include <util/thread/singleton.h>

namespace NTSAN { 
    template <typename T>
    inline void RelaxedStore(volatile T* a, T x) {
        static_assert(std::is_integral<T>::value || std::is_pointer<T>::value, "expect std::is_integral<T>::value || std::is_pointer<T>::value");
#ifdef _win_ 
        *a = x;
#else 
        __atomic_store_n(a, x, __ATOMIC_RELAXED);
#endif 
    }
 
    template <typename T>
    inline T RelaxedLoad(volatile T* a) {
#ifdef _win_ 
        return *a;
#else 
        return __atomic_load_n(a, __ATOMIC_RELAXED);
#endif 
    }
 
} 
 
void SetCurrentThreadName(const char* name);

namespace NThreadExtra {
    namespace NPrivate {
        template <typename TValue, typename TTag>
        struct TValueHolder {
            TValue Value;
        };
    }
}

template <typename TValue, typename TTag>
static inline TValue* FastTlsSingletonWithTag() {
    return &FastTlsSingleton< ::NThreadExtra::NPrivate::TValueHolder<TValue, TTag>>()->Value;
}