aboutsummaryrefslogtreecommitdiff
path: root/computer-network-experiment/ReadWriteLock.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-08 20:22:21 +0800
committercrupest <crupest@outlook.com>2021-06-08 20:22:21 +0800
commitbb0bf92282a107e1e292ef7da84ad6468bed083c (patch)
treed27e7b1165bca4525244d7fb972e7604d0eee5ba /computer-network-experiment/ReadWriteLock.h
parentebf48992df78210131035c7e39664b69cb23b2ca (diff)
downloadlife-bb0bf92282a107e1e292ef7da84ad6468bed083c.tar.gz
life-bb0bf92282a107e1e292ef7da84ad6468bed083c.tar.bz2
life-bb0bf92282a107e1e292ef7da84ad6468bed083c.zip
...
Diffstat (limited to 'computer-network-experiment/ReadWriteLock.h')
-rw-r--r--computer-network-experiment/ReadWriteLock.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/computer-network-experiment/ReadWriteLock.h b/computer-network-experiment/ReadWriteLock.h
new file mode 100644
index 0000000..c9889da
--- /dev/null
+++ b/computer-network-experiment/ReadWriteLock.h
@@ -0,0 +1,40 @@
+#pragma once
+#include "Common.h"
+
+#include <memory>
+
+#ifdef WIN32
+#include <Windows.h>
+#else
+#endif
+
+namespace cru {
+class ReadWriteLock {
+public:
+ ReadWriteLock();
+
+ ReadWriteLock(ReadWriteLock &&other);
+ ReadWriteLock &operator=(ReadWriteLock &&other);
+
+ ~ReadWriteLock();
+
+public:
+ void ReadLock();
+ void WriteLock();
+
+ bool ReadTryLock();
+ bool WriteTryLock();
+
+ void ReadUnlock();
+ void WriteUnlock();
+
+private:
+ void Destroy();
+
+private:
+#ifdef WIN32
+ std::unique_ptr<SRWLOCK> lock_;
+#else
+#endif
+};
+} // namespace cru