void InitDebug( struct TDebug *obj, const char *Program, const char *Param, const char *StartDir ) { obj->FProgram = malloc( strlen( Program ) + 1 ); strcpy( obj->FProgram, Program ); obj->FParam = malloc( strlen( Param ) + 1 ); strcpy( obj->FParam, Param ); obj->FStartDir = malloc( strlen( StartDir ) + 1 ); strcpy( obj->FStartDir, StartDir ); obj->UserWait = RdosCreateWait(); obj->UserSignal = RdosCreateSignal(); RdosAddWaitForSignal( obj->UserWait, obj->UserSignal, obj ); obj->FSection = RdosCreateSection(); obj->ThreadList = 0; obj->ModuleList = 0; obj->CurrentThread = 0; obj->BreakList = 0; obj->FThreadChanged = FALSE; obj->FModuleChanged = FALSE; RdosCreateThread(DebugThread, "Debug device", obj, 0x4000); }
void InitDebug( struct TDebug *obj, const char *Program, const char *Param, const char *StartDir ) { obj->FProgram = malloc( strlen( Program ) + 1 ); strcpy( obj->FProgram, Program ); obj->FParam = malloc( strlen( Param ) + 1 ); strcpy( obj->FParam, Param ); obj->FStartDir = malloc( strlen( StartDir ) + 1 ); strcpy( obj->FStartDir, StartDir ); obj->UserWait = RdosCreateWait(); obj->UserSignal = RdosCreateSignal(); RdosAddWaitForSignal( obj->UserWait, obj->UserSignal, obj ); obj->FSection = RdosCreateSection(); obj->ThreadList = 0; obj->ModuleList = 0; obj->CurrentThread = 0; obj->NewThread = 0; obj->BreakList = 0; obj->WatchList = 0; obj->FThreadChanged = FALSE; obj->FModuleChanged = FALSE; obj->FHandle = 0; obj->FMemoryModel = DEBUG_MEMORY_MODEL_FLAT; obj->FConfigChange = FALSE; obj->FAsyncBreak = FALSE; obj->FAsyncSel = 0; obj->FAsyncOffset = 0; obj->FWaitLoad = TRUE; RdosCreateThread( DebugThread, "Debug device", obj, 0x4000 ); }
static void InitHandle( void ) { int i; rdos_handle_type *h; const char *inherit; const char *ptr; handle_section = RdosCreateSection( "Watcom.Handle" ); handle_count = 5; handle_ptr = ( rdos_handle_type ** )lib_malloc( handle_count * sizeof( rdos_handle_type * ) ); for( i = 0; i < handle_count; i++ ) handle_ptr[i] = 0; h = AllocHandleObj( 0 ); h->type = HANDLE_TYPE_INPUT; h->mode = _READ; handle_ptr[0] = h; h->ref_count++; console_in = h; h = AllocHandleObj( 0 ); h->type = HANDLE_TYPE_OUTPUT; h->mode = _WRITE; handle_ptr[1] = h; h->ref_count++; console_out = h; h->ref_count++; handle_ptr[2] = h; inherit = RdosGetOptions(); if( inherit ) ProcessInherit( inherit ); }
void __InitMultipleThread( void ) /*******************************/ { if( __GetThreadPtr != __MultipleThread ) { #if defined( _NETWARE_CLIB ) { /* __ThreadData[ 0 ] is used whenever GetThreadID() returns a pointer not in our __ThreadIDs list - ie. whenever it returns NULL, a pointer to a thread we didn't create, or an invalid pointer */ void *ptr; ptr = lib_calloc( 1, __ThreadDataSize ); if( ptr == NULL ) { __fatal_runtime_error( "Unable to allocate thread-specific data", 1 ); } __ThreadData[ 0 ].data = ptr; __ThreadData[ 0 ].allocated_entry = 1; __ThreadData[ 0 ].data->__allocated = 1; __ThreadData[ 0 ].data->__randnext = 1; __ThreadData[ 0 ].data->__data_size = __ThreadDataSize; if( __initthread( ptr ) ) { lib_free( ptr ); __fatal_runtime_error( "Unable to initialize thread-specific data", 1 ); } ptr = lib_calloc( 1, __ThreadDataSize ); if( ptr == NULL ) { __fatal_runtime_error( "Unable to allocate thread-specific data", 1 ); } __FirstThreadData = ptr; __FirstThreadData->__allocated = 1; __FirstThreadData->__randnext = 1; __FirstThreadData->__data_size = __ThreadDataSize; __ThreadData[ 1 ].data = __FirstThreadData; __ThreadData[ 1 ].allocated_entry = __FirstThreadData->__allocated; __ThreadIDs[ 1 ] = GetThreadID(); if( __initthread( ptr ) ) { lib_free( ptr ); __fatal_runtime_error( "Unable to initialize thread-specific data", 1 ); } } #elif defined( _NETWARE_LIBC ) InitSemaphore.semaphore = 0; /* sema4 is mutex in this case */ InitSemaphore.initialized = 1; //_ThreadExitRtn = &__ThreadExit; - might need this at some point?? // Note: __AddThreadData uses the InitSemaphore, _AccessTDList & _ReleaseTDList __FirstThreadData->thread_id = GetCurrentThreadId(); __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData ); if(0 != NXKeySetValue(__NXSlotID, __FirstThreadData)) { __fatal_runtime_error( "Unable to initialize thread-specific data", 1 ); } #elif defined( __NT__ ) InitSemaphore.semaphore = __NTGetCriticalSection(); InitSemaphore.initialized = 1; _ThreadExitRtn = &__ThreadExit; // Note: __AddThreadData uses the InitSemaphore, _AccessTDList & _ReleaseTDList __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData ); TlsSetValue( __TlsIndex, __FirstThreadData ); #elif defined( __QNX__ ) __qsem_init( &InitSemaphore.semaphore, 1, 1 ); InitSemaphore.initialized = 1; // first thread data already in magic memory #elif defined( __LINUX__ ) // TODO: Init semaphores for Linux #elif defined( __RDOS__ ) InitSemaphore.semaphore = RdosCreateSection(); InitSemaphore.initialized = 1; __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData ); __tls_set_value( __TlsIndex, __FirstThreadData ); #elif defined( __RDOSDEV__ ) RdosInitKernelSection( &InitSemaphore.semaphore ); InitSemaphore.initialized = 1; #elif defined( __OS2__ ) DosCreateMutexSem( NULL, &InitSemaphore.semaphore, 0, FALSE ); InitSemaphore.initialized = 1; __ThreadData[1].data = __FirstThreadData; __ThreadData[1].allocated_entry = __FirstThreadData->__allocated; #else #error Multiple thread support is not defined for this platform #endif #if !defined( _M_I86 ) // Set these up after we have created the InitSemaphore #if !defined (_THIN_LIB) _AccessFileH = &__AccessFileH; _ReleaseFileH = &__ReleaseFileH; _AccessIOB = &__AccessIOB; _ReleaseIOB = &__ReleaseIOB; #endif _AccessTDList = &__AccessTDList; _ReleaseTDList = &__ReleaseTDList; __AccessSema4 = &__AccessSemaphore; __ReleaseSema4 = &__ReleaseSemaphore; __CloseSema4 = &__CloseSemaphore; #if !defined( __NETWARE__ ) _AccessNHeap = &__AccessNHeap; _AccessFHeap = &__AccessFHeap; _ReleaseNHeap = &__ReleaseNHeap; _ReleaseFHeap = &__ReleaseFHeap; #endif #if defined( __NT__ ) _AccessFList = &__AccessFList; _ReleaseFList = &__ReleaseFList; #endif #endif __GetThreadPtr = __MultipleThread; } }
_WCRTLINK void __AccessSemaphore( semaphore_object *obj ) { TID tid; tid = GetCurrentThreadId(); #if defined( _NETWARE_CLIB ) if( tid == 0 ) return; #endif if( obj->owner != tid ) { #if defined( _M_I86 ) DosSemRequest( &obj->semaphore, -1L ); #else #if !defined( __NETWARE__ ) if( obj->initialized == 0 ) { #if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 ) if( obj == &InitSemaphore ) { __fatal_runtime_error( "Bad semaphore lock", 1 ); } #endif __AccessSemaphore( &InitSemaphore ); if( obj->initialized == 0 ) { #if defined( __NT__ ) obj->semaphore = __NTGetCriticalSection(); #elif defined( __QNX__ ) __qsem_init( &obj->semaphore, 1, 1 ); #elif defined( __LINUX__ ) // TODO: Access semaphore under Linux! #elif defined( __RDOS__ ) obj->semaphore = RdosCreateSection(); #elif defined( __RDOSDEV__ ) RdosInitKernelSection(&obj->semaphore); #else DosCreateMutexSem( NULL, &obj->semaphore, 0, FALSE ); #endif obj->initialized = 1; } __ReleaseSemaphore( &InitSemaphore ); } #endif #if defined( __NETWARE__ ) while( obj->semaphore != 0 ) { #if defined (_NETWARE_CLIB) ThreadSwitch(); #else NXThreadYield(); #endif } obj->semaphore = 1; obj->initialized = 1; #elif defined( __NT__ ) EnterCriticalSection( obj->semaphore ); #elif defined( __QNX__ ) __qsem_wait( &obj->semaphore ); #elif defined( __LINUX__ ) // TODO: Wait for semaphore under Linux! #elif defined( __RDOS__ ) RdosEnterSection( obj->semaphore ); #elif defined( __RDOSDEV__ ) RdosEnterKernelSection( &obj->semaphore ); #else DosRequestMutexSem( obj->semaphore, SEM_INDEFINITE_WAIT ); #endif #endif obj->owner = tid; } obj->count++; }