| 845 | static sl_semaphore sem_oldthreads(1, NULL); |
| 846 | |
| 847 | void 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 | |
| 871 | static SDL_threadID mainthreadid = SDL_ThreadID(); |
| 872 | bool ismainthread() { return mainthreadid == SDL_ThreadID(); } |