27struct fc_thread_wrap_data {
29 void (*
func)(
void *arg);
36static int fc_thread_wrapper(
void *arg)
38 struct fc_thread_wrap_data *data = (
struct fc_thread_wrap_data *) arg;
40 data->func(data->arg);
56 struct fc_thread_wrap_data *data =
fc_malloc(
sizeof(*data));
59 data->func = function;
61 ret = thrd_create(thread, &fc_thread_wrapper, data);
63 return ret != thrd_success;
71 int *return_value = NULL;
73 thrd_join(*thread, return_value);
81 mtx_init(mutex, mtx_plain|mtx_recursive);
129 cnd_wait(cond, mutex);
140#elif defined(FREECIV_HAVE_PTHREAD)
142struct fc_thread_wrap_data {
144 void (*
func)(
void *arg);
151static void *fc_thread_wrapper(
void *arg)
153 struct fc_thread_wrap_data *data = (
struct fc_thread_wrap_data *) arg;
155 data->func(data->arg);
172 struct fc_thread_wrap_data *data =
fc_malloc(
sizeof(*data));
175 data->func = function;
179 pthread_attr_init(&attr);
180 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
182 ret = pthread_create(thread, &attr, &fc_thread_wrapper, data);
184 pthread_attr_destroy(&attr);
194 void **return_value = NULL;
196 pthread_join(*thread, return_value);
204 pthread_mutexattr_t attr;
206 pthread_mutexattr_init(&attr);
207 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
209 pthread_mutex_init(mutex, &attr);
211 pthread_mutexattr_destroy(&attr);
219 pthread_mutex_destroy(mutex);
227 pthread_mutex_lock(mutex);
235 pthread_mutex_unlock(mutex);
243 pthread_cond_init(cond, NULL);
251 pthread_cond_destroy(cond);
259 pthread_cond_wait(cond, mutex);
267 pthread_cond_signal(cond);
270#elif defined(FREECIV_HAVE_WINTHREADS)
272struct fc_thread_wrap_data {
274 void (*
func)(
void *arg);
281static DWORD WINAPI fc_thread_wrapper(LPVOID arg)
283 struct fc_thread_wrap_data *data = (
struct fc_thread_wrap_data *) arg;
285 data->func(data->arg);
295int fc_thread_start(fc_thread *thread,
void (*function) (
void *arg),
void *arg)
298 struct fc_thread_wrap_data *data =
fc_malloc(
sizeof(*data));
301 data->func = function;
303 *thread = CreateThread(NULL, 0, &fc_thread_wrapper, data, 0, NULL);
305 if (*thread == NULL) {
319 GetExitCodeThread(*thread, &exit_code);
321 while (exit_code == STILL_ACTIVE) {
323 GetExitCodeThread(*thread, &exit_code);
326 CloseHandle(*thread);
334 *mutex = CreateMutex(NULL,
FALSE, NULL);
350 WaitForSingleObject(*mutex, INFINITE);
358 ReleaseMutex(*mutex);
367#error "No working thread implementation"
372#ifndef FREECIV_HAVE_THREAD_COND
407#ifdef FREECIV_HAVE_THREAD_COND
void fc_thread_cond_destroy(fc_thread_cond *cond)
void fc_thread_cond_signal(fc_thread_cond *cond)
void fc_thread_cond_wait(fc_thread_cond *cond, fc_mutex *mutex)
bool has_thread_cond_impl(void)
void fc_thread_cond_init(fc_thread_cond *cond)
int fc_thread_start(fc_thread *thread, void(*function)(void *arg), void *arg)
void fc_allocate_mutex(fc_mutex *mutex)
void fc_release_mutex(fc_mutex *mutex)
void fc_thread_wait(fc_thread *thread)
void fc_destroy_mutex(fc_mutex *mutex)
void fc_init_mutex(fc_mutex *mutex)
void fc_usleep(unsigned long usec)