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

wefts_thread.h

Go to the documentation of this file.
00001 /*
00002    wefts_thread.h
00003    Main thread class
00004 
00005    $Id: wefts_thread.h,v 1.2 2003/08/05 15:40:20 jonnymind Exp $
00006 ---------------------------------------------
00007    Begin      : 2003-08-02 23:45
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_THREAD_H
00022 #define WT_THREAD_H
00023 
00024 #ifdef __extern_c
00025 extern "C" {
00026 #endif
00027 
00028 #include <pthread.h>
00029 
00030 #ifdef __extern_c
00031 }
00032 #endif
00033 
00034 #include <wefts_counter.h>
00035 
00036 
00037 
00038 namespace Wefts {
00039 
00043 extern Counter runningThreads;
00044 
00049 extern Counter startedThreads;
00050 
00117 class Thread
00118 {
00119 private:
00128    inline virtual void executionEnd() { m_thid = 0; }
00129 
00131    void setCancel() { setCancel( m_canCancel ); }
00132 
00133 protected:
00135    void *m_runReturnValue;
00137    pthread_t   m_thid;
00139    bool        m_canCancel;
00141    void        *m_thread_data;
00143    bool        m_detached;
00145    bool        m_stopped;
00146 
00150    int         m_thSequence;
00151 
00159    void testCancel() { pthread_testcancel(); if ( m_stopped ) pthread_exit(0); }
00160 
00168    void setCancel( bool cando );
00169 
00170 
00171 public:
00173    Thread();
00174 
00178    virtual ~Thread();
00179 
00188    bool start( bool detachable = false, bool cancelable = true );
00189 
00197    bool stop();
00198 
00205    void detach() { m_detached = true; }
00207    bool detached() { return m_detached; }
00208 
00213    virtual void *join();
00214 
00226    bool running() { return m_thid == 0; }
00227 
00229    pthread_t getId() { return m_thid; }
00230 
00232    inline void setData( void *data ) { m_thread_data = data; }
00233 
00241    inline int  sequence() { return m_thSequence; }
00242 
00253    virtual void cleanup() {};
00254 
00288    virtual void *run()=0;
00289 
00290    friend void *s_ThreadRunFunc( void *);
00291    friend void s_ThreadCleanupper( void *);
00292 
00293 };
00294 
00295 }
00296 
00297 #endif
00298 /* end of wefts_thread.h */

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