osbthread.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.10 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _OSBTHREAD_H_
00031 #define _OSBTHREAD_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <pthread.h>
00037 
00038 // + libraries
00039 
00040 // + local headers
00041 
00042 // + class declarations
00043 
00044 // ************************************************************************
00045 // namespace extensions
00046 namespace OSB_APP {
00047 
00048 // ************************************************************************
00049 // free functions
00065     extern "C" void* callThreadFunction(void* threadBase);
00066 
00067 // ************************************************************************
00068 // class definitions
00069 
00073     class ThreadBase {
00074         // Allow to call ThreadBase::threadFunction and
00075         // ThreadBase::hasReturned.
00076         friend void* callThreadFunction(void* threadBase);
00077     public:
00079         ThreadBase(int id = 0);
00081         virtual ~ThreadBase();
00082 
00093         virtual int start();
00095         bool running() const;
00097         int stop() const;
00104         int rc() const;
00105 
00107         int stop(int newStop);
00124         virtual int join(
00125             bool doStop,
00126             int  signum  = 0
00127         );
00128     public:
00130         int id_;
00131 
00132     protected:
00141         virtual void threadFunction() = 0;
00143         int lock() const;
00145         int unlock() const;
00147         void rc(int ret);
00148 
00149     private:
00151         void hasReturned();
00152     private:
00159         bool running_;
00160 
00161     protected:
00163         int stop_;
00165         int rc_;
00167         pthread_t  thread_;
00169         mutable pthread_mutex_t mutex_;
00170     };
00171 
00172 }                                       // namespace OSB_APP
00173 #endif                                  // #ifndef _OSBTHREAD_H_

Generated on Sat Sep 2 14:17:18 2006 for OSB Library by  doxygen 1.4.7