提交 6f1e2aba 编写于 作者: D Daniel P. Berrange 提交者: Laine Stump

Add a read/write lock implementation

Add virRWLock backed up by a POSIX rwlock primitive
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
(cherry picked from commit c065984b)
上级 6bd52b9c
......@@ -1958,6 +1958,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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册