00001 #ifndef __J2K__Basic_PThread_CPP__
00002 #define __J2K__Basic_PThread_CPP__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <j2k/nto/Basic_PThread.hpp>
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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( ¶m, 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
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
00073 }
00074
00075 #endif