summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-11 23:44:36 +0200
committerwm4 <wm4@nowhere>2015-05-11 23:44:36 +0200
commit92b9d75d7256be71d8c8b18438af9494b78f0e96 (patch)
treeeaf114423ce898dc5ac77f5fa48c3f13ef699c41 /osdep
parentca9964a4fb6b1faa0155da43b3c815db0075e2d5 (diff)
downloadmpv-92b9d75d7256be71d8c8b18438af9494b78f0e96.tar.bz2
mpv-92b9d75d7256be71d8c8b18438af9494b78f0e96.tar.xz
threads: use utility+POSIX functions instead of weird wrappers
There is not much of a reason to have these wrappers around. Use POSIX standard functions directly, and use a separate utility function to take care of the timespec calculations. (Course POSIX for using this weird format for time values.)
Diffstat (limited to 'osdep')
-rw-r--r--osdep/threads.c13
-rw-r--r--osdep/threads.h9
-rw-r--r--osdep/timer.c8
-rw-r--r--osdep/timer.h4
4 files changed, 11 insertions, 23 deletions
diff --git a/osdep/threads.c b/osdep/threads.c
index 4f5b39d504..cccce85d1c 100644
--- a/osdep/threads.c
+++ b/osdep/threads.c
@@ -27,19 +27,6 @@
#include "threads.h"
#include "timer.h"
-int mpthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
- int64_t abstime)
-{
- struct timespec ts = mp_time_us_to_timespec(abstime);
- return pthread_cond_timedwait(cond, mutex, &ts);
-}
-
-int mpthread_cond_timedwait_rel(pthread_cond_t *cond, pthread_mutex_t *mutex,
- double s)
-{
- return mpthread_cond_timedwait(cond, mutex, mp_add_timeout(mp_time_us(), s));
-}
-
int mpthread_mutex_init_recursive(pthread_mutex_t *mutex)
{
pthread_mutexattr_t attr;
diff --git a/osdep/threads.h b/osdep/threads.h
index 2277fa65a1..8633618009 100644
--- a/osdep/threads.h
+++ b/osdep/threads.h
@@ -4,15 +4,6 @@
#include <pthread.h>
#include <inttypes.h>
-// Call pthread_cond_timedwait() with an absolute timeout using the same
-// time source/unit as mp_time_us() (microseconds).
-int mpthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
- int64_t abstime);
-
-// Wait by a relative amount of time in seconds.
-int mpthread_cond_timedwait_rel(pthread_cond_t *cond, pthread_mutex_t *mutex,
- double seconds);
-
// Helper to reduce boiler plate.
int mpthread_mutex_init_recursive(pthread_mutex_t *mutex);
diff --git a/osdep/timer.c b/osdep/timer.c
index 643d7cbb9b..053d12dd7c 100644
--- a/osdep/timer.c
+++ b/osdep/timer.c
@@ -116,6 +116,11 @@ struct timespec mp_time_us_to_timespec(int64_t time_us)
return ts;
}
+struct timespec mp_rel_time_to_timespec(double timeout_sec)
+{
+ return mp_time_us_to_timespec(mp_add_timeout(mp_time_us(), timeout_sec));
+}
+
#if 0
#include <stdio.h>
#include "threads.h"
@@ -138,7 +143,8 @@ int main(void) {
#if TEST_SLEEP
mp_sleep_us(delay);
#else
- mpthread_cond_timedwait(&cnd, &mtx, r + delay);
+ struct timespec ts = mp_time_us_to_timespec(r + delay);
+ pthread_cond_timedwait(&cnd, &mtx, &ts);
#endif
j = (mp_time_us() - r) - delay;
printf("sleep time: t=%"PRId64" sleep=%8i err=%5i\n", r, delay, (int)j);
diff --git a/osdep/timer.h b/osdep/timer.h
index 547323943d..427bcc3ccb 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -52,4 +52,8 @@ int64_t mp_add_timeout(int64_t time_us, double timeout_sec);
// Convert the mp time in microseconds to a timespec using CLOCK_REALTIME.
struct timespec mp_time_us_to_timespec(int64_t time_us);
+// Convert the relative timeout in seconds to a timespec.
+// The timespec is absolute, using CLOCK_REALTIME.
+struct timespec mp_rel_time_to_timespec(double timeout_sec);
+
#endif /* MPLAYER_TIMER_H */