mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 19:36:18 +01:00
libglib: drop use of GStaticMutex
Use GMutex directly instead.
This commit is contained in:
parent
80730bc75c
commit
f35362f3ae
@ -37,7 +37,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_FUTEX
|
#ifndef HAVE_FUTEX
|
||||||
static GStaticMutex g_futex_mutex = G_STATIC_MUTEX_INIT;
|
static GMutex g_futex_mutex = G_MUTEX_INIT;
|
||||||
static GSList *g_futex_address_list = NULL;
|
static GSList *g_futex_address_list = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ static void
|
|||||||
g_futex_wait (const volatile gint *address,
|
g_futex_wait (const volatile gint *address,
|
||||||
gint value)
|
gint value)
|
||||||
{
|
{
|
||||||
g_static_mutex_lock (&g_futex_mutex);
|
g_mutex_lock (&g_futex_mutex);
|
||||||
if G_LIKELY (g_atomic_int_get (address) == value)
|
if G_LIKELY (g_atomic_int_get (address) == value)
|
||||||
{
|
{
|
||||||
WaitAddress *waiter;
|
WaitAddress *waiter;
|
||||||
@ -141,7 +141,7 @@ g_futex_wait (const volatile gint *address,
|
|||||||
}
|
}
|
||||||
|
|
||||||
waiter->ref_count++;
|
waiter->ref_count++;
|
||||||
g_cond_wait (waiter->wait_queue, g_static_mutex_get_mutex (&g_futex_mutex));
|
g_cond_wait (waiter->wait_queue, &g_futex_mutex);
|
||||||
|
|
||||||
if (!--waiter->ref_count)
|
if (!--waiter->ref_count)
|
||||||
{
|
{
|
||||||
@ -151,7 +151,7 @@ g_futex_wait (const volatile gint *address,
|
|||||||
g_slice_free (WaitAddress, waiter);
|
g_slice_free (WaitAddress, waiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_static_mutex_unlock (&g_futex_mutex);
|
g_mutex_unlock (&g_futex_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -165,10 +165,10 @@ g_futex_wake (const volatile gint *address)
|
|||||||
* 2) need to -stay- locked until the end to ensure a wake()
|
* 2) need to -stay- locked until the end to ensure a wake()
|
||||||
* in another thread doesn't cause 'waiter' to stop existing
|
* in another thread doesn't cause 'waiter' to stop existing
|
||||||
*/
|
*/
|
||||||
g_static_mutex_lock (&g_futex_mutex);
|
g_mutex_lock (&g_futex_mutex);
|
||||||
if ((waiter = g_futex_find_address (address)))
|
if ((waiter = g_futex_find_address (address)))
|
||||||
g_cond_signal (waiter->wait_queue);
|
g_cond_signal (waiter->wait_queue);
|
||||||
g_static_mutex_unlock (&g_futex_mutex);
|
g_mutex_unlock (&g_futex_mutex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
19
glib/gmain.c
19
glib/gmain.c
@ -220,7 +220,7 @@ struct _GMainContext
|
|||||||
/* The following lock is used for both the list of sources
|
/* The following lock is used for both the list of sources
|
||||||
* and the list of poll records
|
* and the list of poll records
|
||||||
*/
|
*/
|
||||||
GStaticMutex mutex;
|
GMutex mutex;
|
||||||
GCond *cond;
|
GCond *cond;
|
||||||
GThread *owner;
|
GThread *owner;
|
||||||
guint owner_count;
|
guint owner_count;
|
||||||
@ -309,8 +309,8 @@ struct _GSourcePrivate
|
|||||||
GSource *parent_source;
|
GSource *parent_source;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOCK_CONTEXT(context) g_static_mutex_lock (&context->mutex)
|
#define LOCK_CONTEXT(context) g_mutex_lock (&context->mutex)
|
||||||
#define UNLOCK_CONTEXT(context) g_static_mutex_unlock (&context->mutex)
|
#define UNLOCK_CONTEXT(context) g_mutex_unlock (&context->mutex)
|
||||||
#define G_THREAD_SELF g_thread_self ()
|
#define G_THREAD_SELF g_thread_self ()
|
||||||
|
|
||||||
#define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
|
#define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
|
||||||
@ -488,7 +488,7 @@ g_main_context_unref (GMainContext *context)
|
|||||||
source = next;
|
source = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_static_mutex_free (&context->mutex);
|
g_mutex_clear (&context->mutex);
|
||||||
|
|
||||||
g_ptr_array_free (context->pending_dispatches, TRUE);
|
g_ptr_array_free (context->pending_dispatches, TRUE);
|
||||||
g_free (context->cached_poll_array);
|
g_free (context->cached_poll_array);
|
||||||
@ -542,7 +542,7 @@ g_main_context_new (void)
|
|||||||
|
|
||||||
context = g_new0 (GMainContext, 1);
|
context = g_new0 (GMainContext, 1);
|
||||||
|
|
||||||
g_static_mutex_init (&context->mutex);
|
g_mutex_init (&context->mutex);
|
||||||
|
|
||||||
context->owner = NULL;
|
context->owner = NULL;
|
||||||
context->waiters = NULL;
|
context->waiters = NULL;
|
||||||
@ -2515,8 +2515,7 @@ g_main_context_release (GMainContext *context)
|
|||||||
if (context->waiters)
|
if (context->waiters)
|
||||||
{
|
{
|
||||||
GMainWaiter *waiter = context->waiters->data;
|
GMainWaiter *waiter = context->waiters->data;
|
||||||
gboolean loop_internal_waiter =
|
gboolean loop_internal_waiter = (waiter->mutex == &context->mutex);
|
||||||
(waiter->mutex == g_static_mutex_get_mutex (&context->mutex));
|
|
||||||
context->waiters = g_slist_delete_link (context->waiters,
|
context->waiters = g_slist_delete_link (context->waiters,
|
||||||
context->waiters);
|
context->waiters);
|
||||||
if (!loop_internal_waiter)
|
if (!loop_internal_waiter)
|
||||||
@ -2559,7 +2558,7 @@ g_main_context_wait (GMainContext *context,
|
|||||||
if (context == NULL)
|
if (context == NULL)
|
||||||
context = g_main_context_default ();
|
context = g_main_context_default ();
|
||||||
|
|
||||||
loop_internal_waiter = (mutex == g_static_mutex_get_mutex (&context->mutex));
|
loop_internal_waiter = (mutex == &context->mutex);
|
||||||
|
|
||||||
if (!loop_internal_waiter)
|
if (!loop_internal_waiter)
|
||||||
LOCK_CONTEXT (context);
|
LOCK_CONTEXT (context);
|
||||||
@ -2958,7 +2957,7 @@ g_main_context_iterate (GMainContext *context,
|
|||||||
|
|
||||||
got_ownership = g_main_context_wait (context,
|
got_ownership = g_main_context_wait (context,
|
||||||
context->cond,
|
context->cond,
|
||||||
g_static_mutex_get_mutex (&context->mutex));
|
&context->mutex);
|
||||||
|
|
||||||
if (!got_ownership)
|
if (!got_ownership)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -3169,7 +3168,7 @@ g_main_loop_run (GMainLoop *loop)
|
|||||||
while (loop->is_running && !got_ownership)
|
while (loop->is_running && !got_ownership)
|
||||||
got_ownership = g_main_context_wait (loop->context,
|
got_ownership = g_main_context_wait (loop->context,
|
||||||
loop->context->cond,
|
loop->context->cond,
|
||||||
g_static_mutex_get_mutex (&loop->context->mutex));
|
&loop->context->mutex);
|
||||||
|
|
||||||
if (!loop->is_running)
|
if (!loop->is_running)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user