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

Daniel P. Berrange berrange at redhat.com
Wed Oct 28 17:53:31 UTC 2009


On Wed, Oct 28, 2009 at 05:15:05PM +0100, Daniel Veillard wrote:
> 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).

I mis-understood the manpage for this - I read it to mean these calls
would actually deadlock upon error (as a mutex would), but in fact they
return error EDEADLOCK instead which is rather unhelpful. 

I'm going to withdraw this entire patch.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list