From 7a34e396ae56fff4212df5e8c5aa2a0ccc855ab3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 16 May 2018 10:42:21 +0100 Subject: [PATCH] gmain: Officially deprecate g_main_context_wait() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It’s been de-facto deprecated for a long time, due to emitting a critical warning when used in a non-internal context. Make that official in the documentation and with a deprecation annotation. Split the implementation into an internal helper and an external wrapper, so the two remaining internal uses don’t emit deprecation warnings. Signed-off-by: Philip Withnall https://gitlab.gnome.org/GNOME/glib/issues/903 --- glib/gmain.c | 92 ++++++++++++++++++++++++++++++++++-------------------------- glib/gmain.h | 2 +- 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/glib/gmain.c b/glib/gmain.c index 5f0b05198..fcd996a18 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -3307,25 +3307,10 @@ g_main_context_release (GMainContext *context) UNLOCK_CONTEXT (context); } -/** - * g_main_context_wait: - * @context: a #GMainContext - * @cond: a condition variable - * @mutex: a mutex, currently held - * - * Tries to become the owner of the specified context, - * as with g_main_context_acquire(). But if another thread - * is the owner, atomically drop @mutex and wait on @cond until - * that owner releases ownership or until @cond is signaled, then - * try again (once) to become the owner. - * - * Returns: %TRUE if the operation succeeded, and - * this thread is now the owner of @context. - **/ -gboolean -g_main_context_wait (GMainContext *context, - GCond *cond, - GMutex *mutex) +static gboolean +g_main_context_wait_internal (GMainContext *context, + GCond *cond, + GMutex *mutex) { gboolean result = FALSE; GThread *self = G_THREAD_SELF; @@ -3334,18 +3319,6 @@ g_main_context_wait (GMainContext *context, if (context == NULL) context = g_main_context_default (); - if G_UNLIKELY (cond != &context->cond || mutex != &context->mutex) - { - static gboolean warned; - - if (!warned) - { - g_critical ("WARNING!! g_main_context_wait() will be removed in a future release. " - "If you see this message, please file a bug immediately."); - warned = TRUE; - } - } - loop_internal_waiter = (mutex == &context->mutex); if (!loop_internal_waiter) @@ -3361,10 +3334,10 @@ g_main_context_wait (GMainContext *context, context->waiters = g_slist_append (context->waiters, &waiter); if (!loop_internal_waiter) - UNLOCK_CONTEXT (context); + UNLOCK_CONTEXT (context); g_cond_wait (cond, mutex); - if (!loop_internal_waiter) - LOCK_CONTEXT (context); + if (!loop_internal_waiter) + LOCK_CONTEXT (context); context->waiters = g_slist_remove (context->waiters, &waiter); } @@ -3388,6 +3361,45 @@ g_main_context_wait (GMainContext *context, } /** + * g_main_context_wait: + * @context: a #GMainContext + * @cond: a condition variable + * @mutex: a mutex, currently held + * + * Tries to become the owner of the specified context, + * as with g_main_context_acquire(). But if another thread + * is the owner, atomically drop @mutex and wait on @cond until + * that owner releases ownership or until @cond is signaled, then + * try again (once) to become the owner. + * + * Returns: %TRUE if the operation succeeded, and + * this thread is now the owner of @context. + * Deprecated: 2.58: Use g_main_context_is_owner() and separate locking instead. + */ +gboolean +g_main_context_wait (GMainContext *context, + GCond *cond, + GMutex *mutex) +{ + if (context == NULL) + context = g_main_context_default (); + + if (G_UNLIKELY (cond != &context->cond || mutex != &context->mutex)) + { + static gboolean warned; + + if (!warned) + { + g_critical ("WARNING!! g_main_context_wait() will be removed in a future release. " + "If you see this message, please file a bug immediately."); + warned = TRUE; + } + } + + return g_main_context_wait_internal (context, cond, mutex); +} + +/** * g_main_context_prepare: * @context: a #GMainContext * @priority: location to store priority of highest priority @@ -3864,9 +3876,9 @@ g_main_context_iterate (GMainContext *context, if (!block) return FALSE; - got_ownership = g_main_context_wait (context, - &context->cond, - &context->mutex); + got_ownership = g_main_context_wait_internal (context, + &context->cond, + &context->mutex); if (!got_ownership) return FALSE; @@ -4073,9 +4085,9 @@ g_main_loop_run (GMainLoop *loop) loop->is_running = TRUE; while (loop->is_running && !got_ownership) - got_ownership = g_main_context_wait (loop->context, - &loop->context->cond, - &loop->context->mutex); + got_ownership = g_main_context_wait_internal (loop->context, + &loop->context->cond, + &loop->context->mutex); if (!loop->is_running) { diff --git a/glib/gmain.h b/glib/gmain.h index de6a73ac9..eca14d7d5 100644 --- a/glib/gmain.h +++ b/glib/gmain.h @@ -376,7 +376,7 @@ GLIB_AVAILABLE_IN_ALL void g_main_context_release (GMainContext *context); GLIB_AVAILABLE_IN_ALL gboolean g_main_context_is_owner (GMainContext *context); -GLIB_AVAILABLE_IN_ALL +GLIB_DEPRECATED_IN_2_58_FOR(g_main_context_is_owner) gboolean g_main_context_wait (GMainContext *context, GCond *cond, GMutex *mutex); -- 2.11.4.GIT