aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/actor/thread_extra.h
blob: 5e8e271beb3e9cfd6284e564a5723d3ae97523d0 (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;
}