mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Use a static initializer for static mutexes
Now that we ditched our custom pthread impl for Win32, we can use PTHREAD_MUTEX_INITIALIZER for static mutexes. This avoids the need to use a virOnce one-time global initializer in a number of places. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
25d5d7057d
commit
3f671e6c52
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NWFILTER
|
#define VIR_FROM_THIS VIR_FROM_NWFILTER
|
||||||
|
|
||||||
static virMutex ipAddressMapLock;
|
static virMutex ipAddressMapLock = VIR_MUTEX_INITIALIZER;
|
||||||
static virNWFilterHashTablePtr ipAddressMap;
|
static virNWFilterHashTablePtr ipAddressMap;
|
||||||
|
|
||||||
|
|
||||||
@ -147,11 +147,6 @@ virNWFilterIPAddrMapInit(void)
|
|||||||
if (!ipAddressMap)
|
if (!ipAddressMap)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virMutexInit(&ipAddressMapLock) < 0) {
|
|
||||||
virNWFilterIPAddrMapShutdown();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -823,7 +823,7 @@ static int lxcControllerClearCapabilities(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool wantReboot = false;
|
static bool wantReboot = false;
|
||||||
static virMutex lock;
|
static virMutex lock = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|
||||||
static void virLXCControllerSignalChildIO(virNetServerPtr server,
|
static void virLXCControllerSignalChildIO(virNetServerPtr server,
|
||||||
@ -1108,9 +1108,6 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl)
|
|||||||
int rc = -1;
|
int rc = -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (virMutexInit(&lock) < 0)
|
|
||||||
goto cleanup2;
|
|
||||||
|
|
||||||
if (virNetServerAddSignalHandler(ctrl->server,
|
if (virNetServerAddSignalHandler(ctrl->server,
|
||||||
SIGCHLD,
|
SIGCHLD,
|
||||||
virLXCControllerSignalChildIO,
|
virLXCControllerSignalChildIO,
|
||||||
@ -1164,9 +1161,6 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl)
|
|||||||
rc = wantReboot ? 1 : 0;
|
rc = wantReboot ? 1 : 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexDestroy(&lock);
|
|
||||||
cleanup2:
|
|
||||||
|
|
||||||
for (i = 0; i < ctrl->nconsoles; i++)
|
for (i = 0; i < ctrl->nconsoles; i++)
|
||||||
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ static void ebiptablesDriverShutdown(void);
|
|||||||
static void ebtablesCleanAll(const char *ifname);
|
static void ebtablesCleanAll(const char *ifname);
|
||||||
static int ebiptablesAllTeardown(const char *ifname);
|
static int ebiptablesAllTeardown(const char *ifname);
|
||||||
|
|
||||||
static virMutex execCLIMutex;
|
static virMutex execCLIMutex = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
struct ushort_map {
|
struct ushort_map {
|
||||||
unsigned short attr;
|
unsigned short attr;
|
||||||
@ -4376,9 +4376,6 @@ ebiptablesDriverInit(bool privileged)
|
|||||||
if (!privileged)
|
if (!privileged)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (virMutexInit(&execCLIMutex) < 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
grep_cmd_path = virFindFileInPath("grep");
|
grep_cmd_path = virFindFileInPath("grep");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -119,10 +119,10 @@ struct ether_vlan_header
|
|||||||
} ATTRIBUTE_PACKED;
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
|
|
||||||
static virMutex pendingLearnReqLock;
|
static virMutex pendingLearnReqLock = VIR_MUTEX_INITIALIZER;
|
||||||
static virHashTablePtr pendingLearnReq;
|
static virHashTablePtr pendingLearnReq;
|
||||||
|
|
||||||
static virMutex ifaceMapLock;
|
static virMutex ifaceMapLock = VIR_MUTEX_INITIALIZER;
|
||||||
static virHashTablePtr ifaceLockMap;
|
static virHashTablePtr ifaceLockMap;
|
||||||
|
|
||||||
typedef struct _virNWFilterIfaceLock virNWFilterIfaceLock;
|
typedef struct _virNWFilterIfaceLock virNWFilterIfaceLock;
|
||||||
@ -806,22 +806,12 @@ virNWFilterLearnInit(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virMutexInit(&pendingLearnReqLock) < 0) {
|
|
||||||
virNWFilterLearnShutdown();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ifaceLockMap = virHashCreate(0, virHashValueFree);
|
ifaceLockMap = virHashCreate(0, virHashValueFree);
|
||||||
if (!ifaceLockMap) {
|
if (!ifaceLockMap) {
|
||||||
virNWFilterLearnShutdown();
|
virNWFilterLearnShutdown();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virMutexInit(&ifaceMapLock) < 0) {
|
|
||||||
virNWFilterLearnShutdown();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ typedef struct _testConn *testConnPtr;
|
|||||||
|
|
||||||
static testConn defaultConn;
|
static testConn defaultConn;
|
||||||
static int defaultConnections;
|
static int defaultConnections;
|
||||||
static virMutex defaultLock;
|
static virMutex defaultLock = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
#define TEST_MODEL "i686"
|
#define TEST_MODEL "i686"
|
||||||
#define TEST_MODEL_WORDSIZE 32
|
#define TEST_MODEL_WORDSIZE 32
|
||||||
@ -141,15 +141,6 @@ static int testConnectClose(virConnectPtr conn);
|
|||||||
static void testObjectEventQueue(testConnPtr driver,
|
static void testObjectEventQueue(testConnPtr driver,
|
||||||
virObjectEventPtr event);
|
virObjectEventPtr event);
|
||||||
|
|
||||||
static int
|
|
||||||
testOnceInit(void)
|
|
||||||
{
|
|
||||||
return virMutexInit(&defaultLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(test)
|
|
||||||
|
|
||||||
|
|
||||||
static void testDriverLock(testConnPtr driver)
|
static void testDriverLock(testConnPtr driver)
|
||||||
{
|
{
|
||||||
virMutexLock(&driver->lock);
|
virMutexLock(&driver->lock);
|
||||||
@ -1554,9 +1545,6 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
|
|||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||||
|
|
||||||
if (testInitialize() < 0)
|
|
||||||
return VIR_DRV_OPEN_ERROR;
|
|
||||||
|
|
||||||
if (!conn->uri)
|
if (!conn->uri)
|
||||||
return VIR_DRV_OPEN_DECLINED;
|
return VIR_DRV_OPEN_DECLINED;
|
||||||
|
|
||||||
@ -1596,9 +1584,6 @@ static int testConnectClose(virConnectPtr conn)
|
|||||||
{
|
{
|
||||||
testConnPtr privconn = conn->privateData;
|
testConnPtr privconn = conn->privateData;
|
||||||
|
|
||||||
if (testInitialize() < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (privconn == &defaultConn) {
|
if (privconn == &defaultConn) {
|
||||||
virMutexLock(&defaultLock);
|
virMutexLock(&defaultLock);
|
||||||
if (--defaultConnections) {
|
if (--defaultConnections) {
|
||||||
|
@ -73,18 +73,7 @@ VIR_LOG_INIT("util.netdevmacvlan");
|
|||||||
# define MACVLAN_NAME_PREFIX "macvlan"
|
# define MACVLAN_NAME_PREFIX "macvlan"
|
||||||
# define MACVLAN_NAME_PATTERN "macvlan%d"
|
# define MACVLAN_NAME_PATTERN "macvlan%d"
|
||||||
|
|
||||||
virMutex virNetDevMacVLanCreateMutex;
|
virMutex virNetDevMacVLanCreateMutex = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static int virNetDevMacVLanCreateMutexOnceInit(void)
|
|
||||||
{
|
|
||||||
if (virMutexInit(&virNetDevMacVLanCreateMutex) < 0) {
|
|
||||||
virReportSystemError(errno, "%s", _("unable to init mutex"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(virNetDevMacVLanCreateMutex);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virNetDevMacVLanCreate:
|
* virNetDevMacVLanCreate:
|
||||||
@ -873,8 +862,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
|
|||||||
} else {
|
} else {
|
||||||
create_name:
|
create_name:
|
||||||
retries = 5;
|
retries = 5;
|
||||||
if (virNetDevMacVLanCreateMutexInitialize() < 0)
|
|
||||||
return -1;
|
|
||||||
virMutexLock(&virNetDevMacVLanCreateMutex);
|
virMutexLock(&virNetDevMacVLanCreateMutex);
|
||||||
for (c = 0; c < 8192; c++) {
|
for (c = 0; c < 8192; c++) {
|
||||||
snprintf(ifname, sizeof(ifname), pattern, c);
|
snprintf(ifname, sizeof(ifname), pattern, c);
|
||||||
|
@ -41,18 +41,7 @@ VIR_LOG_INIT("util.netdevveth");
|
|||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
|
|
||||||
virMutex virNetDevVethCreateMutex;
|
virMutex virNetDevVethCreateMutex = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static int virNetDevVethCreateMutexOnceInit(void)
|
|
||||||
{
|
|
||||||
if (virMutexInit(&virNetDevVethCreateMutex) < 0) {
|
|
||||||
virReportSystemError(errno, "%s", _("unable to init mutex"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(virNetDevVethCreateMutex);
|
|
||||||
|
|
||||||
static int virNetDevVethExists(int devNum)
|
static int virNetDevVethExists(int devNum)
|
||||||
{
|
{
|
||||||
@ -132,9 +121,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
|
|||||||
* We might race with other containers, but this is reasonably
|
* We might race with other containers, but this is reasonably
|
||||||
* unlikely, so don't do too many retries for device creation
|
* unlikely, so don't do too many retries for device creation
|
||||||
*/
|
*/
|
||||||
if (virNetDevVethCreateMutexInitialize() < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
virMutexLock(&virNetDevVethCreateMutex);
|
virMutexLock(&virNetDevVethCreateMutex);
|
||||||
#define MAX_VETH_RETRIES 10
|
#define MAX_VETH_RETRIES 10
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ VIR_LOG_INIT("util.nodesuspend");
|
|||||||
static unsigned int nodeSuspendTargetMask;
|
static unsigned int nodeSuspendTargetMask;
|
||||||
static bool nodeSuspendTargetMaskInit;
|
static bool nodeSuspendTargetMaskInit;
|
||||||
|
|
||||||
static virMutex virNodeSuspendMutex;
|
static virMutex virNodeSuspendMutex = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static bool aboutToSuspend;
|
static bool aboutToSuspend;
|
||||||
|
|
||||||
@ -61,20 +61,6 @@ static void virNodeSuspendUnlock(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virNodeSuspendOnceInit(void)
|
|
||||||
{
|
|
||||||
if (virMutexInit(&virNodeSuspendMutex) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Unable to initialize mutex"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(virNodeSuspend)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virNodeSuspendSetNodeWakeup:
|
* virNodeSuspendSetNodeWakeup:
|
||||||
* @alarmTime: time in seconds from now, at which the RTC alarm has to be set.
|
* @alarmTime: time in seconds from now, at which the RTC alarm has to be set.
|
||||||
@ -178,9 +164,6 @@ int nodeSuspendForDuration(unsigned int target,
|
|||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (virNodeSuspendInitialize() < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (virNodeSuspendGetTargetMask(&supported) < 0)
|
if (virNodeSuspendGetTargetMask(&supported) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -267,9 +250,6 @@ virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
|
|||||||
int status;
|
int status;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (virNodeSuspendInitialize() < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
*supported = false;
|
*supported = false;
|
||||||
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
|
@ -56,7 +56,7 @@ enum {
|
|||||||
|
|
||||||
static char randomState[RANDOM_STATE_SIZE];
|
static char randomState[RANDOM_STATE_SIZE];
|
||||||
static struct random_data randomData;
|
static struct random_data randomData;
|
||||||
static virMutex randomLock;
|
static virMutex randomLock = VIR_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -74,9 +74,6 @@ virRandomOnceInit(void)
|
|||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (virMutexInit(&randomLock) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (initstate_r(seed,
|
if (initstate_r(seed,
|
||||||
randomState,
|
randomState,
|
||||||
sizeof(randomState),
|
sizeof(randomState),
|
||||||
|
@ -71,6 +71,11 @@ struct virOnceControl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# define VIR_MUTEX_INITIALIZER \
|
||||||
|
{ \
|
||||||
|
.lock = PTHREAD_MUTEX_INITIALIZER \
|
||||||
|
}
|
||||||
|
|
||||||
# define VIR_ONCE_CONTROL_INITIALIZER \
|
# define VIR_ONCE_CONTROL_INITIALIZER \
|
||||||
{ \
|
{ \
|
||||||
.once = PTHREAD_ONCE_INIT \
|
.once = PTHREAD_ONCE_INIT \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user