Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/Thread.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__Thread_CPP__
00002 #define __J2K__Thread_CPP__
00003 
00004 #include <j2k/Fred/QNX/Thread.hpp>
00005 
00006 // Assign default values and set PID = -1
00007 // to indicate that no thread was created yet.
00008 inline Thread()
00009   : start_stack( DEFAULT_STACK ), 
00010     start_algo(  DEFAULT_ALGO  ), 
00011     start_prio(  DEFAULT_PRIO  ), 
00012     start_param( NULL ),
00013     pid( -1 )
00014     { }
00015 
00016 // , MC_Serialization( THREAD_SERIAL )
00017 
00018 // beginthread() can only call STATIC functions.
00019 static void FAR Thread::Wrapper( void* ptrThis ) 
00020 {
00021   Thread* me = (Thread*)ptrThis;
00022   me->run();  // Run the Thread implemented by it's children
00023 
00024   // run() should contain an Infinite Loop, i.e. for(;;) { ... }
00025   // Exit beautifully, just in case there is no infinite loop.
00026 
00027   _endthread();   
00028 }
00029 
00030 void Thread::start( size_t stack_size, int alg, int prio ) {
00031   if ( pid > 0 ) {
00032     _endthread();  // Kill current Thread.
00033   }
00034 
00035   // Call the static Wrapper() which will call the dynamic run()
00036   pid = _beginthread( &Wrapper, NULL, stack_size, this );
00037   qnx_scheduler( 0, pid, alg, prio, 0);
00038 
00039   start_param = getSchedulerParams();
00040 
00041   start_stack( stack_size );
00042   start_algo(  alg  );
00043   start_prio(  prio );
00044 }
00045 
00046 inline void Thread::stop() {
00047   _endthread();
00048   pid = -1;
00049 }
00050 
00051 inline int Thread::getPriority() {
00052   return getprio( pid );
00053 }
00054 
00055 inline void Thread::setPriority( int prio ) {
00056   setprio( pid, prio );
00057 }
00058 
00059 inline void Thread::resetPriority() {
00060   setprio( pid, start_prio );
00061 }
00062 
00063 inline int Thread::getScheduler() { 
00064   return sched_getscheduler( pid );
00065 }
00066 
00067 inline void Thread::setScheduler( int sched ) {
00068   struct sched_param* param;
00069   sched_getparam( pid, param );
00070   sched_setscheduler( pid, sched, param );
00071 }
00072 
00073 inline void Thread::resetScheduler() {
00074   setScheduler( start_algo );
00075 }
00076 
00077 inline struct sched_param*  Thread::getSchedulerParam() {
00078 }
00079 
00080 inline void Thread::setSchedulerParam( struct sched_param* param ) {
00081 }
00082 
00083 inline void Thread::resetSchedulerParam() {
00084 }
00085 
00086 inline Thread::~Thread() {
00087   stop();
00088 }
00089 
00090 inline pid_t Thread::getPID() {
00091   return pid;
00092 }
00093 
00094 inline int Thread::isStarted() {
00095   return ( pid > 0 );
00096 }
00097 
00098 // Kill the old version of Thread and Start it again.
00099 // Return, if Thread was not started.
00100 void Thread::refresh() 
00101 {
00102   if (pid < 1) return;
00103   _endthread();
00104   start( start_stack, start_algo, start_prio );
00105 }
00106 
00107 #endif

Generated on Sun Oct 14 18:46:42 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001