[libvirt] [PATCH 02/21] Implement a RWLock primitive for drivers to use

Daniel Veillard veillard at redhat.com
Wed Oct 28 16:15:05 UTC 2009


On Fri, Oct 23, 2009 at 02:05:31PM +0100, Daniel P. Berrange wrote:
> This implements a thin wrapper around the pthread_rwlock
> primitives. No impl is provided for Win32 at this time
> since it is rather hard, and none of our code yet requires
> it on Win32
> 
> * src/util/threads.h: Add virRWLockInit, virRWLockDestroy,
>   virRWLockRead, virRWLockWrite, virRWLockUnlock APIs
> * src/util/threads-pthread.h: define virRWLock  struct
> * src/util/threads-pthread.c: Implement RWLock APIs
> ---
>  src/libvirt_private.syms   |    6 ++++++
>  src/util/threads-pthread.c |   30 ++++++++++++++++++++++++++++++
>  src/util/threads-pthread.h |    4 ++++
>  src/util/threads.h         |   10 ++++++++++
>  4 files changed, 50 insertions(+), 0 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index bd9d84a..6ed562d 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -426,6 +426,12 @@ virCondWait;
>  virCondSignal;
>  virCondBroadcast;
>  
> +virRWLockInit;
> +virRWLockDestroy;
> +virRWLockRead;
> +virRWLockWrite;
> +virRWLockUnlock;
> +
>  # util.h
>  virFileReadAll;
>  virFileWriteStr;
> diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c
> index 4e00bc5..2052c0a 100644
> --- a/src/util/threads-pthread.c
> +++ b/src/util/threads-pthread.c
> @@ -57,6 +57,36 @@ void virMutexUnlock(virMutexPtr m)
>  }
>  
>  
> +int virRWLockInit(virRWLockPtr m)
> +{
> +    if (pthread_rwlock_init(&m->lock, NULL) != 0) {
> +        errno = EINVAL;
> +        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);
> +}
> +
> +

  Hum it's a small patch, but I would rather fix those function to not
be void when the underlying pthread_ counterpart can actually fail.
IMHO we should report errors coming from the thread library (whichever
is used on a given platform).

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list