mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
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:
commit
0ea541171d
92
glib/gmain.c
92
glib/gmain.c
@ -3307,25 +3307,10 @@ g_main_context_release (GMainContext *context)
|
|||||||
UNLOCK_CONTEXT (context);
|
UNLOCK_CONTEXT (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static gboolean
|
||||||
* g_main_context_wait:
|
g_main_context_wait_internal (GMainContext *context,
|
||||||
* @context: a #GMainContext
|
GCond *cond,
|
||||||
* @cond: a condition variable
|
GMutex *mutex)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
GThread *self = G_THREAD_SELF;
|
GThread *self = G_THREAD_SELF;
|
||||||
@ -3334,18 +3319,6 @@ g_main_context_wait (GMainContext *context,
|
|||||||
if (context == NULL)
|
if (context == NULL)
|
||||||
context = g_main_context_default ();
|
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);
|
loop_internal_waiter = (mutex == &context->mutex);
|
||||||
|
|
||||||
if (!loop_internal_waiter)
|
if (!loop_internal_waiter)
|
||||||
@ -3361,10 +3334,10 @@ g_main_context_wait (GMainContext *context,
|
|||||||
context->waiters = g_slist_append (context->waiters, &waiter);
|
context->waiters = g_slist_append (context->waiters, &waiter);
|
||||||
|
|
||||||
if (!loop_internal_waiter)
|
if (!loop_internal_waiter)
|
||||||
UNLOCK_CONTEXT (context);
|
UNLOCK_CONTEXT (context);
|
||||||
g_cond_wait (cond, mutex);
|
g_cond_wait (cond, mutex);
|
||||||
if (!loop_internal_waiter)
|
if (!loop_internal_waiter)
|
||||||
LOCK_CONTEXT (context);
|
LOCK_CONTEXT (context);
|
||||||
|
|
||||||
context->waiters = g_slist_remove (context->waiters, &waiter);
|
context->waiters = g_slist_remove (context->waiters, &waiter);
|
||||||
}
|
}
|
||||||
@ -3387,6 +3360,45 @@ g_main_context_wait (GMainContext *context,
|
|||||||
return result;
|
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:
|
* g_main_context_prepare:
|
||||||
* @context: a #GMainContext
|
* @context: a #GMainContext
|
||||||
@ -3864,9 +3876,9 @@ g_main_context_iterate (GMainContext *context,
|
|||||||
if (!block)
|
if (!block)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
got_ownership = g_main_context_wait (context,
|
got_ownership = g_main_context_wait_internal (context,
|
||||||
&context->cond,
|
&context->cond,
|
||||||
&context->mutex);
|
&context->mutex);
|
||||||
|
|
||||||
if (!got_ownership)
|
if (!got_ownership)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -4073,9 +4085,9 @@ g_main_loop_run (GMainLoop *loop)
|
|||||||
loop->is_running = TRUE;
|
loop->is_running = TRUE;
|
||||||
|
|
||||||
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_internal (loop->context,
|
||||||
&loop->context->cond,
|
&loop->context->cond,
|
||||||
&loop->context->mutex);
|
&loop->context->mutex);
|
||||||
|
|
||||||
if (!loop->is_running)
|
if (!loop->is_running)
|
||||||
{
|
{
|
||||||
|
@ -376,7 +376,7 @@ GLIB_AVAILABLE_IN_ALL
|
|||||||
void g_main_context_release (GMainContext *context);
|
void g_main_context_release (GMainContext *context);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
gboolean g_main_context_is_owner (GMainContext *context);
|
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,
|
gboolean g_main_context_wait (GMainContext *context,
|
||||||
GCond *cond,
|
GCond *cond,
|
||||||
GMutex *mutex);
|
GMutex *mutex);
|
||||||
|
Loading…
Reference in New Issue
Block a user