diff --git a/src/core/SkSemaphore.cpp b/src/core/SkSemaphore.cpp index 10f2975f83..55d77d2c96 100644 --- a/src/core/SkSemaphore.cpp +++ b/src/core/SkSemaphore.cpp @@ -9,10 +9,10 @@ #include "src/core/SkLeanWindows.h" #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) - #include + #include // We've got to teach TSAN that there is a happens-before edge between - // semaphore_signal() and semaphore_wait(). + // dispatch_semaphore_signal() and dispatch_semaphore_wait(). #if __has_feature(thread_sanitizer) extern "C" void AnnotateHappensBefore(const char*, int, void*); extern "C" void AnnotateHappensAfter (const char*, int, void*); @@ -22,28 +22,22 @@ #endif struct SkSemaphore::OSSemaphore { - semaphore_t fSemaphore; + dispatch_semaphore_t fSemaphore; OSSemaphore() { - semaphore_create(mach_task_self(), &fSemaphore, SYNC_POLICY_LIFO, 0/*initial count*/); + fSemaphore = dispatch_semaphore_create(0/*initial count*/); } - ~OSSemaphore() { semaphore_destroy(mach_task_self(), fSemaphore); } + ~OSSemaphore() { dispatch_release(fSemaphore); } void signal(int n) { - while (n --> 0) { + while (n-- > 0) { AnnotateHappensBefore(__FILE__, __LINE__, &fSemaphore); - semaphore_signal(fSemaphore); + dispatch_semaphore_signal(fSemaphore); } } void wait() { - while (true) { - kern_return_t result = semaphore_wait(fSemaphore); - if (result == KERN_SUCCESS) { - AnnotateHappensAfter(__FILE__, __LINE__, &fSemaphore); - return; - } - SkASSERT(result == KERN_ABORTED); - } + dispatch_semaphore_wait(fSemaphore, DISPATCH_TIME_FOREVER); + AnnotateHappensAfter(__FILE__, __LINE__, &fSemaphore); } }; #elif defined(SK_BUILD_FOR_WIN)