mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 03:52:22 +02:00
threads: add wrapper for initializing recursive mutexes
Damn this overly verbose pthread API.
This commit is contained in:
parent
2305ffcaba
commit
a17be5576f
@ -41,6 +41,7 @@
|
|||||||
#include "keycodes.h"
|
#include "keycodes.h"
|
||||||
#include "cmd_list.h"
|
#include "cmd_list.h"
|
||||||
#include "cmd_parse.h"
|
#include "cmd_parse.h"
|
||||||
|
#include "osdep/threads.h"
|
||||||
#include "osdep/timer.h"
|
#include "osdep/timer.h"
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
#include "common/global.h"
|
#include "common/global.h"
|
||||||
@ -1474,11 +1475,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
|||||||
.wakeup_pipe = {-1, -1},
|
.wakeup_pipe = {-1, -1},
|
||||||
};
|
};
|
||||||
|
|
||||||
pthread_mutexattr_t attr;
|
mpthread_mutex_init_recursive(&ictx->mutex);
|
||||||
pthread_mutexattr_init(&attr);
|
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
pthread_mutex_init(&ictx->mutex, &attr);
|
|
||||||
pthread_mutexattr_destroy(&attr);
|
|
||||||
|
|
||||||
// Setup default section, so that it does nothing.
|
// Setup default section, so that it does nothing.
|
||||||
mp_input_enable_section(ictx, NULL, MP_INPUT_ALLOW_VO_DRAGGING |
|
mp_input_enable_section(ictx, NULL, MP_INPUT_ALLOW_VO_DRAGGING |
|
||||||
|
@ -55,3 +55,14 @@ int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|||||||
timespec_add_seconds(&ts, timeout);
|
timespec_add_seconds(&ts, timeout);
|
||||||
return pthread_cond_timedwait(cond, mutex, &ts);
|
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;
|
||||||
|
}
|
||||||
|
@ -6,4 +6,6 @@
|
|||||||
int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
int mpthread_cond_timed_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||||
double timeout);
|
double timeout);
|
||||||
|
|
||||||
|
int mpthread_mutex_init_recursive(pthread_mutex_t *mutex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "common/global.h"
|
#include "common/global.h"
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
#include "misc/charset_conv.h"
|
#include "misc/charset_conv.h"
|
||||||
|
#include "osdep/threads.h"
|
||||||
|
|
||||||
extern const struct sd_functions sd_ass;
|
extern const struct sd_functions sd_ass;
|
||||||
extern const struct sd_functions sd_lavc;
|
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->log = mp_log_new(sub, global->log, "sub");
|
||||||
sub->opts = global->opts;
|
sub->opts = global->opts;
|
||||||
|
|
||||||
pthread_mutexattr_t attr;
|
mpthread_mutex_init_recursive(&sub->lock);
|
||||||
pthread_mutexattr_init(&attr);
|
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
pthread_mutex_init(&sub->lock, &attr);
|
|
||||||
pthread_mutexattr_destroy(&attr);
|
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user