diff options
author | crupest <crupest@outlook.com> | 2021-06-08 20:22:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-08 20:22:21 +0800 |
commit | a84887356487a4fcbd57a90f3ce17914ea8bdd0a (patch) | |
tree | a896769a28b73aa10f41b6c0359ec78ce7f2563b /works/life/computer-network-experiment/ReadWriteLock.h | |
parent | 53717298fda9bffed5f8d9201db47f3fd09fa612 (diff) | |
download | crupest-a84887356487a4fcbd57a90f3ce17914ea8bdd0a.tar.gz crupest-a84887356487a4fcbd57a90f3ce17914ea8bdd0a.tar.bz2 crupest-a84887356487a4fcbd57a90f3ce17914ea8bdd0a.zip |
import(life): ...
Diffstat (limited to 'works/life/computer-network-experiment/ReadWriteLock.h')
-rw-r--r-- | works/life/computer-network-experiment/ReadWriteLock.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/works/life/computer-network-experiment/ReadWriteLock.h b/works/life/computer-network-experiment/ReadWriteLock.h new file mode 100644 index 0000000..c9889da --- /dev/null +++ b/works/life/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
|