int main() { SetThreadName("Main"); Logger.Info("UDPServer starting"); MyServer myserver; auto settings = std::make_shared<ServerSettings>(); settings->WorkerCount = 0; settings->MainTCPPort = 5060; settings->StartUDPPort = 5060; settings->StopUDPPort = 5061; settings->Interface = &myserver; Server server; server.Start(settings); for (;;) { std::this_thread::sleep_for(std::chrono::seconds(1)); } server.Stop(); return 0; }
/* ================ idThread::idThread ================ */ idThread::idThread() { Init(); SetThreadName( va( "thread_%d", threadIndex ) ); if ( g_debugScript.GetBool() ) { gameLocal.Printf( "%d: create thread (%d) '%s'\n", gameLocal.time, threadNum, threadName.c_str() ); } }
unsigned long FTPFileWriter::Process(void* parameter) { if(SETTINGS::getInstance().getFtpServerOn() == false) { Sleep(500); return 0; } SetThreadName("FtpFileWriter"); loopRunning = true; waitingForBytes = true; while(!done || !waitingForBytes) { if(!waitingForBytes) { fwrite(currentBuffer,(size_t)currentBufferSize,1,m_File); delete currentBuffer; waitingForBytes = true; } else { Sleep(0); } } loopRunning = false; return 0; }
bool LogonConsoleThread::run() { new LogonConsole; SetThreadName("Console Interpreter"); sLogonConsole._thread = this; int i = 0; char cmd[96]; while (!kill) { // Make sure our buffer is clean to avoid Array bounds overflow memset(cmd, 0, sizeof(cmd)); // Read in single line from "stdin" fgets(cmd, 80, stdin); if(kill) break; for( i = 0 ; i < 80 || cmd[i] != '\0' ; i++ ) { if( cmd[i] =='\n' ) { cmd[i] = '\0'; sLogonConsole.ProcessCmd(cmd); fflush(stdin); break; } } } sLogonConsole._thread=NULL; return true; }
DWORD WINAPI my12doomRendererDShow::queue_thread(LPVOID param) { my12doomRendererDShow * _this = (my12doomRendererDShow*)param; SetThreadName(GetCurrentThreadId(), _this->m_id==0?"queue thread 0":"queue thread 1"); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); while (!_this->m_queue_exit) { CComPtr<IMediaSample> dummy_sample; dummy_sample = NULL; { CAutoLock lck(&_this->m_queue_lock); if (_this->m_queue_count) { _this->m_allocator->GetBuffer(&dummy_sample, &_this->m_queue->start, &_this->m_queue->end, NULL); dummy_sample->SetTime(&_this->m_queue->start, &_this->m_queue->end); memmove(_this->m_queue, _this->m_queue+1, sizeof(dummy_packet)*(my12doom_queue_size-1)); _this->m_queue_count--; } } if(dummy_sample) _this->SuperReceive(dummy_sample); else Sleep(1); } return 0; }
bool Database::run() { SetThreadName("Database Executor"); ThreadRunning = true; string *query = queries_queue.pop(); DatabaseConnection &con = GetFreeConnection(); while(query) { _SendQuery( con, query->c_str(), false ); delete query; if(!m_threadRunning) break; query = queries_queue.pop(); } con.Busy.Release(); if(queries_queue.get_size() > 0) { // execute all the remaining queries query = queries_queue.pop_nowait(); while(query) { DatabaseConnection &con = GetFreeConnection(); _SendQuery( con, query->c_str(), false ); con.Busy.Release(); delete query; query=queries_queue.pop_nowait(); } } ThreadRunning = false; return false; }
bool ConsoleThread::run() { SetThreadName("Console Interpreter"); size_t i = 0; size_t len; char cmd[300]; #ifndef WIN32 struct pollfd input; input.fd = 0; input.events = POLLIN | POLLPRI; input.revents = 0; #endif m_killSwitch = false; m_isRunning = true; while( m_killSwitch != true ) { #ifdef WIN32 // Read in single line from "stdin" memset( cmd, 0, sizeof( cmd ) ); if( fgets( cmd, 300, stdin ) == NULL ) continue; if( m_killSwitch ) break; #else int ret = poll(&input, 1, 1000); if (ret < 0) { break; } else if( ret == 0 ) { if(!m_killSwitch) // timeout continue; else break; } ret = read(0, cmd, sizeof(cmd)); if (ret <= 0) { break; } #endif len = strlen(cmd); for( i = 0; i < len; ++i ) { if(cmd[i] == '\n' || cmd[i] == '\r') cmd[i] = '\0'; } HandleConsoleInput(&g_localConsole, cmd); } m_isRunning = false; return false; }
bool cIsThread::Start(void) { ASSERT(m_Handle == NULL_HANDLE); // Has already started one thread? #ifdef _WIN32 // Create the thread suspended, so that the mHandle variable is valid in the thread procedure DWORD ThreadID = 0; m_Handle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &ThreadID); if (m_Handle == NULL) { LOGERROR("ERROR: Could not create thread \"%s\", GLE = %d!", m_ThreadName.c_str(), GetLastError()); return false; } ResumeThread(m_Handle); #if defined(_DEBUG) && defined(_MSC_VER) // Thread naming is available only in MSVC if (!m_ThreadName.empty()) { SetThreadName(ThreadID, m_ThreadName.c_str()); } #endif // _DEBUG and _MSC_VER #else // _WIN32 if (pthread_create(&m_Handle, NULL, thrExecute, this)) { LOGERROR("ERROR: Could not create thread \"%s\", !", m_ThreadName.c_str()); return false; } #endif // else _WIN32 return true; }
void create_thread( ThreadData* td, bool dec_child = false ) { // If the thread starts successfully, td will be deleted by thread_stub2. // So we must save the threadName for later. std::string threadName = td->name; unsigned threadid = 0; HANDLE h = (HANDLE)_beginthreadex( nullptr, 0, thread_stub2, td, 0, &threadid ); if ( h == 0 ) // added for better debugging { POLLOG.Format( "error in create_thread: {:d} {:d} \"{:s}\" \"{:s}\" {:d} {:d} {:s} {:d} {:d} {:}\n" ) << errno << _doserrno << strerror( errno ) << strerror( _doserrno ) << threads++ << (unsigned)thread_stub2 << td->name.c_str() << (unsigned)td->entry << (unsigned)td->entry_noparam << td->arg; // dec_child says that we should dec_child_threads when there's an error... :) if ( dec_child ) --child_threads; } else { SetThreadName( threadid, threadName ); CloseHandle( h ); } }
bool FRunnableThreadWin::CreateInternal(FRunnable* InRunnable, const TCHAR* InThreadName, uint32 InStackSize, EThreadPriority InThreadPri, uint64 InThreadAffinityMask) { Runnable = InRunnable; ThreadAffinityMask = InThreadAffinityMask; ThreadInitSyncEvent = FPlatformProcess::GetSynchEventFromPool(true); Thread = CreateThread(NULL, InStackSize, _ThreadProc, this, STACK_SIZE_PARAM_IS_A_RESERVATION, (::DWORD *)&ThreadID); if (Thread == nullptr) { Runnable = nullptr; } else { //FThreadManager::Get().AddThread(Thread , this); //ThreadStartUp ThreadInitSyncEvent->Wait(INFINITE); ThreadName = InThreadName ? InThreadName : TEXT("Unnamed"); SetThreadName(ThreadID, ThreadName.c_str()); SetThreadPriority(InThreadPri); } FPlatformProcess::ReturnSynchEventToPool(ThreadInitSyncEvent); ThreadInitSyncEvent = nullptr; return Thread != NULL; }
void ObjectUpdaterThread::run() { SetThreadName("Object Updater - M%u|I%u", m_MapMgr->GetMapId(), m_MapMgr->GetInstanceID()); WOWD_THREAD_TRY_EXECUTION2 Do(); WOWD_THREAD_HANDLE_CRASH2 }
MonitorThread::MonitorThread():ThreadEx() { // m_hEvent=::CreateEvent(NULL,TRUE,FALSE,NULL); SetThreadName("Work thread"); InitData(); }
void modem_input_thread(void *args) { int rd; int buffered; size_t buffer; BOOL monitor_dsr=TRUE; SetThreadName("Modem Input"); conn_api.input_thread_running=1; if(args != NULL) { if((comGetModemStatus(com)&COM_DSR) == 0) monitor_dsr=FALSE; } while(com != COM_HANDLE_INVALID && !conn_api.terminate) { rd=comReadBuf(com, conn_api.rd_buf, conn_api.rd_buf_size, NULL, 100); buffered=0; while(buffered < rd) { pthread_mutex_lock(&(conn_inbuf.mutex)); buffer=conn_buf_wait_free(&conn_inbuf, rd-buffered, 100); buffered+=conn_buf_put(&conn_inbuf, conn_api.rd_buf+buffered, buffer); pthread_mutex_unlock(&(conn_inbuf.mutex)); } if(args==NULL) { if((comGetModemStatus(com)&COM_DCD) == 0) break; } else if(monitor_dsr) { if((comGetModemStatus(com)&COM_DSR) == 0) break; } } if(args != NULL) comLowerDTR(com); conn_api.input_thread_running=0; }
bool Database::run() { SetThreadName("Database Execute Thread"); ThreadRunning = true; char * query = queries_queue.pop(); DatabaseConnection * con = GetFreeConnection(); while(query) { _SendQuery( con, query, false ); SafeDeleteArray(query); if(m_threadRunning == true) break; query = queries_queue.pop(); } con->Busy.Release(); if(queries_queue.get_size() > 0) { // execute all the remaining queries query = queries_queue.pop_nowait(); while(query) { DatabaseConnection * con = GetFreeConnection(); _SendQuery( con, query, false ); con->Busy.Release(); SafeDeleteArray(query); query=queries_queue.pop_nowait(); } } ThreadRunning = false; return false; }
bool SocketWorkerThread::run() { SetThreadName("Socket Worker"); HANDLE cp = sSocketMgr.GetCompletionPort(); DWORD len; Socket * s; OverlappedStruct * ov; LPOVERLAPPED ol_ptr; while(true) { #ifndef _WIN64 if(!GetQueuedCompletionStatus(cp, &len, (LPDWORD)&s, &ol_ptr, 10000)) #else if(!GetQueuedCompletionStatus(cp, &len, (PULONG_PTR)&s, &ol_ptr, 10000)) #endif continue; ov = CONTAINING_RECORD(ol_ptr, OverlappedStruct, m_overlap); if(ov->m_event == SOCKET_IO_THREAD_SHUTDOWN) { delete ov; return true; } if(ov->m_event < NUM_SOCKET_IO_EVENTS) ophandlers[ov->m_event](s, len); } return true; }
VOID CL_ThreadUnix::ExecRun() { #if defined (_FOR_ANDROID_) || defined (_FOR_APPLE_) || defined (_LINUX) m_dwThreadID = GetCurrentThreadId(); #else m_dwThreadID = (DWORD)m_tid; #endif #if defined(_LINUX) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); // 允许退出线程 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); // 设置立即取消 #endif SetPriorityNormal(); SetThreadName(); CL_Printf("<<<< Thread [%s] run (%lu, 0x%x) prio: %d, TC: %lu.", m_szThreadName, m_dwThreadID, m_dwThreadID, GetPriorityExt(), ::GetTickCount()); #ifdef _FOR_APPLE_ m_pPool = NULL; pool_alloc(&m_pPool); #endif m_pThreadIF->Run(); #ifdef _FOR_APPLE_ pool_release(&m_pPool); #endif CL_Printf("<<<< Thread [%s] quit (%lu, 0x%x) TC: %lu.", m_szThreadName, m_dwThreadID, m_dwThreadID, ::GetTickCount()); m_isAlive = CL_FALSE; m_dwThreadID = 0; }
bool RenderThread::update() { /* - Tant qu'il n'y a pas de command -> je pop des task - Une fois que j'ai mes commandes -> pour chacunes d'elles -> je regarde si c'est a moi de les traiter (ex : changement de scene) -> si ca n'est pas a moi de les traiter -> je les passe au render context actif -> si il n'y a pas de render context actif, c'est que j'ai fait une erreur, et j'assert dans ta face :D */ _registerId(); _run = true; _insideRun = true; DWORD threadId = GetThreadId(static_cast<HANDLE>(_threadHandle.native_handle())); SetThreadName(threadId, this->_name.c_str()); TMQ::MessageBase *task = nullptr; while (_run && _insideRun) { SCOPE_profile_cpu_i("RenderTimer", "Update"); if (TMQ::TaskManager::RenderThreadGetTask(task)) { SCOPE_profile_cpu_i("RenderTimer", "Execute task"); auto success = execute(task); // we receive a task that we cannot treat AGE_ASSERT(success); } } return true; }
VOID CL_ThreadUnix::ResetName(const XCHAR* name) { if (!name) return; xcsncpy(m_szThreadName, name, CL_THREAD_NAME_LEN); m_szThreadName[CL_THREAD_NAME_LEN - 1] = TEXT('\0'); SetThreadName(); }
static DWORD WINAPI namedThread( LPVOID arg ) { if( arg ) SetThreadName( -1,"self named thread" ); char *leak = (char*)malloc( 10 ); return leak[0]; }
unsigned long WINAPI hThread::staticFunc(LPVOID pParam) { hThread* pThis_ = (hThread*)pParam; SetThreadName( pThis_->threadName_ ); SetThreadPriority( pThis_->ThreadHand_, pThis_->priority_ ); pThis_->returnCode_ = (*pThis_->threadFunc)( pThis_->pThreadParam_ ); TLS::threadExit(); return pThis_->returnCode_; }
// Worker process for connection listening UINT __cdecl CListener::ListenerWorker(LPVOID v) { CListener * Listener = (CListener *) v; // See _beginthread call for parameter definition SetThreadName("Listener"); Listener->Listen(); return 0; }
/*! \fn ThreadContrl::InitRefresh(void) */ bool ThreadContrl::InitRefresh(int nthreads) { if(nthreads<1) return false; SetThreadName("Task check thread"); return AddNewThreads(nthreads)>0; }
int DeviceManagerThread::Run() { ThreadCommand::PopBuffer command; SetThreadName("OVR::DeviceManagerThread"); LogText("OVR::DeviceManagerThread - running (ThreadId=%p).\n", GetThreadId()); while(!IsExiting()) { // PopCommand will reset event on empty queue. if (PopCommand(&command)) { command.Execute(); } else { bool commands = 0; do { int n = poll(&PollFds[0], PollFds.GetSize(), -1); for (int i = 0; i < PollFds.GetSize(); i++) { if (PollFds[i].revents & POLLERR) { OVR_DEBUG_LOG(("poll: error on [%d]: %d", i, PollFds[i].fd)); } else if (PollFds[i].revents & POLLIN) { if (FdNotifiers[i]) FdNotifiers[i]->OnEvent(i, PollFds[i].fd); else if (i == 0) // command { char dummy[128]; read(PollFds[i].fd, dummy, 128); commands = 1; } } if (PollFds[i].revents & POLLHUP) PollFds[i].events = 0; if (PollFds[i].revents != 0) { n--; if (n == 0) break; } } } while (PollFds.GetSize() > 0 && !commands); } } LogText("OVR::DeviceManagerThread - exiting (ThreadId=%p).\n", GetThreadId()); return 0; }
/* ================ idThread::idThread ================ */ idThread::idThread( const function_t *func ) { assert( func ); Init(); SetThreadName( func->Name() ); interpreter.EnterFunction( func, false ); if( g_debugScript.GetBool() ) { gameLocal.Printf( "%d: create thread (%d) '%s'\n", gameLocal.time, threadNum, threadName.c_str() ); } }
/* ================ idThread::idThread ================ */ idThread::idThread( idEntity *self, const function_t *func ) { assert( self ); Init(); SetThreadName( self->name ); interpreter.EnterObjectFunction( self, func, false ); if( g_debugScript.GetBool() ) { gameLocal.Printf( "%d: create thread (%d) '%s'\n", gameLocal.time, threadNum, threadName.c_str() ); } }
/* ================ idThread::idThread ================ */ idThread::idThread( idInterpreter *source, idEntity *self, const function_t *func, int args ) { assert( self ); Init(); SetThreadName( self->name ); interpreter.ThreadCall( source, func, args ); if( g_debugScript.GetBool() ) { gameLocal.Printf( "%d: create thread (%d) '%s'\n", gameLocal.time, threadNum, threadName.c_str() ); } }
bool CMpaSplitterFilter::DemuxInit() { SetThreadName((DWORD)-1, "CMpaSplitterFilter"); if(!m_pFile) return(false); // TODO return(true); }
unsigned long TextureQueue::Process(void* parameter) { SetThreadName("TextureQueue"); DebugMsg("TextureQueue", "FileTexQueue Process Thread Running"); //SetThreadPriority(this->hThread, THREAD_PRIORITY_LOWEST); while(!m_terminate) { if(m_TextureQueue.size() > 0 && !m_paused) { long priority = -1; int index = 0; for (unsigned int i=0; i< m_TextureQueue.size(); i++) { TextureItem * pTex = m_TextureQueue.at(i); if (pTex->GetPriority() > priority) { priority = pTex->GetPriority(); index = i; } } TextureItem* currentItem = m_TextureQueue[index]; // printf("BEFORE size of the textureQueue is %d and index is %d\n", m_TextureQueue.size(), index); m_TextureQueue.erase(m_TextureQueue.begin()+index); // printf("AFTER size of the textureQueue is %d and index is %d\n", m_TextureQueue.size(), index); bool foundSpot = false; while(!foundSpot && !m_paused) { for(unsigned int x=0;x<m_Workers.size();x++) { if(!m_Workers.at(x)->IsBusy()) { m_Workers.at(x)->SetItem(currentItem); foundSpot = true; break; } } if(!foundSpot) { Sleep(50); } } if(!foundSpot) { m_TextureQueue.push_back(currentItem); } Sleep(0); } else { Sleep(100); } } DebugMsg("TextureQueue", "TextureQueue Process Thread Terminated"); return 0; }
unsigned long ContentCallback::Process( void * parameter ) { // Thread to handle list messages SetThreadName("GameContentCallback"); SetThreadPriority(hThread, CON_THREAD_CONTENT_PRIORITY); // Register class to the ContentObserver ContentManager::getInstance().AddContentObserver(*this); while(!m_bTerminate) { if(!m_bPaused) { // Thread is active, proceed to process any queued messages if( GetContentQueueSize() > 0 ) { EnterCriticalSection(&lock); ContentMessageData *msg = m_vMessageQueue.at(0); m_vMessageQueue.erase(m_vMessageQueue.begin()); LeaveCriticalSection(&lock); CallbackMessageType msgType = msg->nMsgType; switch (msgType) { case ContentAdded: // Received a ContentAdded Message OnContentAdded(msg->pContentItem); break; case ContentMassAdd: OnContentMassAdd(msg->pVec); break; case CacheLoaded: OnContentCacheLoaded(msg->dwMessageFlags); break; case UnknownMessage: // Received a UnknownMessage default: DebugMsg("GameViewManager", "MessageQueue: Ignoring unknown message type."); }; delete msg; } else { // Queue was empty, sleep for 10ms while waiting Sleep(CON_THREAD_SLEEP_IDLE); } } else { // Thread is paused, sleep for now Sleep(CON_THREAD_SLEEP_PAUSE); } }; // Terminating thread, trigger event SetEvent(m_hTerminated); DebugMsg("ContentCallback", "ContentCallback Thread has Successfully Terminated"); return 0; }
static void StartThreadIfNecessary() { if (g_threadHandle) return; InitializeCriticalSection(&g_threadCritSec); g_threadControlHandle = CreateEvent(nullptr, TRUE, FALSE, nullptr); g_threadHandle = CreateThread(nullptr, 0, FileWatcherThread, 0, 0, &g_threadId); SetThreadName(g_threadId, "FileWatcherThread"); }