Chromium Code Reviews| Index: src/core/SkSharedMutex.h |
| diff --git a/src/core/SkSharedMutex.h b/src/core/SkSharedMutex.h |
| index f3430040e38b51ee05ddb9d2915db44a30ff6ec3..eca403f003db5321b0e2f13e4092235010628706 100644 |
| --- a/src/core/SkSharedMutex.h |
| +++ b/src/core/SkSharedMutex.h |
| @@ -11,9 +11,16 @@ |
| #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: |
| + |
| +#ifdef SK_DEBUG |
| + #include "SkMutex.h" |
| + #include "../private/SkUniquePtr.h" |
| +#endif // SK_DEBUG |
| + |
| +// There are two shared lock implementations one debug the other is high performance. They implement |
| +// an interface similar to pthread's rwlocks. |
| +// This is a shared lock implementation similar to pthreads rwlocks. The high performance |
| +// 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 |
| @@ -29,11 +36,7 @@ public: |
| void release(); |
| // Fail if exclusive is not held. |
| -#ifdef SK_DEBUG |
| void assertHeld() const; |
| -#else |
| - void assertHeld() const {} |
| -#endif |
| // Acquire lock for shared use. |
| void acquireShared(); |
| @@ -42,17 +45,28 @@ public: |
| void releaseShared(); |
| // Fail if shared lock not held. |
| -#ifdef SK_DEBUG |
| void assertHeldShared() const; |
| -#else |
| - void assertHeldShared() const {} |
| -#endif |
| private: |
| - SkAtomic<int32_t> fQueueCounts; |
| - SkSemaphore fSharedQueue; |
| +#ifdef SK_DEBUG |
| + class ThreadIDSet; |
| + skstd::unique_ptr<ThreadIDSet>fCurrentShared; |
|
mtklein
2015/09/17 22:07:24
sssppace
|
| + skstd::unique_ptr<ThreadIDSet> fWaitingExclusive; |
| + skstd::unique_ptr<ThreadIDSet> fWaitingShared; |
| + int fSharedQueueSelect{0}; |
| + mutable SkMutex fMu; |
| + SkSemaphore fSharedQueue[2]; |
| SkSemaphore fExclusiveQueue; |
| +#else |
| + SkAtomic<int32_t> fQueueCounts; |
| + SkSemaphore fSharedQueue; |
| + SkSemaphore fExclusiveQueue; |
| +#endif // SK_DEBUG |
| }; |
| +#ifndef SK_DEBUG |
| +inline void SkSharedMutex::assertHeld() const {}; |
| +inline void SkSharedMutex::assertHeldShared() const {}; |
| +#endif // SK_DEBUG |
| #endif // SkSharedLock_DEFINED |