Re: [libvirt] [PATCH] util: ensure virMutexInit is not recursive

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

 



On Thu, Mar 18, 2010 at 11:32:16AM -0600, Eric Blake wrote:
> POSIX states that creation of a mutex with default attributes
> is unspecified whether the mutex is recursive or non-recursive.
> We specifically want non-recursive (deadlock is desirable in
> flushing out coding bugs that used our mutex incorrectly).
> 
> * src/util/threads-pthread.c (virMutexInit): Specifically request
> non-recursive mutex, rather than relying on unspecified default.
> ---
>  src/util/threads-pthread.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c
> index ad42483..2f0746b 100644
> --- a/src/util/threads-pthread.c
> +++ b/src/util/threads-pthread.c
> @@ -1,7 +1,7 @@
>  /*
>   * threads-pthread.c: basic thread synchronization primitives
>   *
> - * Copyright (C) 2009 Red Hat, Inc.
> + * Copyright (C) 2009-2010 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -36,7 +36,10 @@ void virThreadOnExit(void)
>  int virMutexInit(virMutexPtr m)
>  {
>      int ret;
> -    if ((ret = pthread_mutex_init(&m->lock, NULL)) != 0) {
> +    pthread_mutexattr_t attr;
> +    pthread_mutexattr_init(&attr);
> +    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
> +    if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) {
>          errno = ret;
>          return -1;
>      }

ACK, this is good.

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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]