diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a8dced5cdcf1c24b7f5835783170ce2b8d471466..0945df4c944d02ef49acbc7811ad95849da4e712 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2181,7 +2181,7 @@ virRWLockRead; virRWLockUnlock; virRWLockWrite; virThreadCancel; -virThreadCreate; +virThreadCreateFull; virThreadID; virThreadInitialize; virThreadIsSelf; diff --git a/src/util/virthread.c b/src/util/virthread.c index 7e841d12c463999cdd5330455e9a63faa33b657b..c2a9e7faaae95727d0baf4a42d72971cf1d508cf 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -30,6 +30,7 @@ #endif #include "viralloc.h" +#include "virthreadjob.h" /* Nothing special required for pthreads */ @@ -184,6 +185,8 @@ void virCondBroadcast(virCondPtr c) struct virThreadArgs { virThreadFunc func; + const char *funcName; + bool worker; void *opaque; }; @@ -194,14 +197,26 @@ static void *virThreadHelper(void *data) /* Free args early, rather than tying it up during the entire thread. */ VIR_FREE(args); + + if (local.worker) + virThreadJobSetWorker(local.funcName); + else + virThreadJobSet(local.funcName); + local.func(local.opaque); + + if (!local.worker) + virThreadJobClear(0); + return NULL; } -int virThreadCreate(virThreadPtr thread, - bool joinable, - virThreadFunc func, - void *opaque) +int virThreadCreateFull(virThreadPtr thread, + bool joinable, + virThreadFunc func, + const char *funcName, + bool worker, + void *opaque) { struct virThreadArgs *args; pthread_attr_t attr; @@ -216,6 +231,8 @@ int virThreadCreate(virThreadPtr thread, } args->func = func; + args->funcName = funcName; + args->worker = worker; args->opaque = opaque; if (!joinable) diff --git a/src/util/virthread.h b/src/util/virthread.h index 7146f0f4ed95c9906d04e282fadbddd1e045ae0c..e466d9bf01843a4f4563c05b5d82f4f7663f47d0 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -88,10 +88,15 @@ void virThreadOnExit(void); typedef void (*virThreadFunc)(void *opaque); -int virThreadCreate(virThreadPtr thread, - bool joinable, - virThreadFunc func, - void *opaque) ATTRIBUTE_RETURN_CHECK; +# define virThreadCreate(thread, joinable, func, opaque) \ + virThreadCreateFull(thread, joinable, func, #func, false, opaque) + +int virThreadCreateFull(virThreadPtr thread, + bool joinable, + virThreadFunc func, + const char *funcName, + bool worker, + void *opaque) ATTRIBUTE_RETURN_CHECK; void virThreadSelf(virThreadPtr thread); bool virThreadIsSelf(virThreadPtr thread); void virThreadJoin(virThreadPtr thread);