mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: ensure virMutexInit is not recursive
POSIX states that creation of a mutex with default attributes is unspecified whether the mutex is recursive or non-recursive. We specifically want non-recursive (deadlock is desirable in flushing out coding bugs that used our mutex incorrectly). * src/util/threads-pthread.c (virMutexInit): Specifically request non-recursive mutex, rather than relying on unspecified default.
This commit is contained in:
parent
fc148ca133
commit
336fd879c0
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* threads-pthread.c: basic thread synchronization primitives
|
* threads-pthread.c: basic thread synchronization primitives
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009 Red Hat, Inc.
|
* Copyright (C) 2009-2010 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -36,7 +36,10 @@ void virThreadOnExit(void)
|
|||||||
int virMutexInit(virMutexPtr m)
|
int virMutexInit(virMutexPtr m)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = pthread_mutex_init(&m->lock, NULL)) != 0) {
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
||||||
|
if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) {
|
||||||
errno = ret;
|
errno = ret;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user