diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2023-04-24 12:52:51 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2023-04-24 12:52:51 +0000 |
commit | d3e7b9e17c2ce12285dbf8fc811c6a296204b029 (patch) | |
tree | c9f7d4a837d0d3338b4e0a8f0e41ed567b0d9e22 | |
parent | fd493cacf26ed65ff307ca146e7060384c012d6f (diff) | |
parent | 3926af723a7469a2ea492307f421820361d617b3 (diff) | |
download | glib-d3e7b9e17c2ce12285dbf8fc811c6a296204b029.tar.gz |
Merge branch 'context-checks' into 'main'
gmain: More explicitly document g_main_context_release() prereqs
See merge request GNOME/glib!3314
-rw-r--r-- | glib/gmain.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/glib/gmain.c b/glib/gmain.c index 7442d3d05..191e77345 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -3525,7 +3525,7 @@ g_main_dispatch (GMainContext *context) * * You must be the owner of a context before you * can call g_main_context_prepare(), g_main_context_query(), - * g_main_context_check(), g_main_context_dispatch(). + * g_main_context_check(), g_main_context_dispatch(), g_main_context_release(). * * Since 2.76 @context can be %NULL to use the global-default * main context. @@ -3583,15 +3583,32 @@ g_main_context_acquire_unlocked (GMainContext *context) * with g_main_context_acquire(). If the context was acquired multiple * times, the ownership will be released only when g_main_context_release() * is called as many times as it was acquired. + * + * You must have successfully acquired the context with + * g_main_context_acquire() before you may call this function. **/ void g_main_context_release (GMainContext *context) { if (context == NULL) context = g_main_context_default (); - + LOCK_CONTEXT (context); +#ifndef G_DISABLE_CHECKS + if (G_UNLIKELY (context->owner != G_THREAD_SELF || context->owner_count == 0)) + { + GThread *context_owner = context->owner; + guint context_owner_count = context->owner_count; + + UNLOCK_CONTEXT (context); + + g_critical ("g_main_context_release() called on a context (%p, owner %p, " + "owner count %u) which is not acquired by the current thread", + context, context_owner, context_owner_count); + } +#endif /* !G_DISABLE_CHECKS */ + g_main_context_release_unlocked (context); UNLOCK_CONTEXT (context); |