diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 842e47101e07d93fc9058aa3d56c1cfac25e33ee..6915b920e66049cec6a09eb440100d808b40a27e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1958,6 +1958,11 @@ virMutexInitRecursive; virMutexLock; virMutexUnlock; virOnce; +virRWLockDestroy; +virRWLockInit; +virRWLockRead; +virRWLockUnlock; +virRWLockWrite; virThreadCancel; virThreadCreate; virThreadID; diff --git a/src/util/virthread.h b/src/util/virthread.h index 84d3bdc8287b48f7b5587f3a5fc9860c3ac8e35f..7015d6008261ebfacf007bf11b0da79f265ee7d7 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -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); diff --git a/src/util/virthreadpthread.c b/src/util/virthreadpthread.c index ca841e49782591b577fc9c0146d56b6c1f745490..38b6454c27efadb0eee9403dd2e6fbfe6fb783ea 100644 --- a/src/util/virthreadpthread.c +++ b/src/util/virthreadpthread.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; diff --git a/src/util/virthreadpthread.h b/src/util/virthreadpthread.h index b9f1319fc1098dec24ae2bf32a697f1f73f0e4f2..cb607d0d72a1c6b630498e46deb603f47167ef0d 100644 --- a/src/util/virthreadpthread.h +++ b/src/util/virthreadpthread.h @@ -27,6 +27,10 @@ struct virMutex { pthread_mutex_t lock; }; +struct virRWLock { + pthread_rwlock_t lock; +}; + struct virCond { pthread_cond_t cond; }; diff --git a/src/util/virthreadwin32.c b/src/util/virthreadwin32.c index 5d6277f246cd6465c7181733fc90f7f2b43b03f5..a9e235384e424948a601c51e078cf747bf6efc69 100644 --- a/src/util/virthreadwin32.c +++ b/src/util/virthreadwin32.c @@ -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) { diff --git a/src/util/virthreadwin32.h b/src/util/virthreadwin32.h index 645031b696ada3d58e146d37d30fa0c084cae34c..31d9444cc1943f55f3ebf9ee1457d3bfcb86e971 100644 --- a/src/util/virthreadwin32.h +++ b/src/util/virthreadwin32.h @@ -30,6 +30,10 @@ struct virMutex { HANDLE lock; }; +struct virRWLock { + bool ignored; +}; + struct virCond { virMutex lock; size_t nwaiters;