Overview
Comment: | threading.h: Add of_condition_timed_wait(). |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e139086f33fc24c6ccb0d7c4b5c23780 |
User & Date: | js on 2013-04-30 22:29:31 |
Other Links: | manifest | tags |
Context
2013-04-30
| ||
22:36 | Add -[OFCondition waitForTimeInterval:]. check-in: 8d7f5db97e user: js tags: trunk | |
22:29 | threading.h: Add of_condition_timed_wait(). check-in: e139086f33 user: js tags: trunk | |
2013-04-28
| ||
20:53 | Tests: Don't call atexit(objc_exit) on Win32. check-in: 371580cd46 user: js tags: trunk | |
Changes
Modified src/threading.h from [49f79a338f] to [165753d14b].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import "objfw-defs.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) # error No threads available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_t of_thread_t; typedef pthread_key_t of_tlskey_t; | > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #import "objfw-defs.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) # error No threads available! #endif #include <math.h> #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_t of_thread_t; typedef pthread_key_t of_tlskey_t; |
︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | of_atomic_inc_int(&condition->count); if (WaitForSingleObject(condition->event, INFINITE) != WAIT_OBJECT_0) { of_mutex_lock(mutex); return false; } of_atomic_dec_int(&condition->count); if (!of_mutex_lock(mutex)) return false; return true; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | of_atomic_inc_int(&condition->count); if (WaitForSingleObject(condition->event, INFINITE) != WAIT_OBJECT_0) { of_mutex_lock(mutex); return false; } of_atomic_dec_int(&condition->count); if (!of_mutex_lock(mutex)) return false; return true; #endif } static OF_INLINE bool of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, double timeout) { #if defined(OF_HAVE_PTHREADS) struct timespec ts; ts.tv_sec = (time_t)timeout; ts.tv_nsec = lrint((timeout - ts.tv_sec) * 1000000000); return !pthread_cond_timedwait(condition, mutex, &ts); #elif defined(_WIN32) if (!of_mutex_unlock(mutex)) return false; of_atomic_inc_int(&condition->count); if (WaitForSingleObject(condition->event, timeout * 1000) != WAIT_OBJECT_0) { of_mutex_lock(mutex); return false; } of_atomic_dec_int(&condition->count); if (!of_mutex_lock(mutex)) return false; return true; |
︙ | ︙ |