mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
virThread: Set thread job
Automatically assign a job to every thread created by virThreadCreate. The name of the virThreadFunc function passed to virThreadCreate is used as the job or worker name in case no name is explicitly passed. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
23d0c979f7
commit
55ebc93a08
@ -2181,7 +2181,7 @@ virRWLockRead;
|
|||||||
virRWLockUnlock;
|
virRWLockUnlock;
|
||||||
virRWLockWrite;
|
virRWLockWrite;
|
||||||
virThreadCancel;
|
virThreadCancel;
|
||||||
virThreadCreate;
|
virThreadCreateFull;
|
||||||
virThreadID;
|
virThreadID;
|
||||||
virThreadInitialize;
|
virThreadInitialize;
|
||||||
virThreadIsSelf;
|
virThreadIsSelf;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
|
#include "virthreadjob.h"
|
||||||
|
|
||||||
|
|
||||||
/* Nothing special required for pthreads */
|
/* Nothing special required for pthreads */
|
||||||
@ -184,6 +185,8 @@ void virCondBroadcast(virCondPtr c)
|
|||||||
|
|
||||||
struct virThreadArgs {
|
struct virThreadArgs {
|
||||||
virThreadFunc func;
|
virThreadFunc func;
|
||||||
|
const char *funcName;
|
||||||
|
bool worker;
|
||||||
void *opaque;
|
void *opaque;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,13 +197,25 @@ static void *virThreadHelper(void *data)
|
|||||||
|
|
||||||
/* Free args early, rather than tying it up during the entire thread. */
|
/* Free args early, rather than tying it up during the entire thread. */
|
||||||
VIR_FREE(args);
|
VIR_FREE(args);
|
||||||
|
|
||||||
|
if (local.worker)
|
||||||
|
virThreadJobSetWorker(local.funcName);
|
||||||
|
else
|
||||||
|
virThreadJobSet(local.funcName);
|
||||||
|
|
||||||
local.func(local.opaque);
|
local.func(local.opaque);
|
||||||
|
|
||||||
|
if (!local.worker)
|
||||||
|
virThreadJobClear(0);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virThreadCreate(virThreadPtr thread,
|
int virThreadCreateFull(virThreadPtr thread,
|
||||||
bool joinable,
|
bool joinable,
|
||||||
virThreadFunc func,
|
virThreadFunc func,
|
||||||
|
const char *funcName,
|
||||||
|
bool worker,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
struct virThreadArgs *args;
|
struct virThreadArgs *args;
|
||||||
@ -216,6 +231,8 @@ int virThreadCreate(virThreadPtr thread,
|
|||||||
}
|
}
|
||||||
|
|
||||||
args->func = func;
|
args->func = func;
|
||||||
|
args->funcName = funcName;
|
||||||
|
args->worker = worker;
|
||||||
args->opaque = opaque;
|
args->opaque = opaque;
|
||||||
|
|
||||||
if (!joinable)
|
if (!joinable)
|
||||||
|
@ -88,9 +88,14 @@ void virThreadOnExit(void);
|
|||||||
|
|
||||||
typedef void (*virThreadFunc)(void *opaque);
|
typedef void (*virThreadFunc)(void *opaque);
|
||||||
|
|
||||||
int virThreadCreate(virThreadPtr thread,
|
# define virThreadCreate(thread, joinable, func, opaque) \
|
||||||
|
virThreadCreateFull(thread, joinable, func, #func, false, opaque)
|
||||||
|
|
||||||
|
int virThreadCreateFull(virThreadPtr thread,
|
||||||
bool joinable,
|
bool joinable,
|
||||||
virThreadFunc func,
|
virThreadFunc func,
|
||||||
|
const char *funcName,
|
||||||
|
bool worker,
|
||||||
void *opaque) ATTRIBUTE_RETURN_CHECK;
|
void *opaque) ATTRIBUTE_RETURN_CHECK;
|
||||||
void virThreadSelf(virThreadPtr thread);
|
void virThreadSelf(virThreadPtr thread);
|
||||||
bool virThreadIsSelf(virThreadPtr thread);
|
bool virThreadIsSelf(virThreadPtr thread);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user