Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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.13 2004/03/12 05:21:29 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_cleancond.h>
00026 
00027 namespace Wefts {
00028 
00045 class Condition
00046 {
00047 protected:
00049    OSCondition m_cond;
00054    Mutex *m_my_mutex;
00055 
00056 
00057 public:
00060    Condition( Mutex *mtx=0 )
00061    { 
00062       m_my_mutex = mtx; 
00063    }
00064     
00065    ~Condition() {}
00066 
00076    virtual inline bool wait( CleanupHandler *cup = 0, int pos = 0 ) {
00077       CleanupItem clup( cup, pos, this );
00078       return m_cond.wait( m_my_mutex->m_mutex, clup );
00079    }
00080 
00088    void setMutex( Mutex *mtx) { m_my_mutex = mtx; }
00089    /* Returns the mutex used by this condition. */
00090    Mutex *getMutex() { return m_my_mutex; }
00091 
00110    virtual inline bool wait( long seconds, long nanoseconds, CleanupHandler *cup = 0, int pos = 0)
00111    {
00112       CleanupItem clup( cup, pos, this );
00113       return m_cond.timedWait( m_my_mutex->m_mutex, seconds, nanoseconds, clup );
00114    }
00115 
00116 
00128    inline bool wait( double seconds, CleanupHandler *cup = 0, int pos = 0 )
00129    {
00130       return wait( long( seconds ),
00131          long( (seconds - long(seconds)) *1000000000l), cup, pos );
00132    }
00133 
00137    virtual inline void signal() { m_cond.signal(); }
00138    
00149    virtual inline void signalOne() { m_cond.signalOne(); }
00150 
00151 };
00152 
00153 }
00154 
00155 #endif
00156 /* end of wefts_cond.h */

Generated on Sat Mar 13 21:05:43 2004 for Wefts by doxygen 1.3.5