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 <jeremyhu@apple.com>
Reviewed-by: Daniel A. Steffen <dsteffen@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-04-23 11:55:49 -07:00
parent 3e253c603b
commit 1596ea72d6

View File

@ -62,7 +62,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <IOKit/pwr_mgt/IOPMLib.h> #include <IOKit/pwr_mgt/IOPMLib.h>
#include <pthread.h> #include <libkern/OSAtomic.h>
#include <signal.h> #include <signal.h>
#include <rootlessCommon.h> #include <rootlessCommon.h>
@ -279,10 +279,10 @@ static void pokeActivityCallback(CFRunLoopTimerRef timer, void *info) {
static void QuartzScreenSaver(int state) { static void QuartzScreenSaver(int state) {
static CFRunLoopTimerRef pokeActivityTimer = NULL; static CFRunLoopTimerRef pokeActivityTimer = NULL;
static CFRunLoopTimerContext pokeActivityContext = { 0, NULL, NULL, NULL, 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(state) {
if(pokeActivityTimer == NULL) if(pokeActivityTimer == NULL)
goto QuartzScreenSaverEnd; goto QuartzScreenSaverEnd;
@ -303,7 +303,7 @@ static void QuartzScreenSaver(int state) {
CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes); CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes);
} }
QuartzScreenSaverEnd: QuartzScreenSaverEnd:
pthread_mutex_unlock(&pokeActivityMutex); OSSpinLockUnlock(&pokeActivitySpinLock);
} }
void QuartzShowFullscreen(int state) { void QuartzShowFullscreen(int state) {