[libvirt] [PATCH 1/5] Add a read/write lock implementation

Eric Blake eblake at redhat.com
Mon Jan 27 18:17:32 UTC 2014


On 01/23/2014 05:37 AM, Daniel P. Berrange wrote:
> Add virRWLock backed up by a POSIX rwlock primitive
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  src/libvirt_private.syms    |  5 +++++
>  src/util/virthread.h        | 10 ++++++++++
>  src/util/virthreadpthread.c | 31 +++++++++++++++++++++++++++++++
>  src/util/virthreadpthread.h |  4 ++++
>  4 files changed, 50 insertions(+)
> 

> +int virRWLockInit(virRWLockPtr m)
> +{
> +    if (pthread_rwlock_init(&m->lock, NULL) != 0) {
> +        errno = EINVAL;

Wouldn't this be better as:

int rc = pthread_rwlock_init(&m->lock, NULL);
if (rc) {
    errno = rc;
    return -1;
}
return 0;

so that we aren't clobbering non-EINVAL errors?


> +void virRWLockDestroy(virRWLockPtr m)
> +{
> +    pthread_rwlock_destroy(&m->lock);
> +}
> +
> +
> +void virRWLockRead(virRWLockPtr m)
> +{
> +    pthread_rwlock_rdlock(&m->lock);

Worth a VIR_DEBUG on failure of these functions, to help diagnose
incorrect usage?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140127/2e15fc32/attachment-0001.sig>


More information about the libvir-list mailing list