Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 99 | pmbaty | 1 | #if !defined(H_SYSPOR) | 
| 2 | #define H_SYSPOR | ||
| 3 | |||
| 4 | /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ | ||
| 5 | |||
| 6 | /* | ||
| 7 | |       Define | ||
| 8 | |       MONOTHREAD: if SMP functions are not going to be used nor linked with -lpthread | ||
| 9 | | | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifdef _MSC_VER | ||
| 13 |         #include <windows.h> | ||
| 14 | #else | ||
| 15 |         #include <unistd.h> | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifdef _MSC_VER  | ||
| 19 |         #if !defined(MVSC) | ||
| 20 |                 #define MVSC | ||
| 21 |         #endif | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #if defined(__linux__) || defined(__GNUC__) | ||
| 25 |         #if !defined(GCCLINUX) | ||
| 26 |                 #define GCCLINUX | ||
| 27 |         #endif | ||
| 28 | #endif | ||
| 29 | |||
| 30 | |||
| 31 | /* | ||
| 32 | | | ||
| 33 | |       To allow multithreaded functions, MULTI_THREADED_INTERFACE should be defined | ||
| 34 | | | ||
| 35 | \*--------------------------------------------------------------------------------*/ | ||
| 36 | |||
| 37 | |||
| 38 | #if defined(CYGWIN) | ||
| 39 | |||
| 40 |         #define USECLOCK | ||
| 41 |         #define MULTI_THREADED_INTERFACE | ||
| 42 |         #undef  NT_THREADS | ||
| 43 |         #define POSIX_THREADS | ||
| 44 |         #define GCCLINUX_INTEGERS | ||
| 45 | |||
| 46 | #elif defined(MINGW) | ||
| 47 | |||
| 48 |         #define USEWINCLOCK | ||
| 49 |         #define MULTI_THREADED_INTERFACE | ||
| 50 |         #define NT_THREADS | ||
| 51 |         #undef  POSIX_THREADS | ||
| 52 |         #define GCCLINUX_INTEGERS | ||
| 53 | |||
| 54 | #elif defined(GCCLINUX) | ||
| 55 | |||
| 56 |         #define USELINCLOCK | ||
| 57 |         #define MULTI_THREADED_INTERFACE | ||
| 58 |         #undef  NT_THREADS | ||
| 59 |         #define POSIX_THREADS | ||
| 60 |         #define GCCLINUX_INTEGERS | ||
| 61 | |||
| 62 | #elif defined(MVSC) | ||
| 63 | |||
| 64 |         #define USEWINCLOCK  | ||
| 65 |         #define MULTI_THREADED_INTERFACE | ||
| 66 |         #define NT_THREADS | ||
| 67 |         #undef  POSIX_THREADS | ||
| 68 |         #define MSWINDOWS_INTEGERS | ||
| 69 | |||
| 70 | #else | ||
| 71 | |||
| 72 |         #error COMPILER NOT DEFINED | ||
| 73 | |||
| 74 | #endif | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | #if defined(MONOTHREAD) | ||
| 79 |         #undef MULTI_THREADED_INTERFACE | ||
| 80 | #endif | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | #if defined(GCCLINUX) | ||
| 85 | |||
| 86 |         #define U64(x) (x##ull) | ||
| 87 | |||
| 88 | #elif defined(MVSC) | ||
| 89 | |||
| 90 |         #define U64(x) (x##ui64) | ||
| 91 | |||
| 92 | #else | ||
| 93 |         #error OS not defined properly | ||
| 94 | #endif | ||
| 95 | |||
| 96 | |||
| 97 | #if defined(GCCLINUX) | ||
| 98 | /* | ||
| 99 |         typedef unsigned long long int  uint64_t; | ||
| 100 |         typedef long long int                   int64_t; | ||
| 101 |         typedef unsigned char                   uint8_t; | ||
| 102 |         typedef unsigned short int              uint16_t; | ||
| 103 |         typedef unsigned int                    uint32_t; | ||
| 104 | */ | ||
| 105 | |||
| 106 |         #include <stdint.h> | ||
| 107 | |||
| 108 | #elif defined(MVSC) | ||
| 109 | |||
| 110 | typedef unsigned char uint8_t; | ||
| 111 | typedef unsigned short int uint16_t; | ||
| 112 | typedef unsigned int uint32_t; | ||
| 113 | typedef unsigned __int64 uint64_t; | ||
| 114 | |||
| 115 | typedef signed char int8_t; | ||
| 116 | typedef short int int16_t; | ||
| 117 | typedef int int32_t; | ||
| 118 | typedef __int64 int64_t; | ||
| 119 | |||
| 120 | #else | ||
| 121 |         #error OS not defined properly for 64 bit integers | ||
| 122 | #endif | ||
| 123 | |||
| 124 | |||
| 125 | /*----------------- | ||
| 126 |         PATH NAMES | ||
| 127 | ------------------*/ | ||
| 128 | |||
| 129 | #if defined(GCCLINUX) | ||
| 130 |         #define FOLDERSEP "/" | ||
| 131 | #elif defined(MVSC) | ||
| 132 |         #define FOLDERSEP "\\" | ||
| 133 | #else | ||
| 134 |         #define FOLDERSEP "/" | ||
| 135 | #endif | ||
| 136 | |||
| 137 | /* path names */ | ||
| 138 | extern int isfoldersep (int x); | ||
| 139 | |||
| 140 | /*----------------- | ||
| 141 |         FOPEN MAX | ||
| 142 | ------------------*/ | ||
| 143 | |||
| 144 | extern int mysys_fopen_max (void); | ||
| 145 | |||
| 146 | /*------------ | ||
| 147 |         TIMER | ||
| 148 | -------------*/ | ||
| 149 | |||
| 150 | typedef int64_t myclock_t; | ||
| 151 | |||
| 152 | extern myclock_t myclock(void); | ||
| 153 | extern myclock_t ticks_per_sec (void); | ||
| 154 | |||
| 155 | #define MYCLOCKS_PER_SEC (ticks_per_sec()) | ||
| 156 | #define GET_TICK (myclock()) | ||
| 157 | |||
| 158 | |||
| 159 | /*********************************************************************/ | ||
| 160 | #if defined(MULTI_THREADED_INTERFACE) | ||
| 161 | |||
| 162 | /*------------ | ||
| 163 |         THREADS | ||
| 164 | -------------*/ | ||
| 165 | |||
| 166 | #if defined (POSIX_THREADS) | ||
| 167 | |||
| 168 |         #include <pthread.h> | ||
| 169 |         #include <semaphore.h> | ||
| 170 | |||
| 171 |         #define THREAD_CALL | ||
| 172 | |||
| 173 | typedef void * thread_return_t; | ||
| 174 | typedef pthread_t mythread_t; | ||
| 175 | typedef thread_return_t (THREAD_CALL *routine_t) (void *); | ||
| 176 | typedef pthread_mutex_t mythread_mutex_t; | ||
| 177 | |||
| 178 |         #ifdef SPINLOCKS | ||
| 179 | typedef pthread_spinlock_t mythread_spinx_t; | ||
| 180 |         #else | ||
| 181 | typedef pthread_mutex_t mythread_spinx_t; | ||
| 182 |         #endif | ||
| 183 | |||
| 184 | typedef sem_t mysem_t; | ||
| 185 | |||
| 186 | |||
| 187 | #elif defined(NT_THREADS) | ||
| 188 | |||
| 189 |         #define WIN32_LEAN_AND_MEAN | ||
| 190 | |||
| 191 |         #include <windows.h> | ||
| 192 |         #include <process.h> | ||
| 193 | |||
| 194 |         #define THREAD_CALL __stdcall | ||
| 195 | |||
| 196 | typedef unsigned thread_return_t; | ||
| 197 | typedef HANDLE mythread_t; | ||
| 198 | typedef thread_return_t (THREAD_CALL *routine_t) (void *); | ||
| 199 | typedef HANDLE mythread_mutex_t; | ||
| 200 | |||
| 201 |         #define SPINLOCKS | ||
| 202 | |||
| 203 |         #ifdef SPINLOCKS | ||
| 204 | typedef CRITICAL_SECTION mythread_spinx_t; | ||
| 205 |         #else | ||
| 206 | typedef HANDLE mythread_spinx_t; | ||
| 207 |         #endif | ||
| 208 | |||
| 209 | typedef HANDLE mysem_t; | ||
| 210 | |||
| 211 | #else | ||
| 212 |         #error Definition of threads not present | ||
| 213 | #endif | ||
| 214 | |||
| 215 | |||
| 216 | |||
| 217 | extern int /*boolean*/ mythread_create (/*@out@*/ mythread_t *thread, routine_t start_routine, void *arg, /*@out@*/ int *ret_error); | ||
| 218 | extern int /*boolean*/ mythread_join (mythread_t thread); | ||
| 219 | extern void mythread_exit (void); | ||
| 220 | extern const char * mythread_create_error (int err); | ||
| 221 | |||
| 222 | extern void mythread_mutex_init (mythread_mutex_t *m); | ||
| 223 | extern void mythread_mutex_destroy (mythread_mutex_t *m); | ||
| 224 | extern void mythread_mutex_lock (mythread_mutex_t *m); | ||
| 225 | extern void mythread_mutex_unlock (mythread_mutex_t *m); | ||
| 226 | |||
| 227 | extern void mythread_spinx_init (mythread_spinx_t *m); /**/ | ||
| 228 | extern void mythread_spinx_destroy (mythread_spinx_t *m); /**/ | ||
| 229 | extern void mythread_spinx_lock (mythread_spinx_t *m); /**/ | ||
| 230 | extern void mythread_spinx_unlock (mythread_spinx_t *m); /**/ | ||
| 231 | |||
| 232 | /* semaphores*/ | ||
| 233 | extern int /*boolean*/ mysem_init (mysem_t *sem, unsigned int value); | ||
| 234 | extern int /*boolean*/ mysem_wait (mysem_t *sem); | ||
| 235 | extern int /*boolean*/ mysem_post (mysem_t *sem); | ||
| 236 | extern int /*boolean*/ mysem_destroy (mysem_t *sem); | ||
| 237 | #endif | ||
| 238 | |||
| 239 | |||
| 240 | #if defined(MINGW) | ||
| 241 | #undef GCCLINUX | ||
| 242 | #define MSVC | ||
| 243 | #endif | ||
| 244 | |||
| 245 | |||
| 246 | /* end MULTI_THREADED_INTERFACE*/ | ||
| 247 | #endif | ||
| 248 | |||
| 249 | /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |