Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Thread_PTHREAD.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  *              The CBITS Software License, Version 1.0
00003  *
00004  *               Copyright (c) 2002-2003 Bruce Lowery
00005  *                       All rights reserved
00006  *
00007  * Redistribution and use of this software, in source and binary forms,
00008  * with or without modification, are permitted provided that the above
00009  * copyright notice, this paragraph, and the following paragraph are
00010  * retained in each source code file.
00011  *
00012  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00013  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00014  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00015  * DISCLAIMED.  IN NO EVENT SHALL BRUCE LOWERY OR OTHER CONTRIBUTORS
00016  * TO THE CBITS LIBRARY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00017  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00018  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00019  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00020  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00021  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00022  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00023  * SUCH DAMAGE.
00024  * ====================================================================
00025  */
00026 #ifndef __THREAD_PTHREAD_H__
00027 #define __THREAD_PTHREAD_H__
00028 
00029 #include <cbits/Runnable.h>
00030 #include <cbits/Thread.h>
00031 #include <list>
00032 
00033 #ifdef USE_PTHREADS
00034 #include <pthread.h>
00035 #include <sched.h>
00036 #endif
00037 
00038 
00039 #ifdef BUILD_DLL
00040 #define EXPORT __declspec(dllexport)
00041 #else
00042 #define EXPORT
00043 #endif
00044 
00045 
00046 namespace cbits
00047 {
00048 
00049 
00057 class EXPORT Thread_PTHREAD : public virtual Thread
00058 {
00059 
00060 public:
00061 
00066     Thread_PTHREAD
00067     ( 
00069         Runnable* r,
00070 
00072         const Priority p = DEFAULT_PRIORITY
00073     );
00074 
00075 
00084     static Thread* get_current_thread();
00085 
00086 
00091     static void    yield();
00092     
00093 
00098     virtual ~Thread_PTHREAD();
00099 
00100 
00101 protected:
00102     virtual const bool impl_create_thread( const Priority );
00103     virtual const bool impl_start_thread();
00104     virtual const long impl_get_threadid() const;
00105     virtual       void impl_lock_obj() const;
00106     virtual       void impl_unlock_obj() const;
00107     virtual       void impl_interrupt();
00108     virtual const bool impl_join( const long msec );
00109     virtual void impl_sleep( const long msec );
00110 
00111 private:
00112 
00119     static void* run_thread
00120     ( 
00122         void* thread_ptr
00123     );
00124 
00125 
00129     static void  cleanup
00130     ( 
00132         void* t 
00133     );
00134 
00135 
00142     const long getTid() const;
00143 
00144 
00148     static std::list<Thread_PTHREAD*> _threads;
00149 
00150 
00154     static std::list<Thread_PTHREAD*>& getThreadList();
00155 
00156 
00157 #ifdef USE_PTHREADS
00158 
00160     pthread_cond_t _start_cv;
00161 
00163     pthread_mutex_t _start_cv_lk;
00164 
00169     static pthread_mutex_t _tlist_mutex;
00170 
00175     static pthread_mutex_t* getThreadListLock();
00176 
00178     pthread_t                _thr;
00179 
00181     pthread_attr_t           _attr;
00182 
00184     struct sched_param       _tsched;
00185 
00187     mutable pthread_mutex_t  _lock;
00188 #endif
00189 
00191     long  _tid;
00192 
00193 
00194 }; /* END OF CLASS Thread_PTHREAD */
00195 
00196 }; /* END OF NAMESPACE cbits */
00197 
00198 #endif
00199 
00200 /*
00201  * $Id: Thread_PTHREAD.h,v 1.11 2002/10/16 02:47:20 brulow Exp $
00202  *
00203  * History: (Add nothing manually below)
00204  * -----------------------------------------------------------------------
00205  *
00206  * $Log: Thread_PTHREAD.h,v $
00207  * Revision 1.11  2002/10/16 02:47:20  brulow
00208  * build libs with compiler instead of raw 'ld'.
00209  *
00210  * Revision 1.10  2002/10/07 21:07:45  brulow
00211  * Add/improve documentation
00212  *
00213  * Revision 1.9  2002/10/06 04:13:01  brulow
00214  * Add unit thread pkg unit tests and fix thread pkg bugs.
00215  *
00216  * Revision 1.8  2002/10/05 15:48:50  brulow
00217  * Add 'sleep' to Thread interface;
00218  * Add synchronization between creator and new thread.
00219  *
00220  * Revision 1.7  2002/10/05 03:38:37  brulow
00221  * Fix bug in Thread package and unit test
00222  *
00223  * Revision 1.6  2002/10/04 13:57:19  brulow
00224  * Include sched.h
00225  *
00226  * Revision 1.5  2002/10/04 03:02:17  brulow
00227  * Fix 'undefined virtual table' problem in ResourceLock_XX classes
00228  *
00229  * Revision 1.4  2002/10/03 15:09:23  brulow
00230  * Add footer
00231  *
00232  *
00233  */

Generated by
doxygen
Hosted by
SourceForge