mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +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>
This commit is contained in:
parent
94e0906839
commit
c065984b58
@ -1818,6 +1818,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;
|
||||
};
|
||||
|
@ -123,6 +123,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;
|
||||
size_t nwaiters;
|
||||
|
Loading…
Reference in New Issue
Block a user