int __CBeginThread( thread_fn *start_addr, int prio, const char *thread_name, unsigned stack_size, void *arglist ) /************************************************************/ { thread_args *td; int th; __InitMultipleThread(); td = malloc( sizeof( *td ) ); if( td == NULL ) { return( -1L ); } td->rtn = start_addr; td->argument = arglist; td->signal = RdosGetThreadHandle(); RdosClearSignal(); RdosCreateKernelThread( prio, stack_size, begin_thread_helper, thread_name, td ); RdosWaitForSignal(); th = td->tid; free( td ); return( th ); }
struct TDebug *GetCurrentDebug() { int i; int handle = RdosGetThreadHandle(); for( i = 0; i < MAX_DEBUG_THREADS; i++ ) if( ThreadArr[i] == handle ) return( DebugArr[i] ); return( 0 ); }
static void __far begin_thread_helper( void *param ) /********************************************************/ { thread_args *td = (thread_args *)param; thread_fn *rtn; void *arg; td->tid = RdosGetThreadHandle(); rtn = td->rtn; arg = td->argument; RdosSignal( td->signal ); (*rtn)( arg ); _endthread(); return; }
static void begin_thread_helper( void *param ) /********************************************************/ { thread_args *td = (thread_args *)param; thread_fn *rtn; void *arg; thread_data *tdata; int thread_handle; REGISTRATION_RECORD rr; td->tid = RdosGetThreadHandle(); rtn = td->rtn; arg = td->argument; thread_handle = td->thread_handle; RdosSetSignal( td->signal ); tdata = (thread_data *)RdosAllocateMem( __ThreadDataSize ); if( tdata != NULL ) { memset( tdata, 0, __ThreadDataSize ); tdata->__data_size = __ThreadDataSize; if( !__RdosAddThread( tdata ) ) { // print runtime error message now ? return; } } // now get the thread_data ptr the 'standard' way -- this may cause // a new thread_data structure to be allocated on heap: tdata = __THREADDATAPTR; if( tdata == NULL ) { // this is a library runtime error, should we print an error message ? return; } __NewExceptionFilter( &rr ); __sig_init_rtn(); // fills in a thread-specific copy of signal table (*rtn)( arg ); _endthread(); RdosFreeMem(tdata); return; }
void SetCurrentDebug( struct TDebug *obj ) { int i; int handle = RdosGetThreadHandle(); for( i = 0; i < MAX_DEBUG_THREADS; i++ ) { if( ThreadArr[i] == handle ) { ThreadArr[i] = 0; DebugArr[i] = 0; break; } } if( obj ) { for( i = 0; i < MAX_DEBUG_THREADS; i++ ) { if( ThreadArr[i] == 0) { ThreadArr[i] = handle; DebugArr[i] = obj; } } } }