From 1596ea72d66a03d9accb534679172ca6f63f78e1 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Sat, 23 Apr 2011 11:55:49 -0700 Subject: [PATCH] XQuartz: Use a lighter spinlock instead of a pthread_mutex_t in QuartzScreenSaver Currently, we only end up here through a call to QuartzShowFullscreen, and this is always on the same thread. Future changes (such as further incorporating libdispatch) may allow this to change, but contention will remain minimal since the call is infrequent and it is short held. Signed-off-by: Jeremy Huddleston Reviewed-by: Daniel A. Steffen --- hw/xquartz/quartz.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c index 4b72a89d3..0e71d3629 100644 --- a/hw/xquartz/quartz.c +++ b/hw/xquartz/quartz.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include @@ -279,10 +279,10 @@ static void pokeActivityCallback(CFRunLoopTimerRef timer, void *info) { static void QuartzScreenSaver(int state) { static CFRunLoopTimerRef pokeActivityTimer = NULL; static CFRunLoopTimerContext pokeActivityContext = { 0, NULL, NULL, NULL, NULL }; - static pthread_mutex_t pokeActivityMutex = PTHREAD_MUTEX_INITIALIZER; + static OSSpinLock pokeActivitySpinLock = OS_SPINLOCK_INIT; + + OSSpinLockLock(&pokeActivitySpinLock); - pthread_mutex_lock(&pokeActivityMutex); - if(state) { if(pokeActivityTimer == NULL) goto QuartzScreenSaverEnd; @@ -303,7 +303,7 @@ static void QuartzScreenSaver(int state) { CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes); } QuartzScreenSaverEnd: - pthread_mutex_unlock(&pokeActivityMutex); + OSSpinLockUnlock(&pokeActivitySpinLock); } void QuartzShowFullscreen(int state) {