vireventthread: Introduce virEventThreadStop

The aim is to move parts of vir_event_thread_finalize() that MAY
block into a separate function, so that unrefing the a
virEventThread no longer blocks (or require releasing and
subsequent re-acquiring of a mutex).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2024-07-25 09:49:05 +02:00
parent bec195607c
commit 7aca235d8d
3 changed files with 25 additions and 0 deletions

View File

@ -2288,6 +2288,7 @@ virEventGLibRunOnce;
# util/vireventthread.h # util/vireventthread.h
virEventThreadGetContext; virEventThreadGetContext;
virEventThreadNew; virEventThreadNew;
virEventThreadStop;
# util/virfcp.h # util/virfcp.h

View File

@ -188,6 +188,28 @@ virEventThreadNew(const char *name)
} }
/**
* virEventThreadStop:
* @evt: event thread
*
* May block until all events are processed. Typical use case is:
*
* virEventThread *evt = virEventThreadNew("name");
* ...
* virEventThreadStop(evt);
* g_object_unref(evt);
*/
void
virEventThreadStop(virEventThread *evt)
{
if (evt->thread) {
g_main_loop_quit(evt->loop);
g_thread_join(evt->thread);
evt->thread = NULL;
}
}
GMainContext * GMainContext *
virEventThreadGetContext(virEventThread *evt) virEventThreadGetContext(virEventThread *evt)
{ {

View File

@ -28,4 +28,6 @@ G_DECLARE_FINAL_TYPE(virEventThread, vir_event_thread, VIR, EVENT_THREAD, GObjec
virEventThread *virEventThreadNew(const char *name); virEventThread *virEventThreadNew(const char *name);
void virEventThreadStop(virEventThread *evt);
GMainContext *virEventThreadGetContext(virEventThread *evt); GMainContext *virEventThreadGetContext(virEventThread *evt);