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

wefts_counter.h

Go to the documentation of this file.
00001 /*
00002    wefts_counter.h
00003    Shared counter.
00004 
00005    $Id: wefts_counter.h,v 1.3 2003/08/13 14:58:52 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_COUNTER_H
00022 #define WT_COUNTER_H
00023 
00024 #include <wefts_fastcond.h>
00025 
00026 namespace Wefts {
00027 
00049 class Counter: public FastCondition
00050 {
00051 private:
00053    volatile int m_count;
00054 
00055 public:
00059    Counter( int count = 0 ) { m_count = count; }
00060 
00065    int count() { return m_count; }
00066 
00071    void set( int value ) { m_count = value; }
00072 
00078    void count( int value ) { lock(); m_count = value; signal(); unlock();}
00079 
00084    void increment( int amount ) { lock(); m_count += amount; signal(); unlock();}
00085 
00089    void increment() { lock(); m_count ++; signal(); unlock(); }
00090 
00094    void decrement() { lock(); m_count --; signal(); unlock();}
00095 
00101    bool until( int level, double time = 0 )
00102    {
00103       lock();
00104       while( level != m_count ) {
00105          if ( time == 0 ) {
00106             if (! wait() )
00107                return false;
00108          }
00109          else {
00110             if (! wait( time ) )
00111                return false;
00112          }
00113       }
00114       unlock();
00115       return true;
00116    }
00117 
00118 
00119 };
00120 
00121 }
00122 
00123 #endif
00124 /* end of wefts_counter.h */

Generated on Mon Aug 18 05:53:37 2003 for Wefts by doxygen1.2.18