1 /**********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2, or (at your option)
6    any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 ***********************************************************************/
13 
14 #ifndef FC__THREAD_H
15 #define FC__THREAD_H
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 /* gen_headers */
22 #include "freeciv_config.h"
23 
24 /* utility */
25 #include "support.h" /* bool */
26 
27 #ifdef FREECIV_HAVE_C11_THREADS
28 
29 #include <threads.h>
30 
31 #define fc_thread      thrd_t
32 #define fc_mutex       mtx_t
33 #define fc_thread_cond cnd_t
34 
35 #elif defined(FREECIV_HAVE_PTHREAD)
36 
37 #include <pthread.h>
38 
39 #define fc_thread      pthread_t
40 #define fc_mutex       pthread_mutex_t
41 #define fc_thread_cond pthread_cond_t
42 
43 #elif defined (FREECIV_HAVE_WINTHREADS)
44 
45 #include <windows.h>
46 #define fc_thread      HANDLE *
47 #define fc_mutex       HANDLE *
48 
49 #ifndef FREECIV_HAVE_THREAD_COND
50 #define fc_thread_cond char
51 #else  /* FREECIV_HAVE_THREAD_COND */
52 #warning FREECIV_HAVE_THREAD_COND defined but we have no real Windows implementation
53 #endif /* FREECIV_HAVE_THREAD_COND */
54 
55 #else /* No pthreads nor winthreads */
56 
57 #error "No working thread implementation"
58 
59 #endif /* FREECIV_HAVE_PTHREAD */
60 
61 int fc_thread_start(fc_thread *thread, void (*function) (void *arg), void *arg);
62 void fc_thread_wait(fc_thread *thread);
63 
64 void fc_init_mutex(fc_mutex *mutex);
65 void fc_destroy_mutex(fc_mutex *mutex);
66 void fc_allocate_mutex(fc_mutex *mutex);
67 void fc_release_mutex(fc_mutex *mutex);
68 
69 void fc_thread_cond_init(fc_thread_cond *cond);
70 void fc_thread_cond_destroy(fc_thread_cond *cond);
71 void fc_thread_cond_wait(fc_thread_cond *cond, fc_mutex *mutex);
72 void fc_thread_cond_signal(fc_thread_cond *cond);
73 
74 bool has_thread_cond_impl(void);
75 
76 #ifdef __cplusplus
77 }
78 #endif /* __cplusplus */
79 
80 #endif /* FC__THREAD_H */
81