/src/CMake/Utilities/cmliblzma/common/mythread.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: 0BSD |
2 | | |
3 | | /////////////////////////////////////////////////////////////////////////////// |
4 | | // |
5 | | /// \file mythread.h |
6 | | /// \brief Some threading related helper macros and functions |
7 | | // |
8 | | // Author: Lasse Collin |
9 | | // |
10 | | /////////////////////////////////////////////////////////////////////////////// |
11 | | |
12 | | #ifndef MYTHREAD_H |
13 | | #define MYTHREAD_H |
14 | | |
15 | | #include "sysdefs.h" |
16 | | |
17 | | // If any type of threading is enabled, #define MYTHREAD_ENABLED. |
18 | | #if defined(MYTHREAD_POSIX) || defined(MYTHREAD_WIN95) \ |
19 | | || defined(MYTHREAD_VISTA) |
20 | | # define MYTHREAD_ENABLED 1 |
21 | | #endif |
22 | | |
23 | | |
24 | | #ifdef MYTHREAD_ENABLED |
25 | | |
26 | | //////////////////////////////////////// |
27 | | // Shared between all threading types // |
28 | | //////////////////////////////////////// |
29 | | |
30 | | // Locks a mutex for a duration of a block. |
31 | | // |
32 | | // Perform mythread_mutex_lock(&mutex) in the beginning of a block |
33 | | // and mythread_mutex_unlock(&mutex) at the end of the block. "break" |
34 | | // may be used to unlock the mutex and jump out of the block. |
35 | | // mythread_sync blocks may be nested. |
36 | | // |
37 | | // Example: |
38 | | // |
39 | | // mythread_sync(mutex) { |
40 | | // foo(); |
41 | | // if (some_error) |
42 | | // break; // Skips bar() |
43 | | // bar(); |
44 | | // } |
45 | | // |
46 | | // At least GCC optimizes the loops completely away so it doesn't slow |
47 | | // things down at all compared to plain mythread_mutex_lock(&mutex) |
48 | | // and mythread_mutex_unlock(&mutex) calls. |
49 | | // |
50 | 0 | #define mythread_sync(mutex) mythread_sync_helper1(mutex, __LINE__) |
51 | 0 | #define mythread_sync_helper1(mutex, line) mythread_sync_helper2(mutex, line) |
52 | | #define mythread_sync_helper2(mutex, line) \ |
53 | 0 | for (unsigned int mythread_i_ ## line = 0; \ |
54 | 0 | mythread_i_ ## line \ |
55 | 0 | ? (mythread_mutex_unlock(&(mutex)), 0) \ |
56 | 0 | : (mythread_mutex_lock(&(mutex)), 1); \ |
57 | 0 | mythread_i_ ## line = 1) \ |
58 | 0 | for (unsigned int mythread_j_ ## line = 0; \ |
59 | 0 | !mythread_j_ ## line; \ |
60 | 0 | mythread_j_ ## line = 1) |
61 | | #endif |
62 | | |
63 | | |
64 | | #if !defined(MYTHREAD_ENABLED) |
65 | | |
66 | | ////////////////// |
67 | | // No threading // |
68 | | ////////////////// |
69 | | |
70 | | // Calls the given function once. This isn't thread safe. |
71 | | #define mythread_once(func) \ |
72 | | do { \ |
73 | | static bool once_ = false; \ |
74 | | if (!once_) { \ |
75 | | func(); \ |
76 | | once_ = true; \ |
77 | | } \ |
78 | | } while (0) |
79 | | |
80 | | |
81 | | #if !(defined(_WIN32) && !defined(__CYGWIN__)) && !defined(__wasm__) |
82 | | // Use sigprocmask() to set the signal mask in single-threaded programs. |
83 | | #include <signal.h> |
84 | | |
85 | | static inline void |
86 | | mythread_sigmask(int how, const sigset_t *restrict set, |
87 | | sigset_t *restrict oset) |
88 | | { |
89 | | int ret = sigprocmask(how, set, oset); |
90 | | assert(ret == 0); |
91 | | (void)ret; |
92 | | } |
93 | | #endif |
94 | | |
95 | | |
96 | | #elif defined(MYTHREAD_POSIX) |
97 | | |
98 | | //////////////////// |
99 | | // Using pthreads // |
100 | | //////////////////// |
101 | | |
102 | | #include <pthread.h> |
103 | | #include <signal.h> |
104 | | #include <time.h> |
105 | | #include <errno.h> |
106 | | |
107 | | // If clock_gettime() isn't available, use gettimeofday() from <sys/time.h> |
108 | | // as a fallback. gettimeofday() is in SUSv2 and thus is supported on all |
109 | | // relevant POSIX systems. |
110 | | #ifndef HAVE_CLOCK_GETTIME |
111 | | # include <sys/time.h> |
112 | | #endif |
113 | | |
114 | | // MinGW-w64 with winpthreads: |
115 | | // |
116 | | // NOTE: Typical builds with MinGW-w64 don't use this code (MYTHREAD_POSIX). |
117 | | // Instead, native Windows threading APIs are used (MYTHREAD_VISTA or |
118 | | // MYTHREAD_WIN95). |
119 | | // |
120 | | // MinGW-w64 has _sigset_t (an integer type) in <sys/types.h>. |
121 | | // If _POSIX was #defined, the header would add the alias sigset_t too. |
122 | | // Let's keep this working even without _POSIX. |
123 | | // |
124 | | // There are no functions that actually do something with sigset_t |
125 | | // because signals barely exist on Windows. The sigfillset macro below |
126 | | // is just to silence warnings. There is no sigfillset() in MinGW-w64. |
127 | | #ifdef __MINGW32__ |
128 | | # include <sys/types.h> |
129 | | # define sigset_t _sigset_t |
130 | | # define sigfillset(set_ptr) do { *(set_ptr) = 0; } while (0) |
131 | | #endif |
132 | | |
133 | | #define MYTHREAD_RET_TYPE void * |
134 | 0 | #define MYTHREAD_RET_VALUE NULL |
135 | | |
136 | | typedef pthread_t mythread; |
137 | | typedef pthread_mutex_t mythread_mutex; |
138 | | |
139 | | typedef struct { |
140 | | pthread_cond_t cond; |
141 | | #ifdef HAVE_CLOCK_GETTIME |
142 | | // Clock ID (CLOCK_REALTIME or CLOCK_MONOTONIC) associated with |
143 | | // the condition variable. |
144 | | clockid_t clk_id; |
145 | | #endif |
146 | | } mythread_cond; |
147 | | |
148 | | typedef struct timespec mythread_condtime; |
149 | | |
150 | | |
151 | | // Calls the given function once in a thread-safe way. |
152 | | #define mythread_once(func) \ |
153 | | do { \ |
154 | | static pthread_once_t once_ = PTHREAD_ONCE_INIT; \ |
155 | | pthread_once(&once_, &func); \ |
156 | | } while (0) |
157 | | |
158 | | |
159 | | // Use pthread_sigmask() to set the signal mask in multi-threaded programs. |
160 | | // Do nothing on OpenVMS since it lacks pthread_sigmask(). |
161 | | // Do nothing on MinGW-w64 too to silence warnings (its pthread_sigmask() |
162 | | // is #defined to 0 so it's a no-op). |
163 | | static inline void |
164 | | mythread_sigmask(int how, const sigset_t *restrict set, |
165 | | sigset_t *restrict oset) |
166 | 0 | { |
167 | | #if defined(__VMS) || defined(__MINGW32__) |
168 | | (void)how; |
169 | | (void)set; |
170 | | (void)oset; |
171 | | #else |
172 | 0 | int ret = pthread_sigmask(how, set, oset); |
173 | 0 | assert(ret == 0); |
174 | 0 | (void)ret; |
175 | 0 | #endif |
176 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_sigmask Unexecuted instantiation: crc32_table.c:mythread_sigmask Unexecuted instantiation: alone_decoder.c:mythread_sigmask Unexecuted instantiation: alone_encoder.c:mythread_sigmask Unexecuted instantiation: common.c:mythread_sigmask Unexecuted instantiation: filter_decoder.c:mythread_sigmask Unexecuted instantiation: filter_encoder.c:mythread_sigmask Unexecuted instantiation: hardware_cputhreads.c:mythread_sigmask Unexecuted instantiation: stream_decoder.c:mythread_sigmask Unexecuted instantiation: stream_encoder.c:mythread_sigmask Unexecuted instantiation: stream_encoder_mt.c:mythread_sigmask Unexecuted instantiation: stream_flags_common.c:mythread_sigmask Unexecuted instantiation: stream_flags_decoder.c:mythread_sigmask Unexecuted instantiation: stream_flags_encoder.c:mythread_sigmask Unexecuted instantiation: delta_common.c:mythread_sigmask Unexecuted instantiation: delta_decoder.c:mythread_sigmask Unexecuted instantiation: delta_encoder.c:mythread_sigmask Unexecuted instantiation: lzma2_decoder.c:mythread_sigmask Unexecuted instantiation: lzma2_encoder.c:mythread_sigmask Unexecuted instantiation: lzma_decoder.c:mythread_sigmask Unexecuted instantiation: lzma_encoder.c:mythread_sigmask Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_sigmask Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_sigmask Unexecuted instantiation: lzma_encoder_presets.c:mythread_sigmask Unexecuted instantiation: price_table.c:mythread_sigmask Unexecuted instantiation: arm.c:mythread_sigmask Unexecuted instantiation: armthumb.c:mythread_sigmask Unexecuted instantiation: ia64.c:mythread_sigmask Unexecuted instantiation: powerpc.c:mythread_sigmask Unexecuted instantiation: simple_coder.c:mythread_sigmask Unexecuted instantiation: simple_decoder.c:mythread_sigmask Unexecuted instantiation: simple_encoder.c:mythread_sigmask Unexecuted instantiation: sparc.c:mythread_sigmask Unexecuted instantiation: x86.c:mythread_sigmask Unexecuted instantiation: check.c:mythread_sigmask Unexecuted instantiation: crc64_fast.c:mythread_sigmask Unexecuted instantiation: crc64_table.c:mythread_sigmask Unexecuted instantiation: sha256.c:mythread_sigmask Unexecuted instantiation: block_buffer_encoder.c:mythread_sigmask Unexecuted instantiation: block_decoder.c:mythread_sigmask Unexecuted instantiation: block_encoder.c:mythread_sigmask Unexecuted instantiation: block_header_decoder.c:mythread_sigmask Unexecuted instantiation: block_header_encoder.c:mythread_sigmask Unexecuted instantiation: block_util.c:mythread_sigmask Unexecuted instantiation: easy_preset.c:mythread_sigmask Unexecuted instantiation: filter_common.c:mythread_sigmask Unexecuted instantiation: filter_flags_decoder.c:mythread_sigmask Unexecuted instantiation: filter_flags_encoder.c:mythread_sigmask Unexecuted instantiation: index.c:mythread_sigmask Unexecuted instantiation: index_encoder.c:mythread_sigmask Unexecuted instantiation: index_hash.c:mythread_sigmask Unexecuted instantiation: outqueue.c:mythread_sigmask Unexecuted instantiation: vli_decoder.c:mythread_sigmask Unexecuted instantiation: vli_encoder.c:mythread_sigmask Unexecuted instantiation: vli_size.c:mythread_sigmask Unexecuted instantiation: lz_decoder.c:mythread_sigmask Unexecuted instantiation: lz_encoder.c:mythread_sigmask Unexecuted instantiation: lz_encoder_mf.c:mythread_sigmask Unexecuted instantiation: fastpos_table.c:mythread_sigmask |
177 | | |
178 | | |
179 | | // Creates a new thread with all signals blocked. Returns zero on success |
180 | | // and non-zero on error. |
181 | | static inline int |
182 | | mythread_create(mythread *thread, void *(*func)(void *arg), void *arg) |
183 | 0 | { |
184 | 0 | sigset_t old; |
185 | 0 | sigset_t all; |
186 | 0 | sigfillset(&all); |
187 | |
|
188 | 0 | mythread_sigmask(SIG_SETMASK, &all, &old); |
189 | 0 | const int ret = pthread_create(thread, NULL, func, arg); |
190 | 0 | mythread_sigmask(SIG_SETMASK, &old, NULL); |
191 | |
|
192 | 0 | return ret; |
193 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_create Unexecuted instantiation: crc32_table.c:mythread_create Unexecuted instantiation: alone_decoder.c:mythread_create Unexecuted instantiation: alone_encoder.c:mythread_create Unexecuted instantiation: common.c:mythread_create Unexecuted instantiation: filter_decoder.c:mythread_create Unexecuted instantiation: filter_encoder.c:mythread_create Unexecuted instantiation: hardware_cputhreads.c:mythread_create Unexecuted instantiation: stream_decoder.c:mythread_create Unexecuted instantiation: stream_encoder.c:mythread_create Unexecuted instantiation: stream_encoder_mt.c:mythread_create Unexecuted instantiation: stream_flags_common.c:mythread_create Unexecuted instantiation: stream_flags_decoder.c:mythread_create Unexecuted instantiation: stream_flags_encoder.c:mythread_create Unexecuted instantiation: delta_common.c:mythread_create Unexecuted instantiation: delta_decoder.c:mythread_create Unexecuted instantiation: delta_encoder.c:mythread_create Unexecuted instantiation: lzma2_decoder.c:mythread_create Unexecuted instantiation: lzma2_encoder.c:mythread_create Unexecuted instantiation: lzma_decoder.c:mythread_create Unexecuted instantiation: lzma_encoder.c:mythread_create Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_create Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_create Unexecuted instantiation: lzma_encoder_presets.c:mythread_create Unexecuted instantiation: price_table.c:mythread_create Unexecuted instantiation: arm.c:mythread_create Unexecuted instantiation: armthumb.c:mythread_create Unexecuted instantiation: ia64.c:mythread_create Unexecuted instantiation: powerpc.c:mythread_create Unexecuted instantiation: simple_coder.c:mythread_create Unexecuted instantiation: simple_decoder.c:mythread_create Unexecuted instantiation: simple_encoder.c:mythread_create Unexecuted instantiation: sparc.c:mythread_create Unexecuted instantiation: x86.c:mythread_create Unexecuted instantiation: check.c:mythread_create Unexecuted instantiation: crc64_fast.c:mythread_create Unexecuted instantiation: crc64_table.c:mythread_create Unexecuted instantiation: sha256.c:mythread_create Unexecuted instantiation: block_buffer_encoder.c:mythread_create Unexecuted instantiation: block_decoder.c:mythread_create Unexecuted instantiation: block_encoder.c:mythread_create Unexecuted instantiation: block_header_decoder.c:mythread_create Unexecuted instantiation: block_header_encoder.c:mythread_create Unexecuted instantiation: block_util.c:mythread_create Unexecuted instantiation: easy_preset.c:mythread_create Unexecuted instantiation: filter_common.c:mythread_create Unexecuted instantiation: filter_flags_decoder.c:mythread_create Unexecuted instantiation: filter_flags_encoder.c:mythread_create Unexecuted instantiation: index.c:mythread_create Unexecuted instantiation: index_encoder.c:mythread_create Unexecuted instantiation: index_hash.c:mythread_create Unexecuted instantiation: outqueue.c:mythread_create Unexecuted instantiation: vli_decoder.c:mythread_create Unexecuted instantiation: vli_encoder.c:mythread_create Unexecuted instantiation: vli_size.c:mythread_create Unexecuted instantiation: lz_decoder.c:mythread_create Unexecuted instantiation: lz_encoder.c:mythread_create Unexecuted instantiation: lz_encoder_mf.c:mythread_create Unexecuted instantiation: fastpos_table.c:mythread_create |
194 | | |
195 | | // Joins a thread. Returns zero on success and non-zero on error. |
196 | | static inline int |
197 | | mythread_join(mythread thread) |
198 | 0 | { |
199 | 0 | return pthread_join(thread, NULL); |
200 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_join Unexecuted instantiation: crc32_table.c:mythread_join Unexecuted instantiation: alone_decoder.c:mythread_join Unexecuted instantiation: alone_encoder.c:mythread_join Unexecuted instantiation: common.c:mythread_join Unexecuted instantiation: filter_decoder.c:mythread_join Unexecuted instantiation: filter_encoder.c:mythread_join Unexecuted instantiation: hardware_cputhreads.c:mythread_join Unexecuted instantiation: stream_decoder.c:mythread_join Unexecuted instantiation: stream_encoder.c:mythread_join Unexecuted instantiation: stream_encoder_mt.c:mythread_join Unexecuted instantiation: stream_flags_common.c:mythread_join Unexecuted instantiation: stream_flags_decoder.c:mythread_join Unexecuted instantiation: stream_flags_encoder.c:mythread_join Unexecuted instantiation: delta_common.c:mythread_join Unexecuted instantiation: delta_decoder.c:mythread_join Unexecuted instantiation: delta_encoder.c:mythread_join Unexecuted instantiation: lzma2_decoder.c:mythread_join Unexecuted instantiation: lzma2_encoder.c:mythread_join Unexecuted instantiation: lzma_decoder.c:mythread_join Unexecuted instantiation: lzma_encoder.c:mythread_join Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_join Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_join Unexecuted instantiation: lzma_encoder_presets.c:mythread_join Unexecuted instantiation: price_table.c:mythread_join Unexecuted instantiation: arm.c:mythread_join Unexecuted instantiation: armthumb.c:mythread_join Unexecuted instantiation: ia64.c:mythread_join Unexecuted instantiation: powerpc.c:mythread_join Unexecuted instantiation: simple_coder.c:mythread_join Unexecuted instantiation: simple_decoder.c:mythread_join Unexecuted instantiation: simple_encoder.c:mythread_join Unexecuted instantiation: sparc.c:mythread_join Unexecuted instantiation: x86.c:mythread_join Unexecuted instantiation: check.c:mythread_join Unexecuted instantiation: crc64_fast.c:mythread_join Unexecuted instantiation: crc64_table.c:mythread_join Unexecuted instantiation: sha256.c:mythread_join Unexecuted instantiation: block_buffer_encoder.c:mythread_join Unexecuted instantiation: block_decoder.c:mythread_join Unexecuted instantiation: block_encoder.c:mythread_join Unexecuted instantiation: block_header_decoder.c:mythread_join Unexecuted instantiation: block_header_encoder.c:mythread_join Unexecuted instantiation: block_util.c:mythread_join Unexecuted instantiation: easy_preset.c:mythread_join Unexecuted instantiation: filter_common.c:mythread_join Unexecuted instantiation: filter_flags_decoder.c:mythread_join Unexecuted instantiation: filter_flags_encoder.c:mythread_join Unexecuted instantiation: index.c:mythread_join Unexecuted instantiation: index_encoder.c:mythread_join Unexecuted instantiation: index_hash.c:mythread_join Unexecuted instantiation: outqueue.c:mythread_join Unexecuted instantiation: vli_decoder.c:mythread_join Unexecuted instantiation: vli_encoder.c:mythread_join Unexecuted instantiation: vli_size.c:mythread_join Unexecuted instantiation: lz_decoder.c:mythread_join Unexecuted instantiation: lz_encoder.c:mythread_join Unexecuted instantiation: lz_encoder_mf.c:mythread_join Unexecuted instantiation: fastpos_table.c:mythread_join |
201 | | |
202 | | |
203 | | // Initializes a mutex. Returns zero on success and non-zero on error. |
204 | | static inline int |
205 | | mythread_mutex_init(mythread_mutex *mutex) |
206 | 0 | { |
207 | 0 | return pthread_mutex_init(mutex, NULL); |
208 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_mutex_init Unexecuted instantiation: crc32_table.c:mythread_mutex_init Unexecuted instantiation: alone_decoder.c:mythread_mutex_init Unexecuted instantiation: alone_encoder.c:mythread_mutex_init Unexecuted instantiation: common.c:mythread_mutex_init Unexecuted instantiation: filter_decoder.c:mythread_mutex_init Unexecuted instantiation: filter_encoder.c:mythread_mutex_init Unexecuted instantiation: hardware_cputhreads.c:mythread_mutex_init Unexecuted instantiation: stream_decoder.c:mythread_mutex_init Unexecuted instantiation: stream_encoder.c:mythread_mutex_init Unexecuted instantiation: stream_encoder_mt.c:mythread_mutex_init Unexecuted instantiation: stream_flags_common.c:mythread_mutex_init Unexecuted instantiation: stream_flags_decoder.c:mythread_mutex_init Unexecuted instantiation: stream_flags_encoder.c:mythread_mutex_init Unexecuted instantiation: delta_common.c:mythread_mutex_init Unexecuted instantiation: delta_decoder.c:mythread_mutex_init Unexecuted instantiation: delta_encoder.c:mythread_mutex_init Unexecuted instantiation: lzma2_decoder.c:mythread_mutex_init Unexecuted instantiation: lzma2_encoder.c:mythread_mutex_init Unexecuted instantiation: lzma_decoder.c:mythread_mutex_init Unexecuted instantiation: lzma_encoder.c:mythread_mutex_init Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_mutex_init Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_mutex_init Unexecuted instantiation: lzma_encoder_presets.c:mythread_mutex_init Unexecuted instantiation: price_table.c:mythread_mutex_init Unexecuted instantiation: arm.c:mythread_mutex_init Unexecuted instantiation: armthumb.c:mythread_mutex_init Unexecuted instantiation: ia64.c:mythread_mutex_init Unexecuted instantiation: powerpc.c:mythread_mutex_init Unexecuted instantiation: simple_coder.c:mythread_mutex_init Unexecuted instantiation: simple_decoder.c:mythread_mutex_init Unexecuted instantiation: simple_encoder.c:mythread_mutex_init Unexecuted instantiation: sparc.c:mythread_mutex_init Unexecuted instantiation: x86.c:mythread_mutex_init Unexecuted instantiation: check.c:mythread_mutex_init Unexecuted instantiation: crc64_fast.c:mythread_mutex_init Unexecuted instantiation: crc64_table.c:mythread_mutex_init Unexecuted instantiation: sha256.c:mythread_mutex_init Unexecuted instantiation: block_buffer_encoder.c:mythread_mutex_init Unexecuted instantiation: block_decoder.c:mythread_mutex_init Unexecuted instantiation: block_encoder.c:mythread_mutex_init Unexecuted instantiation: block_header_decoder.c:mythread_mutex_init Unexecuted instantiation: block_header_encoder.c:mythread_mutex_init Unexecuted instantiation: block_util.c:mythread_mutex_init Unexecuted instantiation: easy_preset.c:mythread_mutex_init Unexecuted instantiation: filter_common.c:mythread_mutex_init Unexecuted instantiation: filter_flags_decoder.c:mythread_mutex_init Unexecuted instantiation: filter_flags_encoder.c:mythread_mutex_init Unexecuted instantiation: index.c:mythread_mutex_init Unexecuted instantiation: index_encoder.c:mythread_mutex_init Unexecuted instantiation: index_hash.c:mythread_mutex_init Unexecuted instantiation: outqueue.c:mythread_mutex_init Unexecuted instantiation: vli_decoder.c:mythread_mutex_init Unexecuted instantiation: vli_encoder.c:mythread_mutex_init Unexecuted instantiation: vli_size.c:mythread_mutex_init Unexecuted instantiation: lz_decoder.c:mythread_mutex_init Unexecuted instantiation: lz_encoder.c:mythread_mutex_init Unexecuted instantiation: lz_encoder_mf.c:mythread_mutex_init Unexecuted instantiation: fastpos_table.c:mythread_mutex_init |
209 | | |
210 | | static inline void |
211 | | mythread_mutex_destroy(mythread_mutex *mutex) |
212 | 0 | { |
213 | 0 | int ret = pthread_mutex_destroy(mutex); |
214 | 0 | assert(ret == 0); |
215 | 0 | (void)ret; |
216 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_mutex_destroy Unexecuted instantiation: crc32_table.c:mythread_mutex_destroy Unexecuted instantiation: alone_decoder.c:mythread_mutex_destroy Unexecuted instantiation: alone_encoder.c:mythread_mutex_destroy Unexecuted instantiation: common.c:mythread_mutex_destroy Unexecuted instantiation: filter_decoder.c:mythread_mutex_destroy Unexecuted instantiation: filter_encoder.c:mythread_mutex_destroy Unexecuted instantiation: hardware_cputhreads.c:mythread_mutex_destroy Unexecuted instantiation: stream_decoder.c:mythread_mutex_destroy Unexecuted instantiation: stream_encoder.c:mythread_mutex_destroy Unexecuted instantiation: stream_encoder_mt.c:mythread_mutex_destroy Unexecuted instantiation: stream_flags_common.c:mythread_mutex_destroy Unexecuted instantiation: stream_flags_decoder.c:mythread_mutex_destroy Unexecuted instantiation: stream_flags_encoder.c:mythread_mutex_destroy Unexecuted instantiation: delta_common.c:mythread_mutex_destroy Unexecuted instantiation: delta_decoder.c:mythread_mutex_destroy Unexecuted instantiation: delta_encoder.c:mythread_mutex_destroy Unexecuted instantiation: lzma2_decoder.c:mythread_mutex_destroy Unexecuted instantiation: lzma2_encoder.c:mythread_mutex_destroy Unexecuted instantiation: lzma_decoder.c:mythread_mutex_destroy Unexecuted instantiation: lzma_encoder.c:mythread_mutex_destroy Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_mutex_destroy Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_mutex_destroy Unexecuted instantiation: lzma_encoder_presets.c:mythread_mutex_destroy Unexecuted instantiation: price_table.c:mythread_mutex_destroy Unexecuted instantiation: arm.c:mythread_mutex_destroy Unexecuted instantiation: armthumb.c:mythread_mutex_destroy Unexecuted instantiation: ia64.c:mythread_mutex_destroy Unexecuted instantiation: powerpc.c:mythread_mutex_destroy Unexecuted instantiation: simple_coder.c:mythread_mutex_destroy Unexecuted instantiation: simple_decoder.c:mythread_mutex_destroy Unexecuted instantiation: simple_encoder.c:mythread_mutex_destroy Unexecuted instantiation: sparc.c:mythread_mutex_destroy Unexecuted instantiation: x86.c:mythread_mutex_destroy Unexecuted instantiation: check.c:mythread_mutex_destroy Unexecuted instantiation: crc64_fast.c:mythread_mutex_destroy Unexecuted instantiation: crc64_table.c:mythread_mutex_destroy Unexecuted instantiation: sha256.c:mythread_mutex_destroy Unexecuted instantiation: block_buffer_encoder.c:mythread_mutex_destroy Unexecuted instantiation: block_decoder.c:mythread_mutex_destroy Unexecuted instantiation: block_encoder.c:mythread_mutex_destroy Unexecuted instantiation: block_header_decoder.c:mythread_mutex_destroy Unexecuted instantiation: block_header_encoder.c:mythread_mutex_destroy Unexecuted instantiation: block_util.c:mythread_mutex_destroy Unexecuted instantiation: easy_preset.c:mythread_mutex_destroy Unexecuted instantiation: filter_common.c:mythread_mutex_destroy Unexecuted instantiation: filter_flags_decoder.c:mythread_mutex_destroy Unexecuted instantiation: filter_flags_encoder.c:mythread_mutex_destroy Unexecuted instantiation: index.c:mythread_mutex_destroy Unexecuted instantiation: index_encoder.c:mythread_mutex_destroy Unexecuted instantiation: index_hash.c:mythread_mutex_destroy Unexecuted instantiation: outqueue.c:mythread_mutex_destroy Unexecuted instantiation: vli_decoder.c:mythread_mutex_destroy Unexecuted instantiation: vli_encoder.c:mythread_mutex_destroy Unexecuted instantiation: vli_size.c:mythread_mutex_destroy Unexecuted instantiation: lz_decoder.c:mythread_mutex_destroy Unexecuted instantiation: lz_encoder.c:mythread_mutex_destroy Unexecuted instantiation: lz_encoder_mf.c:mythread_mutex_destroy Unexecuted instantiation: fastpos_table.c:mythread_mutex_destroy |
217 | | |
218 | | static inline void |
219 | | mythread_mutex_lock(mythread_mutex *mutex) |
220 | 0 | { |
221 | 0 | int ret = pthread_mutex_lock(mutex); |
222 | 0 | assert(ret == 0); |
223 | 0 | (void)ret; |
224 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_mutex_lock Unexecuted instantiation: crc32_table.c:mythread_mutex_lock Unexecuted instantiation: alone_decoder.c:mythread_mutex_lock Unexecuted instantiation: alone_encoder.c:mythread_mutex_lock Unexecuted instantiation: common.c:mythread_mutex_lock Unexecuted instantiation: filter_decoder.c:mythread_mutex_lock Unexecuted instantiation: filter_encoder.c:mythread_mutex_lock Unexecuted instantiation: hardware_cputhreads.c:mythread_mutex_lock Unexecuted instantiation: stream_decoder.c:mythread_mutex_lock Unexecuted instantiation: stream_encoder.c:mythread_mutex_lock Unexecuted instantiation: stream_encoder_mt.c:mythread_mutex_lock Unexecuted instantiation: stream_flags_common.c:mythread_mutex_lock Unexecuted instantiation: stream_flags_decoder.c:mythread_mutex_lock Unexecuted instantiation: stream_flags_encoder.c:mythread_mutex_lock Unexecuted instantiation: delta_common.c:mythread_mutex_lock Unexecuted instantiation: delta_decoder.c:mythread_mutex_lock Unexecuted instantiation: delta_encoder.c:mythread_mutex_lock Unexecuted instantiation: lzma2_decoder.c:mythread_mutex_lock Unexecuted instantiation: lzma2_encoder.c:mythread_mutex_lock Unexecuted instantiation: lzma_decoder.c:mythread_mutex_lock Unexecuted instantiation: lzma_encoder.c:mythread_mutex_lock Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_mutex_lock Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_mutex_lock Unexecuted instantiation: lzma_encoder_presets.c:mythread_mutex_lock Unexecuted instantiation: price_table.c:mythread_mutex_lock Unexecuted instantiation: arm.c:mythread_mutex_lock Unexecuted instantiation: armthumb.c:mythread_mutex_lock Unexecuted instantiation: ia64.c:mythread_mutex_lock Unexecuted instantiation: powerpc.c:mythread_mutex_lock Unexecuted instantiation: simple_coder.c:mythread_mutex_lock Unexecuted instantiation: simple_decoder.c:mythread_mutex_lock Unexecuted instantiation: simple_encoder.c:mythread_mutex_lock Unexecuted instantiation: sparc.c:mythread_mutex_lock Unexecuted instantiation: x86.c:mythread_mutex_lock Unexecuted instantiation: check.c:mythread_mutex_lock Unexecuted instantiation: crc64_fast.c:mythread_mutex_lock Unexecuted instantiation: crc64_table.c:mythread_mutex_lock Unexecuted instantiation: sha256.c:mythread_mutex_lock Unexecuted instantiation: block_buffer_encoder.c:mythread_mutex_lock Unexecuted instantiation: block_decoder.c:mythread_mutex_lock Unexecuted instantiation: block_encoder.c:mythread_mutex_lock Unexecuted instantiation: block_header_decoder.c:mythread_mutex_lock Unexecuted instantiation: block_header_encoder.c:mythread_mutex_lock Unexecuted instantiation: block_util.c:mythread_mutex_lock Unexecuted instantiation: easy_preset.c:mythread_mutex_lock Unexecuted instantiation: filter_common.c:mythread_mutex_lock Unexecuted instantiation: filter_flags_decoder.c:mythread_mutex_lock Unexecuted instantiation: filter_flags_encoder.c:mythread_mutex_lock Unexecuted instantiation: index.c:mythread_mutex_lock Unexecuted instantiation: index_encoder.c:mythread_mutex_lock Unexecuted instantiation: index_hash.c:mythread_mutex_lock Unexecuted instantiation: outqueue.c:mythread_mutex_lock Unexecuted instantiation: vli_decoder.c:mythread_mutex_lock Unexecuted instantiation: vli_encoder.c:mythread_mutex_lock Unexecuted instantiation: vli_size.c:mythread_mutex_lock Unexecuted instantiation: lz_decoder.c:mythread_mutex_lock Unexecuted instantiation: lz_encoder.c:mythread_mutex_lock Unexecuted instantiation: lz_encoder_mf.c:mythread_mutex_lock Unexecuted instantiation: fastpos_table.c:mythread_mutex_lock |
225 | | |
226 | | static inline void |
227 | | mythread_mutex_unlock(mythread_mutex *mutex) |
228 | 0 | { |
229 | 0 | int ret = pthread_mutex_unlock(mutex); |
230 | 0 | assert(ret == 0); |
231 | 0 | (void)ret; |
232 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_mutex_unlock Unexecuted instantiation: crc32_table.c:mythread_mutex_unlock Unexecuted instantiation: alone_decoder.c:mythread_mutex_unlock Unexecuted instantiation: alone_encoder.c:mythread_mutex_unlock Unexecuted instantiation: common.c:mythread_mutex_unlock Unexecuted instantiation: filter_decoder.c:mythread_mutex_unlock Unexecuted instantiation: filter_encoder.c:mythread_mutex_unlock Unexecuted instantiation: hardware_cputhreads.c:mythread_mutex_unlock Unexecuted instantiation: stream_decoder.c:mythread_mutex_unlock Unexecuted instantiation: stream_encoder.c:mythread_mutex_unlock Unexecuted instantiation: stream_encoder_mt.c:mythread_mutex_unlock Unexecuted instantiation: stream_flags_common.c:mythread_mutex_unlock Unexecuted instantiation: stream_flags_decoder.c:mythread_mutex_unlock Unexecuted instantiation: stream_flags_encoder.c:mythread_mutex_unlock Unexecuted instantiation: delta_common.c:mythread_mutex_unlock Unexecuted instantiation: delta_decoder.c:mythread_mutex_unlock Unexecuted instantiation: delta_encoder.c:mythread_mutex_unlock Unexecuted instantiation: lzma2_decoder.c:mythread_mutex_unlock Unexecuted instantiation: lzma2_encoder.c:mythread_mutex_unlock Unexecuted instantiation: lzma_decoder.c:mythread_mutex_unlock Unexecuted instantiation: lzma_encoder.c:mythread_mutex_unlock Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_mutex_unlock Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_mutex_unlock Unexecuted instantiation: lzma_encoder_presets.c:mythread_mutex_unlock Unexecuted instantiation: price_table.c:mythread_mutex_unlock Unexecuted instantiation: arm.c:mythread_mutex_unlock Unexecuted instantiation: armthumb.c:mythread_mutex_unlock Unexecuted instantiation: ia64.c:mythread_mutex_unlock Unexecuted instantiation: powerpc.c:mythread_mutex_unlock Unexecuted instantiation: simple_coder.c:mythread_mutex_unlock Unexecuted instantiation: simple_decoder.c:mythread_mutex_unlock Unexecuted instantiation: simple_encoder.c:mythread_mutex_unlock Unexecuted instantiation: sparc.c:mythread_mutex_unlock Unexecuted instantiation: x86.c:mythread_mutex_unlock Unexecuted instantiation: check.c:mythread_mutex_unlock Unexecuted instantiation: crc64_fast.c:mythread_mutex_unlock Unexecuted instantiation: crc64_table.c:mythread_mutex_unlock Unexecuted instantiation: sha256.c:mythread_mutex_unlock Unexecuted instantiation: block_buffer_encoder.c:mythread_mutex_unlock Unexecuted instantiation: block_decoder.c:mythread_mutex_unlock Unexecuted instantiation: block_encoder.c:mythread_mutex_unlock Unexecuted instantiation: block_header_decoder.c:mythread_mutex_unlock Unexecuted instantiation: block_header_encoder.c:mythread_mutex_unlock Unexecuted instantiation: block_util.c:mythread_mutex_unlock Unexecuted instantiation: easy_preset.c:mythread_mutex_unlock Unexecuted instantiation: filter_common.c:mythread_mutex_unlock Unexecuted instantiation: filter_flags_decoder.c:mythread_mutex_unlock Unexecuted instantiation: filter_flags_encoder.c:mythread_mutex_unlock Unexecuted instantiation: index.c:mythread_mutex_unlock Unexecuted instantiation: index_encoder.c:mythread_mutex_unlock Unexecuted instantiation: index_hash.c:mythread_mutex_unlock Unexecuted instantiation: outqueue.c:mythread_mutex_unlock Unexecuted instantiation: vli_decoder.c:mythread_mutex_unlock Unexecuted instantiation: vli_encoder.c:mythread_mutex_unlock Unexecuted instantiation: vli_size.c:mythread_mutex_unlock Unexecuted instantiation: lz_decoder.c:mythread_mutex_unlock Unexecuted instantiation: lz_encoder.c:mythread_mutex_unlock Unexecuted instantiation: lz_encoder_mf.c:mythread_mutex_unlock Unexecuted instantiation: fastpos_table.c:mythread_mutex_unlock |
233 | | |
234 | | |
235 | | // Initializes a condition variable. |
236 | | // |
237 | | // Using CLOCK_MONOTONIC instead of the default CLOCK_REALTIME makes the |
238 | | // timeout in pthread_cond_timedwait() work correctly also if system time |
239 | | // is suddenly changed. Unfortunately CLOCK_MONOTONIC isn't available |
240 | | // everywhere while the default CLOCK_REALTIME is, so the default is |
241 | | // used if CLOCK_MONOTONIC isn't available. |
242 | | // |
243 | | // If clock_gettime() isn't available at all, gettimeofday() will be used. |
244 | | static inline int |
245 | | mythread_cond_init(mythread_cond *mycond) |
246 | 0 | { |
247 | | #ifdef HAVE_CLOCK_GETTIME |
248 | | # if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && \ |
249 | | defined(HAVE_CLOCK_MONOTONIC) |
250 | | struct timespec ts; |
251 | | pthread_condattr_t condattr; |
252 | | |
253 | | // POSIX doesn't seem to *require* that pthread_condattr_setclock() |
254 | | // will fail if given an unsupported clock ID. Test that |
255 | | // CLOCK_MONOTONIC really is supported using clock_gettime(). |
256 | | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0 |
257 | | && pthread_condattr_init(&condattr) == 0) { |
258 | | int ret = pthread_condattr_setclock( |
259 | | &condattr, CLOCK_MONOTONIC); |
260 | | if (ret == 0) |
261 | | ret = pthread_cond_init(&mycond->cond, &condattr); |
262 | | |
263 | | pthread_condattr_destroy(&condattr); |
264 | | |
265 | | if (ret == 0) { |
266 | | mycond->clk_id = CLOCK_MONOTONIC; |
267 | | return 0; |
268 | | } |
269 | | } |
270 | | |
271 | | // If anything above fails, fall back to the default CLOCK_REALTIME. |
272 | | // POSIX requires that all implementations of clock_gettime() must |
273 | | // support at least CLOCK_REALTIME. |
274 | | # endif |
275 | | |
276 | | mycond->clk_id = CLOCK_REALTIME; |
277 | | #endif |
278 | |
|
279 | 0 | return pthread_cond_init(&mycond->cond, NULL); |
280 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_cond_init Unexecuted instantiation: crc32_table.c:mythread_cond_init Unexecuted instantiation: alone_decoder.c:mythread_cond_init Unexecuted instantiation: alone_encoder.c:mythread_cond_init Unexecuted instantiation: common.c:mythread_cond_init Unexecuted instantiation: filter_decoder.c:mythread_cond_init Unexecuted instantiation: filter_encoder.c:mythread_cond_init Unexecuted instantiation: hardware_cputhreads.c:mythread_cond_init Unexecuted instantiation: stream_decoder.c:mythread_cond_init Unexecuted instantiation: stream_encoder.c:mythread_cond_init Unexecuted instantiation: stream_encoder_mt.c:mythread_cond_init Unexecuted instantiation: stream_flags_common.c:mythread_cond_init Unexecuted instantiation: stream_flags_decoder.c:mythread_cond_init Unexecuted instantiation: stream_flags_encoder.c:mythread_cond_init Unexecuted instantiation: delta_common.c:mythread_cond_init Unexecuted instantiation: delta_decoder.c:mythread_cond_init Unexecuted instantiation: delta_encoder.c:mythread_cond_init Unexecuted instantiation: lzma2_decoder.c:mythread_cond_init Unexecuted instantiation: lzma2_encoder.c:mythread_cond_init Unexecuted instantiation: lzma_decoder.c:mythread_cond_init Unexecuted instantiation: lzma_encoder.c:mythread_cond_init Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_cond_init Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_cond_init Unexecuted instantiation: lzma_encoder_presets.c:mythread_cond_init Unexecuted instantiation: price_table.c:mythread_cond_init Unexecuted instantiation: arm.c:mythread_cond_init Unexecuted instantiation: armthumb.c:mythread_cond_init Unexecuted instantiation: ia64.c:mythread_cond_init Unexecuted instantiation: powerpc.c:mythread_cond_init Unexecuted instantiation: simple_coder.c:mythread_cond_init Unexecuted instantiation: simple_decoder.c:mythread_cond_init Unexecuted instantiation: simple_encoder.c:mythread_cond_init Unexecuted instantiation: sparc.c:mythread_cond_init Unexecuted instantiation: x86.c:mythread_cond_init Unexecuted instantiation: check.c:mythread_cond_init Unexecuted instantiation: crc64_fast.c:mythread_cond_init Unexecuted instantiation: crc64_table.c:mythread_cond_init Unexecuted instantiation: sha256.c:mythread_cond_init Unexecuted instantiation: block_buffer_encoder.c:mythread_cond_init Unexecuted instantiation: block_decoder.c:mythread_cond_init Unexecuted instantiation: block_encoder.c:mythread_cond_init Unexecuted instantiation: block_header_decoder.c:mythread_cond_init Unexecuted instantiation: block_header_encoder.c:mythread_cond_init Unexecuted instantiation: block_util.c:mythread_cond_init Unexecuted instantiation: easy_preset.c:mythread_cond_init Unexecuted instantiation: filter_common.c:mythread_cond_init Unexecuted instantiation: filter_flags_decoder.c:mythread_cond_init Unexecuted instantiation: filter_flags_encoder.c:mythread_cond_init Unexecuted instantiation: index.c:mythread_cond_init Unexecuted instantiation: index_encoder.c:mythread_cond_init Unexecuted instantiation: index_hash.c:mythread_cond_init Unexecuted instantiation: outqueue.c:mythread_cond_init Unexecuted instantiation: vli_decoder.c:mythread_cond_init Unexecuted instantiation: vli_encoder.c:mythread_cond_init Unexecuted instantiation: vli_size.c:mythread_cond_init Unexecuted instantiation: lz_decoder.c:mythread_cond_init Unexecuted instantiation: lz_encoder.c:mythread_cond_init Unexecuted instantiation: lz_encoder_mf.c:mythread_cond_init Unexecuted instantiation: fastpos_table.c:mythread_cond_init |
281 | | |
282 | | static inline void |
283 | | mythread_cond_destroy(mythread_cond *cond) |
284 | 0 | { |
285 | 0 | int ret = pthread_cond_destroy(&cond->cond); |
286 | 0 | assert(ret == 0); |
287 | 0 | (void)ret; |
288 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_cond_destroy Unexecuted instantiation: crc32_table.c:mythread_cond_destroy Unexecuted instantiation: alone_decoder.c:mythread_cond_destroy Unexecuted instantiation: alone_encoder.c:mythread_cond_destroy Unexecuted instantiation: common.c:mythread_cond_destroy Unexecuted instantiation: filter_decoder.c:mythread_cond_destroy Unexecuted instantiation: filter_encoder.c:mythread_cond_destroy Unexecuted instantiation: hardware_cputhreads.c:mythread_cond_destroy Unexecuted instantiation: stream_decoder.c:mythread_cond_destroy Unexecuted instantiation: stream_encoder.c:mythread_cond_destroy Unexecuted instantiation: stream_encoder_mt.c:mythread_cond_destroy Unexecuted instantiation: stream_flags_common.c:mythread_cond_destroy Unexecuted instantiation: stream_flags_decoder.c:mythread_cond_destroy Unexecuted instantiation: stream_flags_encoder.c:mythread_cond_destroy Unexecuted instantiation: delta_common.c:mythread_cond_destroy Unexecuted instantiation: delta_decoder.c:mythread_cond_destroy Unexecuted instantiation: delta_encoder.c:mythread_cond_destroy Unexecuted instantiation: lzma2_decoder.c:mythread_cond_destroy Unexecuted instantiation: lzma2_encoder.c:mythread_cond_destroy Unexecuted instantiation: lzma_decoder.c:mythread_cond_destroy Unexecuted instantiation: lzma_encoder.c:mythread_cond_destroy Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_cond_destroy Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_cond_destroy Unexecuted instantiation: lzma_encoder_presets.c:mythread_cond_destroy Unexecuted instantiation: price_table.c:mythread_cond_destroy Unexecuted instantiation: arm.c:mythread_cond_destroy Unexecuted instantiation: armthumb.c:mythread_cond_destroy Unexecuted instantiation: ia64.c:mythread_cond_destroy Unexecuted instantiation: powerpc.c:mythread_cond_destroy Unexecuted instantiation: simple_coder.c:mythread_cond_destroy Unexecuted instantiation: simple_decoder.c:mythread_cond_destroy Unexecuted instantiation: simple_encoder.c:mythread_cond_destroy Unexecuted instantiation: sparc.c:mythread_cond_destroy Unexecuted instantiation: x86.c:mythread_cond_destroy Unexecuted instantiation: check.c:mythread_cond_destroy Unexecuted instantiation: crc64_fast.c:mythread_cond_destroy Unexecuted instantiation: crc64_table.c:mythread_cond_destroy Unexecuted instantiation: sha256.c:mythread_cond_destroy Unexecuted instantiation: block_buffer_encoder.c:mythread_cond_destroy Unexecuted instantiation: block_decoder.c:mythread_cond_destroy Unexecuted instantiation: block_encoder.c:mythread_cond_destroy Unexecuted instantiation: block_header_decoder.c:mythread_cond_destroy Unexecuted instantiation: block_header_encoder.c:mythread_cond_destroy Unexecuted instantiation: block_util.c:mythread_cond_destroy Unexecuted instantiation: easy_preset.c:mythread_cond_destroy Unexecuted instantiation: filter_common.c:mythread_cond_destroy Unexecuted instantiation: filter_flags_decoder.c:mythread_cond_destroy Unexecuted instantiation: filter_flags_encoder.c:mythread_cond_destroy Unexecuted instantiation: index.c:mythread_cond_destroy Unexecuted instantiation: index_encoder.c:mythread_cond_destroy Unexecuted instantiation: index_hash.c:mythread_cond_destroy Unexecuted instantiation: outqueue.c:mythread_cond_destroy Unexecuted instantiation: vli_decoder.c:mythread_cond_destroy Unexecuted instantiation: vli_encoder.c:mythread_cond_destroy Unexecuted instantiation: vli_size.c:mythread_cond_destroy Unexecuted instantiation: lz_decoder.c:mythread_cond_destroy Unexecuted instantiation: lz_encoder.c:mythread_cond_destroy Unexecuted instantiation: lz_encoder_mf.c:mythread_cond_destroy Unexecuted instantiation: fastpos_table.c:mythread_cond_destroy |
289 | | |
290 | | static inline void |
291 | | mythread_cond_signal(mythread_cond *cond) |
292 | 0 | { |
293 | 0 | int ret = pthread_cond_signal(&cond->cond); |
294 | 0 | assert(ret == 0); |
295 | 0 | (void)ret; |
296 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_cond_signal Unexecuted instantiation: crc32_table.c:mythread_cond_signal Unexecuted instantiation: alone_decoder.c:mythread_cond_signal Unexecuted instantiation: alone_encoder.c:mythread_cond_signal Unexecuted instantiation: common.c:mythread_cond_signal Unexecuted instantiation: filter_decoder.c:mythread_cond_signal Unexecuted instantiation: filter_encoder.c:mythread_cond_signal Unexecuted instantiation: hardware_cputhreads.c:mythread_cond_signal Unexecuted instantiation: stream_decoder.c:mythread_cond_signal Unexecuted instantiation: stream_encoder.c:mythread_cond_signal Unexecuted instantiation: stream_encoder_mt.c:mythread_cond_signal Unexecuted instantiation: stream_flags_common.c:mythread_cond_signal Unexecuted instantiation: stream_flags_decoder.c:mythread_cond_signal Unexecuted instantiation: stream_flags_encoder.c:mythread_cond_signal Unexecuted instantiation: delta_common.c:mythread_cond_signal Unexecuted instantiation: delta_decoder.c:mythread_cond_signal Unexecuted instantiation: delta_encoder.c:mythread_cond_signal Unexecuted instantiation: lzma2_decoder.c:mythread_cond_signal Unexecuted instantiation: lzma2_encoder.c:mythread_cond_signal Unexecuted instantiation: lzma_decoder.c:mythread_cond_signal Unexecuted instantiation: lzma_encoder.c:mythread_cond_signal Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_cond_signal Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_cond_signal Unexecuted instantiation: lzma_encoder_presets.c:mythread_cond_signal Unexecuted instantiation: price_table.c:mythread_cond_signal Unexecuted instantiation: arm.c:mythread_cond_signal Unexecuted instantiation: armthumb.c:mythread_cond_signal Unexecuted instantiation: ia64.c:mythread_cond_signal Unexecuted instantiation: powerpc.c:mythread_cond_signal Unexecuted instantiation: simple_coder.c:mythread_cond_signal Unexecuted instantiation: simple_decoder.c:mythread_cond_signal Unexecuted instantiation: simple_encoder.c:mythread_cond_signal Unexecuted instantiation: sparc.c:mythread_cond_signal Unexecuted instantiation: x86.c:mythread_cond_signal Unexecuted instantiation: check.c:mythread_cond_signal Unexecuted instantiation: crc64_fast.c:mythread_cond_signal Unexecuted instantiation: crc64_table.c:mythread_cond_signal Unexecuted instantiation: sha256.c:mythread_cond_signal Unexecuted instantiation: block_buffer_encoder.c:mythread_cond_signal Unexecuted instantiation: block_decoder.c:mythread_cond_signal Unexecuted instantiation: block_encoder.c:mythread_cond_signal Unexecuted instantiation: block_header_decoder.c:mythread_cond_signal Unexecuted instantiation: block_header_encoder.c:mythread_cond_signal Unexecuted instantiation: block_util.c:mythread_cond_signal Unexecuted instantiation: easy_preset.c:mythread_cond_signal Unexecuted instantiation: filter_common.c:mythread_cond_signal Unexecuted instantiation: filter_flags_decoder.c:mythread_cond_signal Unexecuted instantiation: filter_flags_encoder.c:mythread_cond_signal Unexecuted instantiation: index.c:mythread_cond_signal Unexecuted instantiation: index_encoder.c:mythread_cond_signal Unexecuted instantiation: index_hash.c:mythread_cond_signal Unexecuted instantiation: outqueue.c:mythread_cond_signal Unexecuted instantiation: vli_decoder.c:mythread_cond_signal Unexecuted instantiation: vli_encoder.c:mythread_cond_signal Unexecuted instantiation: vli_size.c:mythread_cond_signal Unexecuted instantiation: lz_decoder.c:mythread_cond_signal Unexecuted instantiation: lz_encoder.c:mythread_cond_signal Unexecuted instantiation: lz_encoder_mf.c:mythread_cond_signal Unexecuted instantiation: fastpos_table.c:mythread_cond_signal |
297 | | |
298 | | static inline void |
299 | | mythread_cond_wait(mythread_cond *cond, mythread_mutex *mutex) |
300 | 0 | { |
301 | 0 | int ret = pthread_cond_wait(&cond->cond, mutex); |
302 | 0 | assert(ret == 0); |
303 | 0 | (void)ret; |
304 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_cond_wait Unexecuted instantiation: crc32_table.c:mythread_cond_wait Unexecuted instantiation: alone_decoder.c:mythread_cond_wait Unexecuted instantiation: alone_encoder.c:mythread_cond_wait Unexecuted instantiation: common.c:mythread_cond_wait Unexecuted instantiation: filter_decoder.c:mythread_cond_wait Unexecuted instantiation: filter_encoder.c:mythread_cond_wait Unexecuted instantiation: hardware_cputhreads.c:mythread_cond_wait Unexecuted instantiation: stream_decoder.c:mythread_cond_wait Unexecuted instantiation: stream_encoder.c:mythread_cond_wait Unexecuted instantiation: stream_encoder_mt.c:mythread_cond_wait Unexecuted instantiation: stream_flags_common.c:mythread_cond_wait Unexecuted instantiation: stream_flags_decoder.c:mythread_cond_wait Unexecuted instantiation: stream_flags_encoder.c:mythread_cond_wait Unexecuted instantiation: delta_common.c:mythread_cond_wait Unexecuted instantiation: delta_decoder.c:mythread_cond_wait Unexecuted instantiation: delta_encoder.c:mythread_cond_wait Unexecuted instantiation: lzma2_decoder.c:mythread_cond_wait Unexecuted instantiation: lzma2_encoder.c:mythread_cond_wait Unexecuted instantiation: lzma_decoder.c:mythread_cond_wait Unexecuted instantiation: lzma_encoder.c:mythread_cond_wait Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_cond_wait Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_cond_wait Unexecuted instantiation: lzma_encoder_presets.c:mythread_cond_wait Unexecuted instantiation: price_table.c:mythread_cond_wait Unexecuted instantiation: arm.c:mythread_cond_wait Unexecuted instantiation: armthumb.c:mythread_cond_wait Unexecuted instantiation: ia64.c:mythread_cond_wait Unexecuted instantiation: powerpc.c:mythread_cond_wait Unexecuted instantiation: simple_coder.c:mythread_cond_wait Unexecuted instantiation: simple_decoder.c:mythread_cond_wait Unexecuted instantiation: simple_encoder.c:mythread_cond_wait Unexecuted instantiation: sparc.c:mythread_cond_wait Unexecuted instantiation: x86.c:mythread_cond_wait Unexecuted instantiation: check.c:mythread_cond_wait Unexecuted instantiation: crc64_fast.c:mythread_cond_wait Unexecuted instantiation: crc64_table.c:mythread_cond_wait Unexecuted instantiation: sha256.c:mythread_cond_wait Unexecuted instantiation: block_buffer_encoder.c:mythread_cond_wait Unexecuted instantiation: block_decoder.c:mythread_cond_wait Unexecuted instantiation: block_encoder.c:mythread_cond_wait Unexecuted instantiation: block_header_decoder.c:mythread_cond_wait Unexecuted instantiation: block_header_encoder.c:mythread_cond_wait Unexecuted instantiation: block_util.c:mythread_cond_wait Unexecuted instantiation: easy_preset.c:mythread_cond_wait Unexecuted instantiation: filter_common.c:mythread_cond_wait Unexecuted instantiation: filter_flags_decoder.c:mythread_cond_wait Unexecuted instantiation: filter_flags_encoder.c:mythread_cond_wait Unexecuted instantiation: index.c:mythread_cond_wait Unexecuted instantiation: index_encoder.c:mythread_cond_wait Unexecuted instantiation: index_hash.c:mythread_cond_wait Unexecuted instantiation: outqueue.c:mythread_cond_wait Unexecuted instantiation: vli_decoder.c:mythread_cond_wait Unexecuted instantiation: vli_encoder.c:mythread_cond_wait Unexecuted instantiation: vli_size.c:mythread_cond_wait Unexecuted instantiation: lz_decoder.c:mythread_cond_wait Unexecuted instantiation: lz_encoder.c:mythread_cond_wait Unexecuted instantiation: lz_encoder_mf.c:mythread_cond_wait Unexecuted instantiation: fastpos_table.c:mythread_cond_wait |
305 | | |
306 | | // Waits on a condition or until a timeout expires. If the timeout expires, |
307 | | // non-zero is returned, otherwise zero is returned. |
308 | | static inline int |
309 | | mythread_cond_timedwait(mythread_cond *cond, mythread_mutex *mutex, |
310 | | const mythread_condtime *condtime) |
311 | 0 | { |
312 | 0 | int ret = pthread_cond_timedwait(&cond->cond, mutex, condtime); |
313 | 0 | assert(ret == 0 || ret == ETIMEDOUT); |
314 | 0 | return ret; |
315 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_cond_timedwait Unexecuted instantiation: crc32_table.c:mythread_cond_timedwait Unexecuted instantiation: alone_decoder.c:mythread_cond_timedwait Unexecuted instantiation: alone_encoder.c:mythread_cond_timedwait Unexecuted instantiation: common.c:mythread_cond_timedwait Unexecuted instantiation: filter_decoder.c:mythread_cond_timedwait Unexecuted instantiation: filter_encoder.c:mythread_cond_timedwait Unexecuted instantiation: hardware_cputhreads.c:mythread_cond_timedwait Unexecuted instantiation: stream_decoder.c:mythread_cond_timedwait Unexecuted instantiation: stream_encoder.c:mythread_cond_timedwait Unexecuted instantiation: stream_encoder_mt.c:mythread_cond_timedwait Unexecuted instantiation: stream_flags_common.c:mythread_cond_timedwait Unexecuted instantiation: stream_flags_decoder.c:mythread_cond_timedwait Unexecuted instantiation: stream_flags_encoder.c:mythread_cond_timedwait Unexecuted instantiation: delta_common.c:mythread_cond_timedwait Unexecuted instantiation: delta_decoder.c:mythread_cond_timedwait Unexecuted instantiation: delta_encoder.c:mythread_cond_timedwait Unexecuted instantiation: lzma2_decoder.c:mythread_cond_timedwait Unexecuted instantiation: lzma2_encoder.c:mythread_cond_timedwait Unexecuted instantiation: lzma_decoder.c:mythread_cond_timedwait Unexecuted instantiation: lzma_encoder.c:mythread_cond_timedwait Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_cond_timedwait Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_cond_timedwait Unexecuted instantiation: lzma_encoder_presets.c:mythread_cond_timedwait Unexecuted instantiation: price_table.c:mythread_cond_timedwait Unexecuted instantiation: arm.c:mythread_cond_timedwait Unexecuted instantiation: armthumb.c:mythread_cond_timedwait Unexecuted instantiation: ia64.c:mythread_cond_timedwait Unexecuted instantiation: powerpc.c:mythread_cond_timedwait Unexecuted instantiation: simple_coder.c:mythread_cond_timedwait Unexecuted instantiation: simple_decoder.c:mythread_cond_timedwait Unexecuted instantiation: simple_encoder.c:mythread_cond_timedwait Unexecuted instantiation: sparc.c:mythread_cond_timedwait Unexecuted instantiation: x86.c:mythread_cond_timedwait Unexecuted instantiation: check.c:mythread_cond_timedwait Unexecuted instantiation: crc64_fast.c:mythread_cond_timedwait Unexecuted instantiation: crc64_table.c:mythread_cond_timedwait Unexecuted instantiation: sha256.c:mythread_cond_timedwait Unexecuted instantiation: block_buffer_encoder.c:mythread_cond_timedwait Unexecuted instantiation: block_decoder.c:mythread_cond_timedwait Unexecuted instantiation: block_encoder.c:mythread_cond_timedwait Unexecuted instantiation: block_header_decoder.c:mythread_cond_timedwait Unexecuted instantiation: block_header_encoder.c:mythread_cond_timedwait Unexecuted instantiation: block_util.c:mythread_cond_timedwait Unexecuted instantiation: easy_preset.c:mythread_cond_timedwait Unexecuted instantiation: filter_common.c:mythread_cond_timedwait Unexecuted instantiation: filter_flags_decoder.c:mythread_cond_timedwait Unexecuted instantiation: filter_flags_encoder.c:mythread_cond_timedwait Unexecuted instantiation: index.c:mythread_cond_timedwait Unexecuted instantiation: index_encoder.c:mythread_cond_timedwait Unexecuted instantiation: index_hash.c:mythread_cond_timedwait Unexecuted instantiation: outqueue.c:mythread_cond_timedwait Unexecuted instantiation: vli_decoder.c:mythread_cond_timedwait Unexecuted instantiation: vli_encoder.c:mythread_cond_timedwait Unexecuted instantiation: vli_size.c:mythread_cond_timedwait Unexecuted instantiation: lz_decoder.c:mythread_cond_timedwait Unexecuted instantiation: lz_encoder.c:mythread_cond_timedwait Unexecuted instantiation: lz_encoder_mf.c:mythread_cond_timedwait Unexecuted instantiation: fastpos_table.c:mythread_cond_timedwait |
316 | | |
317 | | // Sets condtime to the absolute time that is timeout_ms milliseconds |
318 | | // in the future. The type of the clock to use is taken from cond. |
319 | | static inline void |
320 | | mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond, |
321 | | uint32_t timeout_ms) |
322 | 0 | { |
323 | 0 | condtime->tv_sec = (time_t)(timeout_ms / 1000); |
324 | 0 | condtime->tv_nsec = (long)((timeout_ms % 1000) * 1000000); |
325 | |
|
326 | | #ifdef HAVE_CLOCK_GETTIME |
327 | | struct timespec now; |
328 | | int ret = clock_gettime(cond->clk_id, &now); |
329 | | assert(ret == 0); |
330 | | (void)ret; |
331 | | |
332 | | condtime->tv_sec += now.tv_sec; |
333 | | condtime->tv_nsec += now.tv_nsec; |
334 | | #else |
335 | 0 | (void)cond; |
336 | |
|
337 | 0 | struct timeval now; |
338 | 0 | gettimeofday(&now, NULL); |
339 | |
|
340 | 0 | condtime->tv_sec += now.tv_sec; |
341 | 0 | condtime->tv_nsec += now.tv_usec * 1000L; |
342 | 0 | #endif |
343 | | |
344 | | // tv_nsec must stay in the range [0, 999_999_999]. |
345 | 0 | if (condtime->tv_nsec >= 1000000000L) { |
346 | 0 | condtime->tv_nsec -= 1000000000L; |
347 | 0 | ++condtime->tv_sec; |
348 | 0 | } |
349 | 0 | } Unexecuted instantiation: crc32_fast.c:mythread_condtime_set Unexecuted instantiation: crc32_table.c:mythread_condtime_set Unexecuted instantiation: alone_decoder.c:mythread_condtime_set Unexecuted instantiation: alone_encoder.c:mythread_condtime_set Unexecuted instantiation: common.c:mythread_condtime_set Unexecuted instantiation: filter_decoder.c:mythread_condtime_set Unexecuted instantiation: filter_encoder.c:mythread_condtime_set Unexecuted instantiation: hardware_cputhreads.c:mythread_condtime_set Unexecuted instantiation: stream_decoder.c:mythread_condtime_set Unexecuted instantiation: stream_encoder.c:mythread_condtime_set Unexecuted instantiation: stream_encoder_mt.c:mythread_condtime_set Unexecuted instantiation: stream_flags_common.c:mythread_condtime_set Unexecuted instantiation: stream_flags_decoder.c:mythread_condtime_set Unexecuted instantiation: stream_flags_encoder.c:mythread_condtime_set Unexecuted instantiation: delta_common.c:mythread_condtime_set Unexecuted instantiation: delta_decoder.c:mythread_condtime_set Unexecuted instantiation: delta_encoder.c:mythread_condtime_set Unexecuted instantiation: lzma2_decoder.c:mythread_condtime_set Unexecuted instantiation: lzma2_encoder.c:mythread_condtime_set Unexecuted instantiation: lzma_decoder.c:mythread_condtime_set Unexecuted instantiation: lzma_encoder.c:mythread_condtime_set Unexecuted instantiation: lzma_encoder_optimum_fast.c:mythread_condtime_set Unexecuted instantiation: lzma_encoder_optimum_normal.c:mythread_condtime_set Unexecuted instantiation: lzma_encoder_presets.c:mythread_condtime_set Unexecuted instantiation: price_table.c:mythread_condtime_set Unexecuted instantiation: arm.c:mythread_condtime_set Unexecuted instantiation: armthumb.c:mythread_condtime_set Unexecuted instantiation: ia64.c:mythread_condtime_set Unexecuted instantiation: powerpc.c:mythread_condtime_set Unexecuted instantiation: simple_coder.c:mythread_condtime_set Unexecuted instantiation: simple_decoder.c:mythread_condtime_set Unexecuted instantiation: simple_encoder.c:mythread_condtime_set Unexecuted instantiation: sparc.c:mythread_condtime_set Unexecuted instantiation: x86.c:mythread_condtime_set Unexecuted instantiation: check.c:mythread_condtime_set Unexecuted instantiation: crc64_fast.c:mythread_condtime_set Unexecuted instantiation: crc64_table.c:mythread_condtime_set Unexecuted instantiation: sha256.c:mythread_condtime_set Unexecuted instantiation: block_buffer_encoder.c:mythread_condtime_set Unexecuted instantiation: block_decoder.c:mythread_condtime_set Unexecuted instantiation: block_encoder.c:mythread_condtime_set Unexecuted instantiation: block_header_decoder.c:mythread_condtime_set Unexecuted instantiation: block_header_encoder.c:mythread_condtime_set Unexecuted instantiation: block_util.c:mythread_condtime_set Unexecuted instantiation: easy_preset.c:mythread_condtime_set Unexecuted instantiation: filter_common.c:mythread_condtime_set Unexecuted instantiation: filter_flags_decoder.c:mythread_condtime_set Unexecuted instantiation: filter_flags_encoder.c:mythread_condtime_set Unexecuted instantiation: index.c:mythread_condtime_set Unexecuted instantiation: index_encoder.c:mythread_condtime_set Unexecuted instantiation: index_hash.c:mythread_condtime_set Unexecuted instantiation: outqueue.c:mythread_condtime_set Unexecuted instantiation: vli_decoder.c:mythread_condtime_set Unexecuted instantiation: vli_encoder.c:mythread_condtime_set Unexecuted instantiation: vli_size.c:mythread_condtime_set Unexecuted instantiation: lz_decoder.c:mythread_condtime_set Unexecuted instantiation: lz_encoder.c:mythread_condtime_set Unexecuted instantiation: lz_encoder_mf.c:mythread_condtime_set Unexecuted instantiation: fastpos_table.c:mythread_condtime_set |
350 | | |
351 | | |
352 | | #elif defined(MYTHREAD_WIN95) || defined(MYTHREAD_VISTA) |
353 | | |
354 | | ///////////////////// |
355 | | // Windows threads // |
356 | | ///////////////////// |
357 | | |
358 | | #define WIN32_LEAN_AND_MEAN |
359 | | #ifdef MYTHREAD_VISTA |
360 | | # undef _WIN32_WINNT |
361 | | # define _WIN32_WINNT 0x0600 |
362 | | #endif |
363 | | #include <windows.h> |
364 | | #include <process.h> |
365 | | |
366 | | #define MYTHREAD_RET_TYPE unsigned int __stdcall |
367 | | #define MYTHREAD_RET_VALUE 0 |
368 | | |
369 | | typedef HANDLE mythread; |
370 | | typedef CRITICAL_SECTION mythread_mutex; |
371 | | |
372 | | #ifdef MYTHREAD_WIN95 |
373 | | typedef HANDLE mythread_cond; |
374 | | #else |
375 | | typedef CONDITION_VARIABLE mythread_cond; |
376 | | #endif |
377 | | |
378 | | typedef struct { |
379 | | // Tick count (milliseconds) in the beginning of the timeout. |
380 | | // NOTE: This is 32 bits so it wraps around after 49.7 days. |
381 | | // Multi-day timeouts may not work as expected. |
382 | | DWORD start; |
383 | | |
384 | | // Length of the timeout in milliseconds. The timeout expires |
385 | | // when the current tick count minus "start" is equal or greater |
386 | | // than "timeout". |
387 | | DWORD timeout; |
388 | | } mythread_condtime; |
389 | | |
390 | | |
391 | | // mythread_once() is only available with Vista threads. |
392 | | #ifdef MYTHREAD_VISTA |
393 | | #define mythread_once(func) \ |
394 | | do { \ |
395 | | static INIT_ONCE once_ = INIT_ONCE_STATIC_INIT; \ |
396 | | BOOL pending_; \ |
397 | | if (!InitOnceBeginInitialize(&once_, 0, &pending_, NULL)) \ |
398 | | abort(); \ |
399 | | if (pending_) { \ |
400 | | func(); \ |
401 | | if (!InitOnceComplete(&once_, 0, NULL)) \ |
402 | | abort(); \ |
403 | | } \ |
404 | | } while (0) |
405 | | #endif |
406 | | |
407 | | |
408 | | // mythread_sigmask() isn't available on Windows. Even a dummy version would |
409 | | // make no sense because the other POSIX signal functions are missing anyway. |
410 | | |
411 | | |
412 | | static inline int |
413 | | mythread_create(mythread *thread, |
414 | | unsigned int (__stdcall *func)(void *arg), void *arg) |
415 | | { |
416 | | uintptr_t ret = _beginthreadex(NULL, 0, func, arg, 0, NULL); |
417 | | if (ret == 0) |
418 | | return -1; |
419 | | |
420 | | *thread = (HANDLE)ret; |
421 | | return 0; |
422 | | } |
423 | | |
424 | | static inline int |
425 | | mythread_join(mythread thread) |
426 | | { |
427 | | int ret = 0; |
428 | | |
429 | | if (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0) |
430 | | ret = -1; |
431 | | |
432 | | if (!CloseHandle(thread)) |
433 | | ret = -1; |
434 | | |
435 | | return ret; |
436 | | } |
437 | | |
438 | | |
439 | | static inline int |
440 | | mythread_mutex_init(mythread_mutex *mutex) |
441 | | { |
442 | | InitializeCriticalSection(mutex); |
443 | | return 0; |
444 | | } |
445 | | |
446 | | static inline void |
447 | | mythread_mutex_destroy(mythread_mutex *mutex) |
448 | | { |
449 | | DeleteCriticalSection(mutex); |
450 | | } |
451 | | |
452 | | static inline void |
453 | | mythread_mutex_lock(mythread_mutex *mutex) |
454 | | { |
455 | | EnterCriticalSection(mutex); |
456 | | } |
457 | | |
458 | | static inline void |
459 | | mythread_mutex_unlock(mythread_mutex *mutex) |
460 | | { |
461 | | LeaveCriticalSection(mutex); |
462 | | } |
463 | | |
464 | | |
465 | | static inline int |
466 | | mythread_cond_init(mythread_cond *cond) |
467 | | { |
468 | | #ifdef MYTHREAD_WIN95 |
469 | | *cond = CreateEvent(NULL, FALSE, FALSE, NULL); |
470 | | return *cond == NULL ? -1 : 0; |
471 | | #else |
472 | | InitializeConditionVariable(cond); |
473 | | return 0; |
474 | | #endif |
475 | | } |
476 | | |
477 | | static inline void |
478 | | mythread_cond_destroy(mythread_cond *cond) |
479 | | { |
480 | | #ifdef MYTHREAD_WIN95 |
481 | | CloseHandle(*cond); |
482 | | #else |
483 | | (void)cond; |
484 | | #endif |
485 | | } |
486 | | |
487 | | static inline void |
488 | | mythread_cond_signal(mythread_cond *cond) |
489 | | { |
490 | | #ifdef MYTHREAD_WIN95 |
491 | | SetEvent(*cond); |
492 | | #else |
493 | | WakeConditionVariable(cond); |
494 | | #endif |
495 | | } |
496 | | |
497 | | static inline void |
498 | | mythread_cond_wait(mythread_cond *cond, mythread_mutex *mutex) |
499 | | { |
500 | | #ifdef MYTHREAD_WIN95 |
501 | | LeaveCriticalSection(mutex); |
502 | | WaitForSingleObject(*cond, INFINITE); |
503 | | EnterCriticalSection(mutex); |
504 | | #else |
505 | | BOOL ret = SleepConditionVariableCS(cond, mutex, INFINITE); |
506 | | assert(ret); |
507 | | (void)ret; |
508 | | #endif |
509 | | } |
510 | | |
511 | | static inline int |
512 | | mythread_cond_timedwait(mythread_cond *cond, mythread_mutex *mutex, |
513 | | const mythread_condtime *condtime) |
514 | | { |
515 | | #ifdef MYTHREAD_WIN95 |
516 | | LeaveCriticalSection(mutex); |
517 | | #endif |
518 | | |
519 | | DWORD elapsed = GetTickCount() - condtime->start; |
520 | | DWORD timeout = elapsed >= condtime->timeout |
521 | | ? 0 : condtime->timeout - elapsed; |
522 | | |
523 | | #ifdef MYTHREAD_WIN95 |
524 | | DWORD ret = WaitForSingleObject(*cond, timeout); |
525 | | assert(ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT); |
526 | | |
527 | | EnterCriticalSection(mutex); |
528 | | |
529 | | return ret == WAIT_TIMEOUT; |
530 | | #else |
531 | | BOOL ret = SleepConditionVariableCS(cond, mutex, timeout); |
532 | | assert(ret || GetLastError() == ERROR_TIMEOUT); |
533 | | return !ret; |
534 | | #endif |
535 | | } |
536 | | |
537 | | static inline void |
538 | | mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond, |
539 | | uint32_t timeout) |
540 | | { |
541 | | (void)cond; |
542 | | condtime->start = GetTickCount(); |
543 | | condtime->timeout = timeout; |
544 | | } |
545 | | |
546 | | #endif |
547 | | |
548 | | #endif |