summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-31 19:50:25 +0100
committerwm4 <wm4@nowhere>2014-01-31 19:50:25 +0100
commita17be5576fae918c683688a0e2bd2fd21b32d428 (patch)
treec46ceb404511ce0fbceadae24e85420bb7667321
parent2305ffcaba2b762825cc18cb35cec06c203e3821 (diff)
downloadmpv-a17be5576fae918c683688a0e2bd2fd21b32d428.tar.bz2
mpv-a17be5576fae918c683688a0e2bd2fd21b32d428.tar.xz
threads: add wrapper for initializing recursive mutexes
Damn this overly verbose pthread API.
-rw-r--r--input/input.c7
-rw-r--r--osdep/threads.c11
-rw-r--r--osdep/threads.h2
-rw-r--r--sub/dec_sub.c7
4 files changed, 17 insertions, 10 deletions
diff --git a/input/input.c b/input/input.c
index 42b45b842f..d4905112dc 100644
--- a/input/input.c
+++ b/input/input.c
@@ -41,6 +41,7 @@
#include "keycodes.h"
#include "cmd_list.h"
#include "cmd_parse.h"
+#include "osdep/threads.h"
#include "osdep/timer.h"
#include "common/msg.h"
#include "common/global.h"
@@ -1474,11 +1475,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
.wakeup_pipe = {-1, -1},
};
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&ictx->mutex, &attr);
- pthread_mutexattr_destroy(&attr);
+ mpthread_mutex_init_recursive(&ictx->mutex);
// Setup default section, so that it does nothing.
mp_input_enable_section(ictx, NULL, MP_INPUT_ALLOW_VO_DRAGGING |
diff --git a/osdep/threads.c b/osdep/threads.c
index ac6dfbb0f0..0c31ffa40a 100644
--- a/osdep/threads.c
+++ b/osdep/threads.c
@@ -55,3 +55,14 @@ int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
timespec_add_seconds(&ts, timeout);
return pthread_cond_timedwait(cond, mutex, &ts);
}
+
+// Helper to reduce boiler plate.
+int mpthread_mutex_init_recursive(pthread_mutex_t *mutex)
+{
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ int r = pthread_mutex_init(mutex, &attr);
+ pthread_mutexattr_destroy(&attr);
+ return r;
+}
diff --git a/osdep/threads.h b/osdep/threads.h
index 7c9f041320..662f718f8c 100644
--- a/osdep/threads.h
+++ b/osdep/threads.h
@@ -6,4 +6,6 @@
int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
double timeout);
+int mpthread_mutex_init_recursive(pthread_mutex_t *mutex);
+
#endif
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index 64d285f568..46c5b3fafb 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -31,6 +31,7 @@
#include "common/global.h"
#include "common/msg.h"
#include "misc/charset_conv.h"
+#include "osdep/threads.h"
extern const struct sd_functions sd_ass;
extern const struct sd_functions sd_lavc;
@@ -96,11 +97,7 @@ struct dec_sub *sub_create(struct mpv_global *global)
sub->log = mp_log_new(sub, global->log, "sub");
sub->opts = global->opts;
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&sub->lock, &attr);
- pthread_mutexattr_destroy(&attr);
+ mpthread_mutex_init_recursive(&sub->lock);
return sub;
}