mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-09-07 16:54:28 +00:00
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:
parent
198925c5ae
commit
a8ba24aecf
@ -168,18 +168,18 @@ static inline int find_next_page_clear(int page)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SPINLOCKS
|
#if defined(HAVE_PTHREADS)
|
||||||
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact)
|
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact)
|
||||||
#define LOCK_VOSF spin_lock(&vosf_lock)
|
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
|
||||||
#define UNLOCK_VOSF spin_unlock(&vosf_lock)
|
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact)
|
static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact)
|
||||||
#define LOCK_VOSF vosf_lock.lock();
|
#define LOCK_VOSF vosf_lock.lock();
|
||||||
#define UNLOCK_VOSF vosf_lock.unlock();
|
#define UNLOCK_VOSF vosf_lock.unlock();
|
||||||
#elif defined(HAVE_PTHREADS)
|
#elif defined(HAVE_SPINLOCKS)
|
||||||
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact)
|
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact)
|
||||||
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
|
#define LOCK_VOSF spin_lock(&vosf_lock)
|
||||||
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
|
#define UNLOCK_VOSF spin_unlock(&vosf_lock)
|
||||||
#else
|
#else
|
||||||
#define LOCK_VOSF
|
#define LOCK_VOSF
|
||||||
#define UNLOCK_VOSF
|
#define UNLOCK_VOSF
|
||||||
|
@ -372,7 +372,8 @@ typedef volatile int spinlock_t;
|
|||||||
|
|
||||||
static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
|
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
|
#define HAVE_SPINLOCKS 1
|
||||||
static inline void spin_lock(spinlock_t *lock)
|
static inline void spin_lock(spinlock_t *lock)
|
||||||
{
|
{
|
||||||
@ -442,16 +443,16 @@ typedef struct rgb_color {
|
|||||||
} rgb_color;
|
} rgb_color;
|
||||||
|
|
||||||
// X11 display fast locks
|
// X11 display fast locks
|
||||||
#ifdef HAVE_SPINLOCKS
|
#if defined(HAVE_PTHREADS)
|
||||||
#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)
|
|
||||||
#define X11_LOCK_TYPE pthread_mutex_t
|
#define X11_LOCK_TYPE pthread_mutex_t
|
||||||
#define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
|
#define X11_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
|
||||||
#define XDisplayLock() pthread_mutex_lock(&x_display_lock);
|
#define XDisplayLock() pthread_mutex_lock(&x_display_lock);
|
||||||
#define XDisplayUnlock() pthread_mutex_unlock(&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
|
#else
|
||||||
#define XDisplayLock()
|
#define XDisplayLock()
|
||||||
#define XDisplayUnlock()
|
#define XDisplayUnlock()
|
||||||
|
@ -168,28 +168,28 @@ static int num_x_video_modes;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Mutex to protect palette
|
// Mutex to protect palette
|
||||||
#ifdef HAVE_SPINLOCKS
|
#if defined(HAVE_PTHREADS)
|
||||||
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)
|
|
||||||
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
|
#define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
|
||||||
#define UNLOCK_PALETTE pthread_mutex_unlock(&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
|
#else
|
||||||
#define LOCK_PALETTE
|
#define LOCK_PALETTE
|
||||||
#define UNLOCK_PALETTE
|
#define UNLOCK_PALETTE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Mutex to protect frame buffer
|
// Mutex to protect frame buffer
|
||||||
#ifdef HAVE_SPINLOCKS
|
#if defined(HAVE_PTHREADS)
|
||||||
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)
|
|
||||||
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
|
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
|
||||||
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&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
|
#else
|
||||||
#define LOCK_FRAME_BUFFER
|
#define LOCK_FRAME_BUFFER
|
||||||
#define UNLOCK_FRAME_BUFFER
|
#define UNLOCK_FRAME_BUFFER
|
||||||
|
Loading…
Reference in New Issue
Block a user