Re: [libvirt] [PATCH 03/15] Add a new timed condition variable wait API

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

 



On Tue, Nov 03, 2009 at 02:49:57PM -0500, Daniel P. Berrange wrote:
> * src/util/threads.h, src/util/threads-pthread.c,
>   src/libvirt_private.syms: Add virCondWaitUntil()
> ---
>  src/libvirt_private.syms   |    1 +
>  src/util/threads-pthread.c |   15 +++++++++++++++
>  src/util/threads.h         |    1 +
>  3 files changed, 17 insertions(+), 0 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 1e4a3dd..600dfee 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -443,6 +443,7 @@ virMutexUnlock;
>  virCondInit;
>  virCondDestroy;
>  virCondWait;
> +virCondWaitUntil;
>  virCondSignal;
>  virCondBroadcast;
>  
> diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c
> index b3ec06e..ad42483 100644
> --- a/src/util/threads-pthread.c
> +++ b/src/util/threads-pthread.c
> @@ -88,6 +88,21 @@ int virCondWait(virCondPtr c, virMutexPtr m)
>      return 0;
>  }
>  
> +int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms)
> +{
> +    int ret;
> +    struct timespec ts;
> +
> +    ts.tv_sec = whenms / 1000;
> +    ts.tv_nsec = (whenms % 1000) * 1000;
> +
> +    if ((ret = pthread_cond_timedwait(&c->cond, &m->lock, &ts)) != 0) {
> +        errno = ret;
> +        return -1;
> +    }
> +    return 0;
> +}
> +
>  void virCondSignal(virCondPtr c)
>  {
>      pthread_cond_signal(&c->cond);
> diff --git a/src/util/threads.h b/src/util/threads.h
> index 62239b7..d97463d 100644
> --- a/src/util/threads.h
> +++ b/src/util/threads.h
> @@ -49,6 +49,7 @@ int virCondInit(virCondPtr c) ATTRIBUTE_RETURN_CHECK;
>  int virCondDestroy(virCondPtr c) ATTRIBUTE_RETURN_CHECK;
>  
>  int virCondWait(virCondPtr c, virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
> +int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms) ATTRIBUTE_RETURN_CHECK;
>  void virCondSignal(virCondPtr c);
>  void virCondBroadcast(virCondPtr c);
>  

  Haha, now I understand the slight change and why it's the thread
  waiting which gets to timeout, simpler, and probably as practical

  ACK

Daniel

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

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