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

Unified Diff: src/core/SkSemaphore.cpp

Issue 1947153002: Modernize SkMutex and SkSemaphore. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: this time no destructors Created 4 years, 7 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 | « include/private/SkSemaphore.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkSemaphore.cpp
diff --git a/src/core/SkSemaphore.cpp b/src/core/SkSemaphore.cpp
index da422e282f6ea8a367c187c9e81a02b347e8ad4a..2286c0b2bb37a15d375cb91ba2ae973b013b955c 100644
--- a/src/core/SkSemaphore.cpp
+++ b/src/core/SkSemaphore.cpp
@@ -57,43 +57,16 @@
///////////////////////////////////////////////////////////////////////////////
-void SkBaseSemaphore::signal(int n) {
- SkASSERT(n >= 0);
-
- // We only want to call the OS semaphore when our logical count crosses
- // from <= 0 to >0 (when we need to wake sleeping threads).
- //
- // This is easiest to think about with specific examples of prev and n.
- // If n == 5 and prev == -3, there are 3 threads sleeping and we signal
- // SkTMin(-(-3), 5) == 3 times on the OS semaphore, leaving the count at 2.
- //
- // If prev >= 0, no threads are waiting, SkTMin(-prev, n) is always <= 0,
- // so we don't call the OS semaphore, leaving the count at (prev + n).
- int prev = sk_atomic_fetch_add(&fCount, n, sk_memory_order_release);
- int toSignal = SkTMin(-prev, n);
- if (toSignal > 0) {
- this->osSignal(toSignal);
- }
+void SkBaseSemaphore::osSignal(int n) {
+ fOSSemaphoreOnce([this] { fOSSemaphore = new OSSemaphore; });
+ fOSSemaphore->signal(n);
}
-static SkBaseSemaphore::OSSemaphore* semaphore(SkBaseSemaphore* semaphore) {
- return semaphore->fOSSemaphore.get([](){ return new SkBaseSemaphore::OSSemaphore(); });
+void SkBaseSemaphore::osWait() {
+ fOSSemaphoreOnce([this] { fOSSemaphore = new OSSemaphore; });
+ fOSSemaphore->wait();
}
-void SkBaseSemaphore::osSignal(int n) { semaphore(this)->signal(n); }
-
-void SkBaseSemaphore::osWait() { semaphore(this)->wait(); }
-
-void SkBaseSemaphore::deleteSemaphore() {
- delete (OSSemaphore*) fOSSemaphore;
+void SkBaseSemaphore::cleanup() {
+ delete fOSSemaphore;
}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkSemaphore::SkSemaphore(){ fBaseSemaphore = {0, {0}}; }
-
-SkSemaphore::~SkSemaphore() { fBaseSemaphore.deleteSemaphore(); }
-
-void SkSemaphore::wait() { fBaseSemaphore.wait(); }
-
-void SkSemaphore::signal(int n) {fBaseSemaphore.signal(n); }
« no previous file with comments | « include/private/SkSemaphore.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698