Use fast spinlocks only for small enough atomic operations. Otherwise, you

run into some performance problems in e.g. video graphics experience because
of busywaits in the current spin_lock() implementation.
This commit is contained in:
gbeauche 2005-06-25 11:40:29 +00:00
parent 198925c5ae
commit a8ba24aecf
3 changed files with 26 additions and 25 deletions

View File

@ -168,18 +168,18 @@ static inline int find_next_page_clear(int page)
#endif
}
#ifdef HAVE_SPINLOCKS
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF spin_lock(&vosf_lock)
#define UNLOCK_VOSF spin_unlock(&vosf_lock)
#if defined(HAVE_PTHREADS)
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
#elif defined(_WIN32)
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF vosf_lock.lock();
#define UNLOCK_VOSF vosf_lock.unlock();
#elif defined(HAVE_PTHREADS)
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
#elif defined(HAVE_SPINLOCKS)
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF spin_lock(&vosf_lock)
#define UNLOCK_VOSF spin_unlock(&vosf_lock)
#else
#define LOCK_VOSF
#define UNLOCK_VOSF

View File

@ -372,7 +372,8 @@ typedef volatile int spinlock_t;
static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
#if HAVE_TEST_AND_SET
#if defined(HAVE_TEST_AND_SET) && defined(HAVE_PTHREADS)
// There is nothing to lock if we are not in an multithreaded environment
#define HAVE_SPINLOCKS 1
static inline void spin_lock(spinlock_t *lock)
{
@ -442,16 +443,16 @@ typedef struct rgb_color {
} rgb_color;
// X11 display fast locks
#ifdef HAVE_SPINLOCKS
#define X11_LOCK_TYPE spinlock_t
#define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
#define XDisplayLock() spin_lock(&x_display_lock)
#define XDisplayUnlock() spin_unlock(&x_display_lock)
#elif defined(HAVE_PTHREADS)
#if defined(HAVE_PTHREADS)
#define X11_LOCK_TYPE pthread_mutex_t
#define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
#define XDisplayLock() pthread_mutex_lock(&x_display_lock);
#define XDisplayUnlock() pthread_mutex_unlock(&x_display_lock);
#elif defined(HAVE_SPINLOCKS)
#define X11_LOCK_TYPE spinlock_t
#define X11_LOCK_INIT SPIN_LOCK_UNLOCKED
#define XDisplayLock() spin_lock(&x_display_lock)
#define XDisplayUnlock() spin_unlock(&x_display_lock)
#else
#define XDisplayLock()
#define XDisplayUnlock()

View File

@ -168,28 +168,28 @@ static int num_x_video_modes;
#endif
// Mutex to protect palette
#ifdef HAVE_SPINLOCKS
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
#define LOCK_PALETTE spin_lock(&x_palette_lock)
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
#elif defined(HAVE_PTHREADS)
#if defined(HAVE_PTHREADS)
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
#define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock)
#elif defined(HAVE_SPINLOCKS)
static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
#define LOCK_PALETTE spin_lock(&x_palette_lock)
#define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
#else
#define LOCK_PALETTE
#define UNLOCK_PALETTE
#endif
// Mutex to protect frame buffer
#ifdef HAVE_SPINLOCKS
static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
#define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
#define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
#elif defined(HAVE_PTHREADS)
#if defined(HAVE_PTHREADS)
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
#elif defined(HAVE_SPINLOCKS)
static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
#define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
#define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
#else
#define LOCK_FRAME_BUFFER
#define UNLOCK_FRAME_BUFFER