Switch SkSemaphore to use dispatch_semaphore_t on Mac.
The dispatch_semaphore_t is a higher-level, more-efficient semaphore primitive if the cross-process capabilities of semaphore_t are not needed. Bug: chromium:1012386 Change-Id: I7c39fa6b8c015bdf7b4b2275da8165165253c2d1 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/248259 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
a4b5228e16
commit
caf025e8f5
@ -9,10 +9,10 @@
|
|||||||
#include "src/core/SkLeanWindows.h"
|
#include "src/core/SkLeanWindows.h"
|
||||||
|
|
||||||
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
||||||
#include <mach/mach.h>
|
#include <dispatch/dispatch.h>
|
||||||
|
|
||||||
// We've got to teach TSAN that there is a happens-before edge between
|
// 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)
|
#if __has_feature(thread_sanitizer)
|
||||||
extern "C" void AnnotateHappensBefore(const char*, int, void*);
|
extern "C" void AnnotateHappensBefore(const char*, int, void*);
|
||||||
extern "C" void AnnotateHappensAfter (const char*, int, void*);
|
extern "C" void AnnotateHappensAfter (const char*, int, void*);
|
||||||
@ -22,28 +22,22 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SkSemaphore::OSSemaphore {
|
struct SkSemaphore::OSSemaphore {
|
||||||
semaphore_t fSemaphore;
|
dispatch_semaphore_t fSemaphore;
|
||||||
|
|
||||||
OSSemaphore() {
|
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) {
|
void signal(int n) {
|
||||||
while (n --> 0) {
|
while (n-- > 0) {
|
||||||
AnnotateHappensBefore(__FILE__, __LINE__, &fSemaphore);
|
AnnotateHappensBefore(__FILE__, __LINE__, &fSemaphore);
|
||||||
semaphore_signal(fSemaphore);
|
dispatch_semaphore_signal(fSemaphore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void wait() {
|
void wait() {
|
||||||
while (true) {
|
dispatch_semaphore_wait(fSemaphore, DISPATCH_TIME_FOREVER);
|
||||||
kern_return_t result = semaphore_wait(fSemaphore);
|
AnnotateHappensAfter(__FILE__, __LINE__, &fSemaphore);
|
||||||
if (result == KERN_SUCCESS) {
|
|
||||||
AnnotateHappensAfter(__FILE__, __LINE__, &fSemaphore);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SkASSERT(result == KERN_ABORTED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#elif defined(SK_BUILD_FOR_WIN)
|
#elif defined(SK_BUILD_FOR_WIN)
|
||||||
|
Loading…
Reference in New Issue
Block a user