Merge branch '903-deprecate-main-context-wait' into 'master'

gmain: Officially deprecate g_main_context_wait()

Closes #903

See merge request GNOME/glib!139
This commit is contained in:
Philip Withnall 2018-06-28 16:59:39 +00:00
commit 0ea541171d
2 changed files with 53 additions and 41 deletions

View File

@ -3307,23 +3307,8 @@ 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,
static gboolean
g_main_context_wait_internal (GMainContext *context,
GCond *cond,
GMutex *mutex)
{
@ -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)
@ -3387,6 +3360,45 @@ g_main_context_wait (GMainContext *context,
return result;
}
/**
* 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
@ -3864,7 +3876,7 @@ g_main_context_iterate (GMainContext *context,
if (!block)
return FALSE;
got_ownership = g_main_context_wait (context,
got_ownership = g_main_context_wait_internal (context,
&context->cond,
&context->mutex);
@ -4073,7 +4085,7 @@ g_main_loop_run (GMainLoop *loop)
loop->is_running = TRUE;
while (loop->is_running && !got_ownership)
got_ownership = g_main_context_wait (loop->context,
got_ownership = g_main_context_wait_internal (loop->context,
&loop->context->cond,
&loop->context->mutex);

View File

@ -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);