summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe ANDRE <jpeg@videolan.org>2014-11-02 15:02:32 +0900
committerJean-Philippe ANDRE <jpeg@videolan.org>2014-11-02 15:14:36 +0900
commitd0bae13693c025293bd2787f15cb22ac99efeb17 (patch)
treec5fb1242e3c0c24e104d1c035d0d5de0cf4ece28
parentadc14650491fc3c20fc95b7e34e54a55fa50c05c (diff)
Eina lock: try to fix compilation for OSX
This is a quick fix. It looks like OSX doesn't provide the same infra as linux for cond_timedwait, but instead they provide directly a relative time wait function. Since I don't have any build / test environment for OSX, this is as far as I can go. Arguably, OSX libc seems to use gettimeofday() for cond_timedwait, so this should close T1701. See the pthread cond implementation: http://www.opensource.apple.com/source/Libc/Libc-167/pthreads.subproj/pthread_cond.c
-rw-r--r--src/lib/eina/eina_inline_lock_posix.x26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/lib/eina/eina_inline_lock_posix.x b/src/lib/eina/eina_inline_lock_posix.x
index 1da4a3d31e..18732f6e03 100644
--- a/src/lib/eina/eina_inline_lock_posix.x
+++ b/src/lib/eina/eina_inline_lock_posix.x
@@ -117,7 +117,9 @@ struct _Eina_Condition
117{ 117{
118 Eina_Lock *lock; /**< The lock for this condition */ 118 Eina_Lock *lock; /**< The lock for this condition */
119 pthread_cond_t condition; /**< The condition variable */ 119 pthread_cond_t condition; /**< The condition variable */
120#if defined(__clockid_t_defined)
120 clockid_t clkid; /**< The attached clock for timedwait */ 121 clockid_t clkid; /**< The attached clock for timedwait */
122#endif
121}; 123};
122 124
123struct _Eina_RWLock 125struct _Eina_RWLock
@@ -346,25 +348,28 @@ eina_condition_new(Eina_Condition *cond, Eina_Lock *mutex)
346 memset(cond, 0, sizeof (Eina_Condition)); 348 memset(cond, 0, sizeof (Eina_Condition));
347#endif 349#endif
348 350
351 cond->lock = mutex;
349 pthread_condattr_init(&attr); 352 pthread_condattr_init(&attr);
350 cond->clkid = (clockid_t) 0;
351 353
354 /* OSX doesn't provide clockid_t or clock_gettime. */
355#if defined(__clockid_t_defined)
356 cond->clkid = (clockid_t) 0;
352 /* We try here to chose the best clock for cond_timedwait */ 357 /* We try here to chose the best clock for cond_timedwait */
353#if defined(CLOCK_MONOTONIC_RAW) 358# if defined(CLOCK_MONOTONIC_RAW)
354 if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC_RAW)) 359 if (!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC_RAW))
355 cond->clkid = CLOCK_MONOTONIC_RAW; 360 cond->clkid = CLOCK_MONOTONIC_RAW;
356#endif 361# endif
357#if defined(CLOCK_MONOTONIC) 362# if defined(CLOCK_MONOTONIC)
358 if (!cond->clkid && !pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) 363 if (!cond->clkid && !pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
359 cond->clkid = CLOCK_MONOTONIC; 364 cond->clkid = CLOCK_MONOTONIC;
360#endif 365# endif
361#if defined(CLOCK_REALTIME) 366# if defined(CLOCK_REALTIME)
362 if (!cond->clkid && !pthread_condattr_setclock(&attr, CLOCK_REALTIME)) 367 if (!cond->clkid && !pthread_condattr_setclock(&attr, CLOCK_REALTIME))
363 cond->clkid = CLOCK_REALTIME; 368 cond->clkid = CLOCK_REALTIME;
369# endif
364#endif 370#endif
365 371
366 cond->lock = mutex; 372 if (pthread_cond_init(&cond->condition, &attr) != 0)
367 if (pthread_cond_init(&cond->condition, cond->clkid ? &attr : NULL) != 0)
368 { 373 {
369 pthread_condattr_destroy(&attr); 374 pthread_condattr_destroy(&attr);
370#ifdef EINA_HAVE_DEBUG_THREADS 375#ifdef EINA_HAVE_DEBUG_THREADS
@@ -434,14 +439,17 @@ eina_condition_timedwait(Eina_Condition *cond, double t)
434 return EINA_FALSE; 439 return EINA_FALSE;
435 } 440 }
436 441
442#if defined(__clockid_t_defined)
437 if (cond->clkid) 443 if (cond->clkid)
438 { 444 {
439 if (clock_gettime(cond->clkid, &ts) != 0) 445 if (clock_gettime(cond->clkid, &ts) != 0)
440 return EINA_FALSE; 446 return EINA_FALSE;
441 } 447 }
442 else 448 else
449#endif
443 { 450 {
444 /* Obsolete - this probably will never happen */ 451 /* Obsolete for Linux.
452 * TODO: use pthread_cond_timedwait_relative_np for OSX. */
445 struct timeval tv; 453 struct timeval tv;
446 if (gettimeofday(&tv, NULL) != 0) 454 if (gettimeofday(&tv, NULL) != 0)
447 return EINA_FALSE; 455 return EINA_FALSE;