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

C:/temp/src/j2k/nto/bak2/Basic_PThread.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__Basic_PThread_CPP__
00002 #define __J2K__Basic_PThread_CPP__
00003 
00004 /*************************************************************************
00005  **  FILE NAME   : Basic_PThread.cpp                                    **
00006  **  CLASS NAME  : Basic_PThread                                        **
00007  **  DESCRIPTION : This class allows the creation of Generic Thread     **
00008  **                which takes care of the internals                    **
00009  **                of the PThread features. Any other subsequent        **
00010  **                classes can use this thread, or can appear as thread **
00011  **                just by inheriting from this basic class.            **
00012  **                just by inheriting from this basic class.            **
00013  **                just by inheriting from this basic class.            **
00014  *************************************************************************/
00015 
00016 #include <j2k/nto/Basic_PThread.hpp>
00017 
00018 /**************************************************************
00019 ***************************************************************
00020 ***  Attribute         Default Value                        ***
00021 ***  =========         =============                        *** 
00022 ***   detachstate       PTHREAD_CREATE_JOINABLE             *** 
00023 ***   schedpolicy       PTHREAD_INHERIT_SCHED               ***
00024 ***   schedparam        Inherited from parent PThread       *** 
00025 ***   contentionscope   PTHREAD_SCOPE_SYSTEM                *** 
00026 ***   stacksize         4096                                *** 
00027 ***   stackaddr         NULL                                ***
00028 ***************************************************************
00029 **************************************************************/
00030 
00031  // INVALID arg attr !
00032 
00033  void Basic_PThread::start( int start_prio )
00034  {
00035    if ( pid >= 0 && (signed long)pid != INVALID_PID ) return;
00036 
00037    memset( &attr,  0, sizeof( attr  ) );
00038    memset( &param, 0, sizeof( param ) );
00039 
00040    register int rc = EOK;
00041 
00042    rc = pthread_attr_init(            &attr );
00043    MC_OnError( rc, Error, "while initializing a basic pthread attribute." )
00044 
00045    rc = pthread_attr_setdetachstate(  &attr, PTHREAD_CREATE_DETACHED );
00046    MC_OnError( rc, Error, "while setting a basic pthread attribute to detached." )
00047 
00048    rc = pthread_attr_setscope(        &attr, PTHREAD_SCOPE_SYSTEM );
00049    MC_OnError( rc, Error, "while setting a basic pthread attribute to system scope." )
00050 
00051    rc = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );   
00052    MC_OnError( rc, Error, "while setting a basic pthread attribute to explicit scheduling." )
00053 
00054    priority = start_prio;
00055    attr.param.sched_priority = start_prio;
00056 
00057    rc = pthread_attr_setschedpolicy( &attr, SCHED_RR );
00058    MC_OnError( rc, Error, "while setting a this pthread parameter to Round-Robin." )
00059 
00060    // Call the static Wrapper() which will call the dynamic run()
00061    rc = pthread_create( &pid, &attr, Wrapper, (void*)this );
00062 
00063    if ( rc == -1 ) {
00064      printf( "Forgot to include libraries:" 
00065              "g++ -lpthread -lrt -lsocket -lnsl -g Basic_PThread.cpp" );
00066    }
00067 
00068    MC_OnError( rc, Error, "while starting a basic pthread." )
00069 
00070    pthread_detach( pid );
00071 
00072    // pthread_exit( NULL );
00073  }
00074 
00075 #endif

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