mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 01:47:58 +02:00
glib-aux: add nm_g_main_context_can_acquire() helper
This commit is contained in:
parent
9c8a937280
commit
5dc9307a34
2 changed files with 22 additions and 0 deletions
|
|
@ -6682,3 +6682,23 @@ nm_g_main_context_iterate_for_msec(GMainContext *context, guint timeout_msec)
|
|||
while (source)
|
||||
g_main_context_iteration(context, TRUE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean
|
||||
nm_g_main_context_can_acquire(GMainContext *context)
|
||||
{
|
||||
/* Fast path. Usually we don't pass contexts between threads
|
||||
* and operate while iterating the context. Hence, usually we
|
||||
* already acquired the context. Check that first. */
|
||||
if (g_main_context_is_owner(context))
|
||||
return TRUE;
|
||||
|
||||
/* Either the context is not owned, or owned by somebody else. Only
|
||||
* one way to find out. */
|
||||
if (!g_main_context_acquire(context))
|
||||
return FALSE;
|
||||
|
||||
g_main_context_release(context);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1931,6 +1931,8 @@ nm_g_main_context_iterate_ready(GMainContext *context)
|
|||
|
||||
void nm_g_main_context_iterate_for_msec(GMainContext *context, guint timeout_msec);
|
||||
|
||||
gboolean nm_g_main_context_can_acquire(GMainContext *context);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue