aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/global/variable.h
blob: 8b1a6c92a9985fd0a90fe0fde5781065f49e9279 (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
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include "access.h"

namespace NYT::NGlobal {

////////////////////////////////////////////////////////////////////////////////

namespace NDetail {

// Defined in impl.cpp.
void RegisterVariable(const TVariableTag& tag, TAccessor accessor);

} // namespace NDetail

////////////////////////////////////////////////////////////////////////////////

template <CTriviallyErasable<GlobalVariableMaxByteSize> T>
class TVariable
{
public:
    TVariable(
        const TVariableTag& tag,
        TAccessor accessor,
        T initValue = {}) noexcept;

    TVariable(const TVariable& other) = delete;
    TVariable& operator=(const TVariable& other) = delete;

    T Get() const noexcept;
    void Set(T value) noexcept;

private:
    // NB(arkady-e1ppa): Ban TVariable<TVariable<T>>.
    static_assert(!requires (T t) {
        [] <class U> (TVariable<U>&) { } (t);
    });

    T Value_;
};

////////////////////////////////////////////////////////////////////////////////

#define YT_DEFINE_TRACKED_GLOBAL(Type, Name, Tag, InitExpr)
#define YT_DEFINE_TRACKED_THREAD_LOCAL(Type, Name, Tag, ...)

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NGlobal

#define GLOBAL_VARIABLE_INL_H_
#include "variable-inl.h"
#undef GLOBAL_VARIABLE_INL_H_