// The kernel thread needs another stack to delete its own stack. static void kthread_do_kill_thread(void* user) { Thread* thread = (Thread*) user; while ( thread->state != ThreadState::DEAD ) kthread_yield(); FreeThread(thread); }
/* ================ idThread::PruneThreads ================ */ void idThread::PruneThreads( void ) { idThread* next = NULL; for ( idThread* thread = threadList.Next(); thread; thread = next ) { next = thread->threadNode.Next(); if ( thread->interpreter.terminateOnExit ) { FreeThread( thread ); continue; } } }
/* ================ idThread::Restart ================ */ void idThread::Restart( void ) { // reset the threadIndex threadIndex = 0; currentThread = NULL; threadAllocator.Shutdown(); while ( !threadList.IsListEmpty() ) { FreeThread( threadList.Next() ); } threadNumList.Clear(); memset( &trace, 0, sizeof( trace ) ); trace.c.entityNum = ENTITYNUM_NONE; }
int32_t TThread::Start() { if (state_ == TS_RUNNING) { return 0; } if (nullptr!=p_handle_->h_thread) { FreeThread(); } SetState(TS_UNINITIALIZED); uint32_t flag = 0; p_handle_->h_thread = (HANDLE)_beginthreadex(nullptr, 0, ThreadStart, this, flag, nullptr); if (nullptr == p_handle_->h_thread) { return -1; } SetState(TS_INITIALIZED); return 0; }
/* ================ idThread::Event_Remove ================ */ void idThread::Event_Remove( void ) { OnEventRemove(); FreeThread( this ); }
TThread::~TThread(void) { FreeThread(); delete p_handle_; }