Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

wefts_cond.h

Go to the documentation of this file.
00001 /*
00002    wefts_cond.h
00003    Abstract class implementing a condition variable.
00004 
00005    $Id: wefts_cond.h,v 1.2 2003/08/05 15:40:20 jonnymind Exp $
00006 ----------------------------------------------
00007    Begin      : 2003-08-02 00:10
00008    Author     : Giancarlo Niccolai
00009 
00010    Last modified because:
00011 
00012 */
00013 
00014 /**************************************************************************
00015 *   This program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU Library General Public License as       *
00017 *   published by the Free Software Foundation; either version 2.1 of the  *
00018 *   License, or (at your option) any later version.                       *
00019 ***************************************************************************/
00020 
00021 #ifndef WT_COND_H
00022 #define WT_COND_H
00023 
00024 #include <wefts_mutex.h>
00025 #include <sys/time.h>
00026 
00027 
00028 namespace Wefts {
00029 
00042 class Cond
00043 {
00044 protected:
00046    pthread_cond_t m_cond;
00051    pthread_mutex_t *m_my_mutex;
00052 
00053 protected:
00056    Cond() { pthread_cond_init( &m_cond, NULL ); }
00057    ~Cond() { pthread_cond_destroy( &m_cond ); }
00058 
00059 public:
00064    virtual inline int wait() { return pthread_cond_wait( &m_cond, m_my_mutex ); }
00065 
00066 
00078    virtual inline int wait( long seconds, long nanoseconds)
00079    {
00080       struct timeval now;
00081       struct timespec timeout;
00082 
00083       gettimeofday(&now, NULL);
00084       timeout.tv_sec = now.tv_sec + seconds;
00085       timeout.tv_nsec = now.tv_usec * 1000 + nanoseconds;
00086       return pthread_cond_timedwait(&m_cond, m_my_mutex, &timeout);
00087    }
00088 
00089 
00096    inline int wait( double seconds )
00097    {
00098       return wait( long( seconds ),
00099          long( (seconds - long(seconds)) *1000000000l) );
00100    }
00101 
00105    virtual inline void signal() { pthread_cond_broadcast( &m_cond ); }
00106 };
00107 
00108 }
00109 
00110 #endif
00111 /* end of wefts_cond.h */

Generated on Tue Aug 5 18:09:00 2003 for Wefts by doxygen1.2.18