3 * Copyright (c) 2016 Tino Reichardt
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the root directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
10 * You can contact the author at:
11 * - zstdmt source repository: https://github.com/mcmilk/zstdmt
14 #ifndef THREADING_H_938743
15 #define THREADING_H_938743
17 #if defined (__cplusplus)
21 #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
24 * Windows minimalist Pthread Wrapper, based on :
25 * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
35 #define _WIN32_WINNT 0x0600
37 #ifndef WIN32_LEAN_AND_MEAN
38 # define WIN32_LEAN_AND_MEAN
44 #define pthread_mutex_t CRITICAL_SECTION
45 #define pthread_mutex_init(a,b) InitializeCriticalSection((a))
46 #define pthread_mutex_destroy(a) DeleteCriticalSection((a))
47 #define pthread_mutex_lock(a) EnterCriticalSection((a))
48 #define pthread_mutex_unlock(a) LeaveCriticalSection((a))
50 /* condition variable */
51 #define pthread_cond_t CONDITION_VARIABLE
52 #define pthread_cond_init(a, b) InitializeConditionVariable((a))
53 #define pthread_cond_destroy(a) /* No delete */
54 #define pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE)
55 #define pthread_cond_signal(a) WakeConditionVariable((a))
56 #define pthread_cond_broadcast(a) WakeAllConditionVariable((a))
58 /* pthread_create() and pthread_join() */
61 void* (*start_routine)(void*);
65 int pthread_create(pthread_t* thread, const void* unused,
66 void* (*start_routine) (void*), void* arg);
68 #define pthread_join(a, b) _pthread_join(&(a), (b))
69 int _pthread_join(pthread_t* thread, void** value_ptr);
72 * add here more wrappers as required
76 #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
77 /* === POSIX Systems === */
80 #else /* ZSTD_MULTITHREAD not defined */
81 /* No multithreading support */
83 #define pthread_mutex_t int /* #define rather than typedef, as sometimes pthread support is implicit, resulting in duplicated symbols */
84 #define pthread_mutex_init(a,b)
85 #define pthread_mutex_destroy(a)
86 #define pthread_mutex_lock(a)
87 #define pthread_mutex_unlock(a)
89 #define pthread_cond_t int
90 #define pthread_cond_init(a,b)
91 #define pthread_cond_destroy(a)
92 #define pthread_cond_wait(a,b)
93 #define pthread_cond_signal(a)
94 #define pthread_cond_broadcast(a)
96 /* do not use pthread_t */
98 #endif /* ZSTD_MULTITHREAD */
100 #if defined (__cplusplus)
104 #endif /* THREADING_H_938743 */