Use adaptive mutexes when available

These are supposedly better on multi-cpu systems - and who doesn't
have multiple cpus nowadays. One single-processor systems, they
are identical to normal mutexes.
See e.g. http://bugzilla.mozilla.org/show_bug.cgi?id=132089

https://bugzilla.gnome.org/show_bug.cgi?id=659423
This commit is contained in:
Matthias Clasen 2011-09-22 00:52:18 -04:00
parent 19e7026fe7
commit cedc82290f
2 changed files with 16 additions and 1 deletions

View File

@ -96,9 +96,20 @@ void
g_mutex_init (GMutex *mutex)
{
gint status;
pthread_mutexattr_t *pattr = NULL;
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
pattr = &attr;
#endif
if G_UNLIKELY ((status = pthread_mutex_init (&mutex->impl, NULL)) != 0)
if G_UNLIKELY ((status = pthread_mutex_init (&mutex->impl, pattr)) != 0)
g_thread_abort (status, "pthread_mutex_init");
#ifdef PTHREAD_ADAPTIVE_MUTEX_NP
pthread_mutexattr_destroy (&attr);
#endif
}
/**

View File

@ -82,7 +82,11 @@ struct _GCond
#include <pthread.h>
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
#define G_MUTEX_INIT { PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP }
#else
#define G_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER }
#endif
struct _GMutex
{
pthread_mutex_t impl;