CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
seq_lock.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_THREADS_SEQLOCK_H
10#define CPPCOMMON_THREADS_SEQLOCK_H
11
12#include <atomic>
13#include <cstring>
14
15namespace CppCommon {
16
18
29template <typename T>
31{
32public:
33 SeqLock();
34 explicit SeqLock(const T& data);
35 SeqLock(const SeqLock&) = delete;
36 SeqLock(SeqLock&&) = default;
37 ~SeqLock() = default;
38
39 SeqLock& operator=(const T& data) noexcept;
40 SeqLock& operator=(const SeqLock&) = delete;
42
44
49 T Read() const noexcept;
50
52
57 void Write(const T& data) noexcept;
58
59private:
60 typedef char cache_line_pad[128];
61
62 cache_line_pad _pad0;
63 T _data;
64 std::atomic<size_t> _seq;
65 cache_line_pad _pad1;
66};
67
70} // namespace CppCommon
71
72#include "seq_lock.inl"
73
74#endif // CPPCOMMON_THREADS_SEQLOCK_H
Sequential lock synchronization primitive.
Definition seq_lock.h:31
void Write(const T &data) noexcept
Write data under the sequential lock.
Definition seq_lock.inl:51
SeqLock & operator=(const SeqLock &)=delete
T Read() const noexcept
Read data under the sequential lock.
Definition seq_lock.inl:32
SeqLock & operator=(const T &data) noexcept
Definition seq_lock.inl:25
SeqLock(SeqLock &&)=default
SeqLock & operator=(SeqLock &&)=delete
SeqLock(const SeqLock &)=delete
C++ Common project definitions.