X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fposix%2Fos-threads.h;h=e5f935cf64ac9d24ff0c7637b53725755671c417;hb=ecc633c51b6c69bebaff4932e90245665ca06373;hp=5216ffe7793ac40bea9c28bf93ffbb6e7cba986b;hpb=960f33c651b2dd1e6331dafe5b21705c11cee1a2;p=deb_libcec.git diff --git a/src/lib/platform/posix/os-threads.h b/src/lib/platform/posix/os-threads.h index 5216ffe..e5f935c 100644 --- a/src/lib/platform/posix/os-threads.h +++ b/src/lib/platform/posix/os-threads.h @@ -48,19 +48,26 @@ namespace PLATFORM inline struct timespec GetAbsTime(uint64_t iIncreaseBy = 0) { - struct timespec abstime; - struct timeval now; - gettimeofday(&now, NULL); - iIncreaseBy += now.tv_usec / 1000; - abstime.tv_sec = now.tv_sec + (time_t)(iIncreaseBy / 1000); - abstime.tv_nsec = (int32_t)((iIncreaseBy % (uint32_t)1000) * (uint32_t)1000000); - return abstime; + struct timespec now; + #ifdef __APPLE__ + struct timeval tv; + gettimeofday(&tv, NULL); + now.tv_sec = tv.tv_sec; + now.tv_nsec = tv.tv_usec * 1000; + #else + clock_gettime(CLOCK_REALTIME, &now); + #endif + now.tv_nsec += iIncreaseBy % 1000 * 1000000; + now.tv_sec += iIncreaseBy / 1000 + now.tv_nsec / 1000000000; + now.tv_nsec %= 1000000000; + return now; } typedef pthread_t thread_t; + #define INVALID_THREAD_VALUE 0 #define ThreadsCreate(thread, func, arg) (pthread_create(&thread, NULL, (void *(*) (void *))func, (void *)arg) == 0) - #define ThreadsWait(thread, retval) (pthread_join(thread, retval) == 0) + #define ThreadsWait(thread, retval) (thread ? pthread_join(thread, retval) == 0 : true) typedef pthread_mutex_t mutex_t; #define MutexCreate(mutex) pthread_mutex_init(&mutex, GetRecursiveMutexAttribute());