[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



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 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

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]