mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
Add a read/write lock implementation
Add virRWLock backed up by a POSIX rwlock primitive
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit c065984b58
)
This commit is contained in:
parent
11a31c0880
commit
7596594301
@ -1774,6 +1774,11 @@ virMutexInitRecursive;
|
||||
virMutexLock;
|
||||
virMutexUnlock;
|
||||
virOnce;
|
||||
virRWLockDestroy;
|
||||
virRWLockInit;
|
||||
virRWLockRead;
|
||||
virRWLockUnlock;
|
||||
virRWLockWrite;
|
||||
virThreadCancel;
|
||||
virThreadCreate;
|
||||
virThreadID;
|
||||
|
@ -28,6 +28,9 @@
|
||||
typedef struct virMutex virMutex;
|
||||
typedef virMutex *virMutexPtr;
|
||||
|
||||
typedef struct virRWLock virRWLock;
|
||||
typedef virRWLock *virRWLockPtr;
|
||||
|
||||
typedef struct virCond virCond;
|
||||
typedef virCond *virCondPtr;
|
||||
|
||||
@ -89,6 +92,13 @@ void virMutexLock(virMutexPtr m);
|
||||
void virMutexUnlock(virMutexPtr m);
|
||||
|
||||
|
||||
int virRWLockInit(virRWLockPtr m) ATTRIBUTE_RETURN_CHECK;
|
||||
void virRWLockDestroy(virRWLockPtr m);
|
||||
|
||||
void virRWLockRead(virRWLockPtr m);
|
||||
void virRWLockWrite(virRWLockPtr m);
|
||||
void virRWLockUnlock(virRWLockPtr m);
|
||||
|
||||
|
||||
int virCondInit(virCondPtr c) ATTRIBUTE_RETURN_CHECK;
|
||||
int virCondDestroy(virCondPtr c);
|
||||
|
@ -91,6 +91,39 @@ void virMutexUnlock(virMutexPtr m)
|
||||
}
|
||||
|
||||
|
||||
int virRWLockInit(virRWLockPtr m)
|
||||
{
|
||||
int ret;
|
||||
ret = pthread_rwlock_init(&m->lock, NULL);
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void virRWLockDestroy(virRWLockPtr m)
|
||||
{
|
||||
pthread_rwlock_destroy(&m->lock);
|
||||
}
|
||||
|
||||
|
||||
void virRWLockRead(virRWLockPtr m)
|
||||
{
|
||||
pthread_rwlock_rdlock(&m->lock);
|
||||
}
|
||||
|
||||
void virRWLockWrite(virRWLockPtr m)
|
||||
{
|
||||
pthread_rwlock_wrlock(&m->lock);
|
||||
}
|
||||
|
||||
|
||||
void virRWLockUnlock(virRWLockPtr m)
|
||||
{
|
||||
pthread_rwlock_unlock(&m->lock);
|
||||
}
|
||||
|
||||
int virCondInit(virCondPtr c)
|
||||
{
|
||||
int ret;
|
||||
|
@ -27,6 +27,10 @@ struct virMutex {
|
||||
pthread_mutex_t lock;
|
||||
};
|
||||
|
||||
struct virRWLock {
|
||||
pthread_rwlock_t lock;
|
||||
};
|
||||
|
||||
struct virCond {
|
||||
pthread_cond_t cond;
|
||||
};
|
||||
|
@ -121,6 +121,25 @@ void virMutexUnlock(virMutexPtr m)
|
||||
}
|
||||
|
||||
|
||||
int virRWLockInit(virRWLockPtr m ATTRIBUTE_UNUSED)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void virRWLockDestroy(virRWLockPtr m ATTRIBUTE_UNUSED)
|
||||
{}
|
||||
|
||||
|
||||
void virRWLockRead(virRWLockPtr m ATTRIBUTE_UNUSED)
|
||||
{}
|
||||
|
||||
void virRWLockWrite(virRWLockPtr m ATTRIBUTE_UNUSED)
|
||||
{}
|
||||
|
||||
|
||||
void virRWLockUnlock(virRWLockPtr m ATTRIBUTE_UNUSED)
|
||||
{}
|
||||
|
||||
int virCondInit(virCondPtr c)
|
||||
{
|
||||
|
@ -30,6 +30,10 @@ struct virMutex {
|
||||
HANDLE lock;
|
||||
};
|
||||
|
||||
struct virRWLock {
|
||||
bool ignored;
|
||||
};
|
||||
|
||||
struct virCond {
|
||||
virMutex lock;
|
||||
unsigned int nwaiters;
|
||||
|
Loading…
Reference in New Issue
Block a user