MCPcopy Create free account
hub / github.com/assaultcube/AC / sl_detachthread

Function sl_detachthread

source/src/tools.cpp:847–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

845static sl_semaphore sem_oldthreads(1, NULL);
846
847void sl_detachthread(void *ti) // SDL can't actually detach threads, so this is manual cleanup
848{
849 if(ti && sl_pollthread(ti))
850 {
851 SDL_WaitThread(((sl_threadinfo *)ti)->handle, NULL);
852 delete (sl_threadinfo *) ti;
853 ti = NULL;
854 }
855 if(ti || sem_oldthreads.getvalue() > 0)
856 {
857 sem_oldthreads.wait();
858 if(ti) oldthreads.add((sl_threadinfo *)ti);
859 loopvrev(oldthreads)
860 {
861 if(oldthreads[i]->done)
862 {
863 SDL_WaitThread(oldthreads[i]->handle, NULL);
864 delete oldthreads.remove(i);
865 }
866 }
867 sem_oldthreads.post();
868 }
869}
870
871static SDL_threadID mainthreadid = SDL_ThreadID();
872bool ismainthread() { return mainthreadid == SDL_ThreadID(); }

Callers 1

connectMethod · 0.85

Calls 7

sl_pollthreadFunction · 0.85
getvalueMethod · 0.80
waitMethod · 0.80
postMethod · 0.80
loopvrevFunction · 0.70
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected