diff --git a/src/base/system.c b/src/base/system.c index 90fe1fe27..40f59df62 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -526,7 +526,9 @@ void *thread_init(void (*threadfunc)(void *), void *u) void thread_wait(void *thread) { #if defined(CONF_FAMILY_UNIX) - pthread_join((pthread_t)thread, NULL); + int result = pthread_join((pthread_t)thread, NULL); + if(result != 0) + dbg_msg("thread", "!! %d", result); #elif defined(CONF_FAMILY_WINDOWS) WaitForSingleObject((HANDLE)thread, INFINITE); #else @@ -534,16 +536,6 @@ void thread_wait(void *thread) #endif } -void thread_destroy(void *thread) -{ -#if defined(CONF_FAMILY_UNIX) - void *r = 0; - pthread_join((pthread_t)thread, &r); -#else - /*#error not implemented*/ -#endif -} - void thread_yield() { #if defined(CONF_FAMILY_UNIX) @@ -647,12 +639,7 @@ void lock_unlock(LOCK lock) #endif } -#if defined(CONF_FAMILY_UNIX) && !defined(CONF_PLATFORM_MACOSX) -void sphore_init(SEMAPHORE *sem) { sem_init(sem, 0, 0); } -void sphore_wait(SEMAPHORE *sem) { sem_wait(sem); } -void sphore_signal(SEMAPHORE *sem) { sem_post(sem); } -void sphore_destroy(SEMAPHORE *sem) { sem_destroy(sem); } -#elif defined(CONF_FAMILY_WINDOWS) +#if defined(CONF_FAMILY_WINDOWS) void sphore_init(SEMAPHORE *sem) { *sem = CreateSemaphore(0, 0, 10000, 0); } void sphore_wait(SEMAPHORE *sem) { WaitForSingleObject((HANDLE)*sem, INFINITE); } void sphore_signal(SEMAPHORE *sem) { ReleaseSemaphore((HANDLE)*sem, 1, NULL); } @@ -666,9 +653,18 @@ void sphore_init(SEMAPHORE *sem) } void sphore_wait(SEMAPHORE *sem) { sem_wait(*sem); } void sphore_signal(SEMAPHORE *sem) { sem_post(*sem); } -void sphore_destroy(SEMAPHORE *sem) { sem_close(*sem); } -#else - #error not implemented on this platform +void sphore_destroy(SEMAPHORE *sem) +{ + char aBuf[64]; + sem_close(*sem); + str_format(aBuf, sizeof(aBuf), "/%d-ddphore-%p", pid(), (void *)sem); + sem_unlink(aBuf); +} +#elif defined(CONF_FAMILY_UNIX) +void sphore_init(SEMAPHORE *sem) { sem_init(sem, 0, 0); } +void sphore_wait(SEMAPHORE *sem) { sem_wait(sem); } +void sphore_signal(SEMAPHORE *sem) { sem_post(sem); } +void sphore_destroy(SEMAPHORE *sem) { sem_destroy(sem); } #endif static int new_tick = -1; diff --git a/src/base/system.h b/src/base/system.h index 3f182e7eb..7cd04c2df 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -387,18 +387,9 @@ void *thread_init(void (*threadfunc)(void *), void *user); */ void thread_wait(void *thread); -/* - Function: thread_destroy - Destroys a thread. - - Parameters: - thread - Thread to destroy. -*/ -void thread_destroy(void *thread); - /* Function: thread_yeild - Yeild the current threads execution slice. + Yield the current threads execution slice. */ void thread_yield(); @@ -425,15 +416,14 @@ void lock_unlock(LOCK lock); /* Group: Semaphores */ -#if defined(CONF_FAMILY_UNIX) - #include - #if defined(CONF_PLATFORM_MACOSX) - typedef sem_t* SEMAPHORE; - #else - typedef sem_t SEMAPHORE; - #endif -#elif defined(CONF_FAMILY_WINDOWS) +#if defined(CONF_FAMILY_WINDOWS) typedef void* SEMAPHORE; +#elif defined(CONF_PLATFORM_MACOSX) + #include + typedef sem_t* SEMAPHORE; +#elif defined(CONF_FAMILY_UNIX) + #include + typedef sem_t SEMAPHORE; #else #error not implemented on this platform #endif @@ -1274,9 +1264,7 @@ void swap_endian(void *data, unsigned elem_size, unsigned num); typedef void (*DBG_LOGGER)(const char *line); void dbg_logger(DBG_LOGGER logger); -#if !defined(CONF_PLATFORM_MACOSX) void dbg_enable_threaded(); -#endif void dbg_logger_stdout(); void dbg_logger_debugger(); void dbg_logger_file(const char *filename); diff --git a/src/base/tl/threading.h b/src/base/tl/threading.h index ff2d0cb2b..c2e60144a 100644 --- a/src/base/tl/threading.h +++ b/src/base/tl/threading.h @@ -61,21 +61,15 @@ #error missing atomic implementation for this compiler #endif -#if defined(CONF_PLATFORM_MACOSX) - /* - use semaphore provided by SDL on macosx - */ -#else - class semaphore - { - SEMAPHORE sem; - public: - semaphore() { sphore_init(&sem); } - ~semaphore() { sphore_destroy(&sem); } - void wait() { sphore_wait(&sem); } - void signal() { sphore_signal(&sem); } - }; -#endif +class semaphore +{ + SEMAPHORE sem; +public: + semaphore() { sphore_init(&sem); } + ~semaphore() { sphore_destroy(&sem); } + void wait() { sphore_wait(&sem); } + void signal() { sphore_signal(&sem); } +}; class lock { diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 8240df7fb..1e2dad36d 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -80,7 +80,6 @@ void CGraphicsBackend_Threaded::StopProcessor() m_Shutdown = true; m_Activity.signal(); thread_wait(m_pThread); - thread_destroy(m_pThread); } void CGraphicsBackend_Threaded::RunBuffer(CCommandBuffer *pBuffer) diff --git a/src/engine/client/fetcher.cpp b/src/engine/client/fetcher.cpp index 5a975edb1..9359d6f5c 100644 --- a/src/engine/client/fetcher.cpp +++ b/src/engine/client/fetcher.cpp @@ -60,7 +60,6 @@ void CFetcher::QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest, if(!m_pThHandle) { m_pThHandle = thread_init(&FetcherThread, this); - thread_detach(m_pThHandle); } if(!m_pFirst) diff --git a/src/engine/shared/jobs.cpp b/src/engine/shared/jobs.cpp index 8424067d8..eceb939de 100644 --- a/src/engine/shared/jobs.cpp +++ b/src/engine/shared/jobs.cpp @@ -17,10 +17,7 @@ CJobPool::~CJobPool() { m_Shutdown = true; for(int i = 0; i < m_NumThreads; i++) - { thread_wait(m_apThreads[i]); - thread_destroy(m_apThreads[i]); - } lock_destroy(m_Lock); }