HRESULT CDirect3D::LockTexture(void) { // Lock the surface and write the pixels static DWORD d3dflags = D3DLOCK_NO_DIRTY_UPDATE; lock_texture: if(GCC_UNLIKELY(!lpTexture || deviceLost)) { // Try to reset the device, but only when running main thread #if D3D_THREAD if((SDL_ThreadID() != SDL_GetThreadID(thread))) #endif { Resize3DEnvironment(); } if(GCC_UNLIKELY(!lpTexture || deviceLost)) { LOG_MSG("D3D:Device is lost, locktexture() failed..."); return E_FAIL; } // Success, continue as planned... } if(GCC_UNLIKELY(lpTexture->LockRect(0, &d3dlr, NULL, d3dflags) != D3D_OK)) { if(d3dflags) { d3dflags = 0; LOG_MSG("D3D:Cannot lock texture, fallback to compatible mode"); goto lock_texture; } else { LOG_MSG("D3D:Failed to lock texture!"); } return E_FAIL; } return S_OK; }
/* ================== Sys_CreateThread ================== */ void Sys_CreateThread(xthread_t function, void *parms, xthreadInfo& info, const char *name) { Sys_EnterCriticalSection(); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Thread *t = SDL_CreateThread(function, name, parms); #else SDL_Thread *t = SDL_CreateThread(function, parms); #endif if (!t) { common->Error("ERROR: SDL_thread for '%s' failed\n", name); Sys_LeaveCriticalSection(); return; } info.name = name; info.threadHandle = t; info.threadId = SDL_GetThreadID(t); if (thread_count < MAX_THREADS) thread[thread_count++] = &info; else common->DPrintf("WARNING: MAX_THREADS reached\n"); Sys_LeaveCriticalSection(); }
HANDLE WINAPI CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId ) { // a thread handle would actually contain an event // the event would mark if the thread is running or not. it will be used in the Wait functions. // DO NOT use SDL_WaitThread for waiting. it will delete the thread object. HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL); h->ChangeType(CXHandle::HND_THREAD); InternalThreadParam *pParam = new InternalThreadParam; pParam->threadFunc = lpStartAddress; pParam->data = lpParameter; pParam->handle = h; h->m_nRefCount++; h->m_hThread = SDL_CreateThread(InternalThreadFunc, (void*)pParam); if (lpThreadId) *lpThreadId = SDL_GetThreadID(h->m_hThread); return h; }
void NetworkThread::Wait() { if (thread != NULL && SDL_ThreadID() != SDL_GetThreadID(thread)) { SDL_WaitThread(thread, NULL); } thread = NULL; stop_thread = false; }
static void LocalStats (SDL_Thread *thread) { #if defined (WIN32) || !defined(SDL_PTHREADS) fprintf (stderr, "Thread ID %u\n", SDL_GetThreadID (thread)); #else /* !defined (WIN32) && defined(SDL_PTHREADS) */ // This only works if SDL implements threads as processes pid_t pid; struct rusage ru; long seconds; pid = (pid_t) SDL_GetThreadID (thread); fprintf (stderr, "Pid %d\n", (int) pid); getrusage(RUSAGE_SELF, &ru); seconds = ru.ru_utime.tv_sec + ru.ru_utime.tv_sec; fprintf (stderr, "Used %ld.%ld minutes of processor time.\n", seconds / 60, seconds % 60); #endif /* defined (WIN32) && defined(SDL_PTHREADS) */ }
void Download::cancel() { logger->log("Canceling download: %s", mUrl.c_str()); mOptions.cancel = true; if (mThread && SDL_GetThreadID(mThread) != 0) { SDL_WaitThread(mThread, NULL); mThread = NULL; } }
static void OHQ_Call(_THIS, void (*func)(SDL_VideoDevice*)) { if (this->VideoInit != OHQ_VideoInit) { func(this); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { func(this->hidden->real_video); } else { this->hidden->call.type = OGL_CALL_P; this->hidden->call.func.p = func; SendSyncCommand(this,OGL_CALL); } }
IPC::~IPC() { mListen = false; if (mSocket) { TcpNet::closeSocket(mSocket); mSocket = nullptr; } int status; if (mThread && SDL_GetThreadID(mThread)) SDL_WaitThread(mThread, &status); mThread = nullptr; }
static int OHQ_Call__i(_THIS, int (*func)(SDL_VideoDevice*)) { if (this->VideoInit != OHQ_VideoInit) { return func(this); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { return func(this->hidden->real_video); } else { this->hidden->call.type = OGL_CALL_P_I; this->hidden->call.func.p_i = func; SendSyncCommand(this,OGL_CALL); return (int)this->hidden->call.result; } }
static void OHQ_Call_p(_THIS, void (*func)(SDL_VideoDevice*,const void*), const void* arg1) { if (this->VideoInit != OHQ_VideoInit) { func(this,arg1); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { func(this->hidden->real_video,arg1); } else { this->hidden->call.type = OGL_CALL_PP; this->hidden->call.func.pp = func; this->hidden->call.args[0] = (intptr_t)arg1; SendSyncCommand(this,OGL_CALL); } }
static void OHQ_Call_ii(_THIS, void (*func)(SDL_VideoDevice*,int,int), int arg1, int arg2) { if (this->VideoInit != OHQ_VideoInit) { func(this,arg1,arg2); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { func(this->hidden->real_video,arg1,arg2); } else { this->hidden->call.type = OGL_CALL_PII; this->hidden->call.func.pii = func; this->hidden->call.args[0] = (intptr_t)arg1; this->hidden->call.args[1] = (intptr_t)arg2; SendSyncCommand(this,OGL_CALL); } }
static int OHQ_Call_i_i(_THIS, int (*func)(SDL_VideoDevice*,int), int arg1) { if (this->VideoInit != OHQ_VideoInit) { return func(this,arg1); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { return func(this->hidden->real_video,arg1); } else { this->hidden->call.type = OGL_CALL_PI_I; this->hidden->call.func.pi_i = func; this->hidden->call.args[0] = (intptr_t)arg1; SendSyncCommand(this,OGL_CALL); return (int)this->hidden->call.result; } }
bool BoostThreadPriority(SDL_Thread* inThread) { #if defined(_POSIX_PRIORITY_SCHEDULING) pthread_t theTargetThread = (pthread_t) SDL_GetThreadID(inThread); int theSchedulingPolicy; struct sched_param theSchedulingParameters; if(pthread_getschedparam(theTargetThread, &theSchedulingPolicy, &theSchedulingParameters) != 0) return false; theSchedulingParameters.sched_priority = sched_get_priority_max(theSchedulingPolicy); if(pthread_setschedparam(theTargetThread, theSchedulingPolicy, &theSchedulingParameters) != 0) return false; #endif return true; }
WhoIsOnline::~WhoIsOnline() { config.removeListeners(this); if (mThread && SDL_GetThreadID(mThread)) SDL_WaitThread(mThread, nullptr); free(mMemoryBuffer); mMemoryBuffer = nullptr; // Remove possibly leftover temporary download delete []mCurlError; FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers) delete *itd; mOnlinePlayers.clear(); mOnlineNicks.clear(); }
static TrueThread FindThreadInfo (Uint32 threadID) { TrueThread ptr; SDL_mutexP (threadQueueMutex); ptr = threadQueue; while (ptr) { if (SDL_GetThreadID (ptr->native) == threadID) { SDL_mutexV (threadQueueMutex); return ptr; } ptr = ptr->next; } SDL_mutexV (threadQueueMutex); return NULL; }
static void* OHQ_Call_ppiiii_p(_THIS, void* (*func)(SDL_VideoDevice*,const void*,const void*,int,int,int,int), const void* arg1, const void* arg2, int arg3, int arg4, int arg5, int arg6) { if (this->VideoInit != OHQ_VideoInit) { return func(this,arg1,arg2,arg3,arg4,arg5,arg6); } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) { return func(this->hidden->real_video,arg1,arg2,arg3,arg4,arg5,arg6); } else { this->hidden->call.type = OGL_CALL_PPPIIII_P; this->hidden->call.func.pppiiii_p = func; this->hidden->call.args[0] = (intptr_t)arg1; this->hidden->call.args[1] = (intptr_t)arg2; this->hidden->call.args[2] = (intptr_t)arg3; this->hidden->call.args[3] = (intptr_t)arg4; this->hidden->call.args[4] = (intptr_t)arg5; this->hidden->call.args[5] = (intptr_t)arg6; SendSyncCommand(this,OGL_CALL); return (void*)this->hidden->call.result; } }
void Network::disconnect() { mState = IDLE; if (mWorkerThread && SDL_GetThreadID(mWorkerThread)) { SDL_WaitThread(mWorkerThread, nullptr); mWorkerThread = nullptr; } if (mSocket) { // need call SDLNet_TCP_DelSocket? SDLNet_TCP_Close(mSocket); mSocket = nullptr; int sleep = config.getIntValue("networksleep"); if (sleep > 0) SDL_Delay(sleep); } }
fe_mt_thread fe_mt_thread_create(int (*func)(void*), const char *name, void *arg) { SDL_Thread *th = SDL_CreateThread(func, name, arg); if(!th) return -1; fe_mt_mutex_lock(&pool_mutex); size_t i; for(i=0 ; i<pool.count ; ++i) if(!pool.slots[i].taken) goto allocate; pool.slots = fe_mem_heaprealloc(pool.slots, i+1, fe_mt_threadpool_slot, ""); if(!pool.slots) { fe_mt_mutex_unlock(&pool_mutex); return -1; } allocate: pool.slots[i].taken = true; pool.slots[i].thread = th; pool.slots[i].id = SDL_GetThreadID(th); fe_mt_mutex_unlock(&pool_mutex); return i; }
Uint32 get_id() { return SDL_GetThreadID(thread_); }
Uint32 GetThreadID(Thread *thread) { return SDL_GetThreadID(thread); }
int main(int m_argc, char **m_argv) { int terminated; SDL_Event evert; argc = m_argc; argv = m_argv; // // Initialise SDL // atexit(SDL_Quit); if( SDL_Init(SDL_INIT_EVERYTHING) != 0 ) { debug_fatal("Unable to initialise SDL: %s", SDL_GetError()); return 1; } // // Install our own exception handler! // initialise_application_exception_handler (); // // Set the current directory to where the executable is located // set_application_current_directory (); // // Unlink the debug.log file here. // unlink ( "debug.log" ); system_thread_id = SDL_ThreadID (); application_debug_fatal = FALSE; application_active = TRUE; // // Initialise the memory statistics // initialise_memory_totals (); if ( !initialise_windows ( 1 ) ) { deinitialise_windows (); return ( FALSE ); } number_user_message_functions = 0; number_system_message_functions = 0; register_system_message_function ( SDL_USEREVENT, call_user_function_routine ); // register_system_message_function ( WM_SETCURSOR, windows_cursor_routine ); register_system_message_function ( SDL_VIDEOEXPOSE, windows_paint_routine ); register_system_message_function ( SDL_VIDEORESIZE, windows_sizemove_routine ); register_system_message_function ( SDL_SYSWMEVENT, windows_systemcommand_routine ); register_system_message_function ( SDL_QUIT, windows_close_request_routine ); initialise_cdrom_system (); initialise_system_thread_calling_function (); exit_message_id = get_unique_message_id (); register_user_message_function ( exit_message_id, windows_exit_routine ); // // The graphics / 3d / 2d systems need the maths fpu to round to zero // set_fpu_rounding_mode_zero (); set_fpu_exceptions (); initialise_event_system (); initialise_timers_system (); initialise_file_system (); terminated = FALSE; application_thread_handle = (SDL_Thread *) SDL_CreateThread ( start_application, NULL ); application_thread_id = SDL_GetThreadID ( application_thread_handle ); // SetThreadPriority ( GetCurrentThread (), THREAD_PRIORITY_ABOVE_NORMAL ); while(SDL_WaitEvent( &evert )) { if(!application_window_proc(&evert)) { generate_keyboard_events ( &evert ); generate_mouse_events ( &evert ); } } return ( 0 ); }
boost::uint32_t threading::thread::get_id() { return SDL_GetThreadID(thread_); }
unsigned int Thread::get_id() { return SDL_GetThreadID(m_impl); }