mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-14 11:38:05 +02:00
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:
parent
19e7026fe7
commit
cedc82290f
@ -96,9 +96,20 @@ void
|
|||||||
g_mutex_init (GMutex *mutex)
|
g_mutex_init (GMutex *mutex)
|
||||||
{
|
{
|
||||||
gint status;
|
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");
|
g_thread_abort (status, "pthread_mutex_init");
|
||||||
|
|
||||||
|
#ifdef PTHREAD_ADAPTIVE_MUTEX_NP
|
||||||
|
pthread_mutexattr_destroy (&attr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +82,11 @@ struct _GCond
|
|||||||
|
|
||||||
#include <pthread.h>
|
#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 }
|
#define G_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER }
|
||||||
|
#endif
|
||||||
struct _GMutex
|
struct _GMutex
|
||||||
{
|
{
|
||||||
pthread_mutex_t impl;
|
pthread_mutex_t impl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user