Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File 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.10 2003/12/16 03:07:48 jonnymind Exp $
00006 ----------------------------------------------
00007    Begin      : 2003-08-02 00:10
00008    Author     : Giancarlo Niccolai
00009 
00010    Last modified because:
00011    Implementing OS independent base threading
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 <wefts_cleanup.h>
00026 
00027 namespace Wefts {
00028 
00045 class Condition
00046 {
00047 protected:
00049    OSCondition m_cond;
00054    Mutex *m_my_mutex;
00055    CleanupItem m_whenStopped;
00056 
00057 
00058 public:
00061    Condition( Mutex *mtx=0 ) { m_my_mutex = mtx; m_whenStopped.first = 0;}
00062    ~Condition() {}
00063 
00073    virtual inline bool wait() {
00074       return m_cond.wait( m_my_mutex->m_mutex, m_whenStopped );
00075    }
00076 
00077    void setMutex( Mutex *mtx) { m_my_mutex = mtx; }
00078 
00097    virtual inline bool wait( long seconds, long nanoseconds)
00098    {
00099       return m_cond.timedWait( m_my_mutex->m_mutex, seconds, nanoseconds, m_whenStopped );
00100    }
00101 
00102 
00114    inline int wait( double seconds )
00115    {
00116       return wait( long( seconds ),
00117          long( (seconds - long(seconds)) *1000000000l) );
00118    }
00119 
00123    virtual inline void signal() { m_cond.signal(); }
00124 
00134    inline void onStop( CleanupHandler *guard=0, int param=0) {
00135       m_whenStopped.first = guard;
00136       m_whenStopped.second = param;
00137    }
00138 };
00139 
00140 }
00141 
00142 #endif
00143 /* end of wefts_cond.h */

Generated on Mon Dec 22 04:12:30 2003 for Wefts by doxygen1.2.18