mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Fix encoder getting stuck on OS-X
Main thread was stuck looping on pthread_cond_timedwait because the abs time given on OS-X had already passed and the wait returned immediately without releasing the mutex to allow worker threads to proceed. Fix was to use the gettimeofday, which returns real time instead of monotonic, which is what pthread_cond_timedwait wants.
This commit is contained in:
parent
4ceda1908b
commit
d893474bab
|
@ -42,19 +42,16 @@
|
||||||
|
|
||||||
#ifdef __MACH__
|
#ifdef __MACH__
|
||||||
// Workaround Mac OS not having clock_gettime.
|
// Workaround Mac OS not having clock_gettime.
|
||||||
#include <mach/clock.h> // IWYU pragma: export
|
// This needs to work with pthread_cond_timedwait.
|
||||||
#include <mach/mach.h> // IWYU pragma: export
|
# include <sys/time.h>
|
||||||
#define KVZ_GET_TIME(clock_t) { \
|
# define KVZ_GET_TIME(clock_t) { \
|
||||||
clock_serv_t cclock; \
|
struct timeval tv; \
|
||||||
mach_timespec_t mts; \
|
gettimeofday(&tv, NULL); \
|
||||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); \
|
(clock_t)->tv_sec = tv.tv_sec; \
|
||||||
clock_get_time(cclock, &mts); \
|
(clock_t)->tv_nsec = tv.tv_usec * 1000; \
|
||||||
mach_port_deallocate(mach_task_self(), cclock); \
|
}
|
||||||
(clock_t)->tv_sec = mts.tv_sec; \
|
|
||||||
(clock_t)->tv_nsec = mts.tv_nsec; \
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#define KVZ_GET_TIME(clock_t) { clock_gettime(CLOCK_MONOTONIC, (clock_t)); }
|
# define KVZ_GET_TIME(clock_t) { clock_gettime(CLOCK_MONOTONIC, (clock_t)); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KVZ_CLOCK_T_AS_DOUBLE(ts) ((double)((ts).tv_sec) + (double)((ts).tv_nsec) / 1e9)
|
#define KVZ_CLOCK_T_AS_DOUBLE(ts) ((double)((ts).tv_sec) + (double)((ts).tv_nsec) / 1e9)
|
||||||
|
|
Loading…
Reference in a new issue