summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/atomic-inl.h
blob: 7408d171d6962843c95bfc1ab691ef2e2ab43daf (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
#ifndef ATOMIC_INL_H_
#error "Direct inclusion of this file is not allowed, include atomic.h"
// For the sake of sane code completion.
#include "atomic.h"
#endif

namespace NYT {

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

template <class T>
T SingleWriterFetchAdd(std::atomic<T>& atomic, T delta)
{
    auto oldValue = atomic.load(std::memory_order::relaxed);
    atomic.store(oldValue + delta, std::memory_order::relaxed);
    return oldValue;
}

template <class T>
T SingleWriterFetchSub(std::atomic<T>& atomic, T delta)
{
    auto oldValue = atomic.load(std::memory_order::relaxed);
    atomic.store(oldValue - delta, std::memory_order::relaxed);
    return oldValue;
}

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

} // namespace NYT