Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: src/core/SkSharedMutex.h

Issue 1215503005: Implement shared locks in the style of pthread's rwlock. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reformat test case. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkSharedMutex.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkSharedMutex.h
diff --git a/src/core/SkSharedMutex.h b/src/core/SkSharedMutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..a020f9e1be94b3fd5fc3b2625609069320b75602
--- /dev/null
+++ b/src/core/SkSharedMutex.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSharedLock_DEFINED
+#define SkSharedLock_DEFINED
+
+#include "SkAtomics.h"
+#include "SkSemaphore.h"
+#include "SkTypes.h"
+
+// This is a shared lock implementation similar to pthreads rwlocks. This implementation is
+// cribbed from Preshing's article:
+// http://preshing.com/20150316/semaphores-are-surprisingly-versatile/
+//
+// This lock does not obey strict queue ordering. It will always alternate between readers and
+// a single writer.
+class SkSharedMutex {
+public:
+ SkSharedMutex();
+
+ // Acquire lock for exclusive use.
+ void acquire();
+
+ // Release lock for exclusive use.
+ void release();
+
+ // Acquire lock for shared use.
+ void acquireShared();
+
+ // Release lock for shared use.
+ void releaseShared();
+
+private:
+ SkAtomic<int32_t> fQueueCounts;
+ SkSemaphore fSharedQueue;
+ SkSemaphore fExclusiveQueue;
+};
+
+#endif // SkSharedLock_DEFINED
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkSharedMutex.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698