summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
Diffstat (limited to 'player')
-rw-r--r--player/client.c208
-rw-r--r--player/command.c11
-rw-r--r--player/core.h10
-rw-r--r--player/loadfile.c22
-rw-r--r--player/main.c13
-rw-r--r--player/scripting.c13
6 files changed, 137 insertions, 140 deletions
diff --git a/player/client.c b/player/client.c
index 68cc055597..f78a4e7210 100644
--- a/player/client.c
+++ b/player/client.c
@@ -64,7 +64,7 @@
struct mp_client_api {
struct MPContext *mpctx;
- pthread_mutex_t lock;
+ mp_mutex lock;
// -- protected by lock
@@ -118,10 +118,10 @@ struct mpv_handle {
struct mpv_event_property cur_property_event;
struct observe_property *cur_property;
- pthread_mutex_t lock;
+ mp_mutex lock;
- pthread_mutex_t wakeup_lock;
- pthread_cond_t wakeup;
+ mp_mutex wakeup_lock;
+ mp_cond wakeup;
// -- protected by wakeup_lock
bool need_wakeup;
@@ -185,7 +185,7 @@ void mp_clients_init(struct MPContext *mpctx)
.mpctx = mpctx,
};
mpctx->global->client_api = mpctx->clients;
- pthread_mutex_init(&mpctx->clients->lock, NULL);
+ mp_mutex_init(&mpctx->clients->lock);
}
void mp_clients_destroy(struct MPContext *mpctx)
@@ -201,7 +201,7 @@ void mp_clients_destroy(struct MPContext *mpctx)
abort();
}
- pthread_mutex_destroy(&mpctx->clients->lock);
+ mp_mutex_destroy(&mpctx->clients->lock);
talloc_free(mpctx->clients);
mpctx->clients = NULL;
}
@@ -211,14 +211,14 @@ void mp_clients_destroy(struct MPContext *mpctx)
bool mp_clients_all_initialized(struct MPContext *mpctx)
{
bool all_ok = true;
- pthread_mutex_lock(&mpctx->clients->lock);
+ mp_mutex_lock(&mpctx->clients->lock);
for (int n = 0; n < mpctx->clients->num_clients; n++) {
struct mpv_handle *ctx = mpctx->clients->clients[n];
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
all_ok &= ctx->fuzzy_initialized;
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
}
- pthread_mutex_unlock(&mpctx->clients->lock);
+ mp_mutex_unlock(&mpctx->clients->lock);
return all_ok;
}
@@ -253,15 +253,15 @@ static struct mpv_handle *find_client(struct mp_client_api *clients,
bool mp_client_id_exists(struct MPContext *mpctx, int64_t id)
{
- pthread_mutex_lock(&mpctx->clients->lock);
+ mp_mutex_lock(&mpctx->clients->lock);
bool r = find_client_id(mpctx->clients, id);
- pthread_mutex_unlock(&mpctx->clients->lock);
+ mp_mutex_unlock(&mpctx->clients->lock);
return r;
}
struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name)
{
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
char nname[MAX_CLIENT_NAME];
for (int n = 1; n < 1000; n++) {
@@ -278,7 +278,7 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
}
if (!nname[0] || clients->shutting_down) {
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
return NULL;
}
@@ -296,9 +296,9 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
.event_mask = (1ULL << INTERNAL_EVENT_BASE) - 1, // exclude internal events
.wakeup_pipe = {-1, -1},
};
- pthread_mutex_init(&client->lock, NULL);
- pthread_mutex_init(&client->wakeup_lock, NULL);
- pthread_cond_init(&client->wakeup, NULL);
+ mp_mutex_init(&client->lock);
+ mp_mutex_init(&client->wakeup_lock);
+ mp_cond_init(&client->wakeup);
snprintf(client->name, sizeof(client->name), "%s", nname);
@@ -308,7 +308,7 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
if (clients->num_clients == 1 && !clients->mpctx->is_cli)
client->fuzzy_initialized = true;
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
mpv_request_event(client, MPV_EVENT_TICK, 0);
@@ -317,9 +317,9 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
void mp_client_set_weak(struct mpv_handle *ctx)
{
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
ctx->is_weak = true;
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
}
const char *mpv_client_name(mpv_handle *ctx)
@@ -344,43 +344,41 @@ struct mpv_global *mp_client_get_global(struct mpv_handle *ctx)
static void wakeup_client(struct mpv_handle *ctx)
{
- pthread_mutex_lock(&ctx->wakeup_lock);
+ mp_mutex_lock(&ctx->wakeup_lock);
if (!ctx->need_wakeup) {
ctx->need_wakeup = true;
- pthread_cond_broadcast(&ctx->wakeup);
+ mp_cond_broadcast(&ctx->wakeup);
if (ctx->wakeup_cb)
ctx->wakeup_cb(ctx->wakeup_cb_ctx);
if (ctx->wakeup_pipe[0] != -1)
(void)write(ctx->wakeup_pipe[1], &(char){0}, 1);
}
- pthread_mutex_unlock(&ctx->wakeup_lock);
+ mp_mutex_unlock(&ctx->wakeup_lock);
}
// Note: the caller has to deal with sporadic wakeups.
static int wait_wakeup(struct mpv_handle *ctx, int64_t end)
{
int r = 0;
- pthread_mutex_unlock(&ctx->lock);
- pthread_mutex_lock(&ctx->wakeup_lock);
- if (!ctx->need_wakeup) {
- struct timespec ts = mp_time_ns_to_realtime(end);
- r = pthread_cond_timedwait(&ctx->wakeup, &ctx->wakeup_lock, &ts);
- }
+ mp_mutex_unlock(&ctx->lock);
+ mp_mutex_lock(&ctx->wakeup_lock);
+ if (!ctx->need_wakeup)
+ r = mp_cond_timedwait_until(&ctx->wakeup, &ctx->wakeup_lock, end);
if (r == 0)
ctx->need_wakeup = false;
- pthread_mutex_unlock(&ctx->wakeup_lock);
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_unlock(&ctx->wakeup_lock);
+ mp_mutex_lock(&ctx->lock);
return r;
}
void mpv_set_wakeup_callback(mpv_handle *ctx, void (*cb)(void *d), void *d)
{
- pthread_mutex_lock(&ctx->wakeup_lock);
+ mp_mutex_lock(&ctx->wakeup_lock);
ctx->wakeup_cb = cb;
ctx->wakeup_cb_ctx = d;
if (ctx->wakeup_cb)
ctx->wakeup_cb(ctx->wakeup_cb_ctx);
- pthread_mutex_unlock(&ctx->wakeup_lock);
+ mp_mutex_unlock(&ctx->wakeup_lock);
}
static void lock_core(mpv_handle *ctx)
@@ -395,10 +393,10 @@ static void unlock_core(mpv_handle *ctx)
void mpv_wait_async_requests(mpv_handle *ctx)
{
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
while (ctx->reserved_events || ctx->async_counter)
wait_wakeup(ctx, INT64_MAX);
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
}
// Send abort signal to all matching work items.
@@ -407,7 +405,7 @@ void mpv_wait_async_requests(mpv_handle *ctx)
static void abort_async(struct MPContext *mpctx, mpv_handle *ctx,
int type, uint64_t id)
{
- pthread_mutex_lock(&mpctx->abort_lock);
+ mp_mutex_lock(&mpctx->abort_lock);
// Destroy all => ensure any newly appearing work is aborted immediately.
if (ctx == NULL)
@@ -422,12 +420,12 @@ static void abort_async(struct MPContext *mpctx, mpv_handle *ctx,
}
}
- pthread_mutex_unlock(&mpctx->abort_lock);
+ mp_mutex_unlock(&mpctx->abort_lock);
}
static void get_thread(void *ptr)
{
- *(pthread_t *)ptr = pthread_self();
+ *(mp_thread *)ptr = mp_thread_self();
}
static void mp_destroy_client(mpv_handle *ctx, bool terminate)
@@ -443,7 +441,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
if (terminate)
mpv_command(ctx, (const char*[]){"quit", NULL});
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
ctx->destroying = true;
@@ -455,7 +453,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
prop_unref(ctx->cur_property);
ctx->cur_property = NULL;
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
abort_async(mpctx, ctx, 0, 0);
@@ -467,7 +465,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
osd_set_external_remove_owner(mpctx->osd, ctx);
mp_input_remove_sections_by_owner(mpctx->input, ctx->name);
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
for (int n = 0; n < clients->num_clients; n++) {
if (clients->clients[n] == ctx) {
@@ -479,9 +477,9 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
ctx->num_events--;
}
mp_msg_log_buffer_destroy(ctx->messages);
- pthread_cond_destroy(&ctx->wakeup);
- pthread_mutex_destroy(&ctx->wakeup_lock);
- pthread_mutex_destroy(&ctx->lock);
+ mp_cond_destroy(&ctx->wakeup);
+ mp_mutex_destroy(&ctx->wakeup_lock);
+ mp_mutex_destroy(&ctx->lock);
if (ctx->wakeup_pipe[0] != -1) {
close(ctx->wakeup_pipe[0]);
close(ctx->wakeup_pipe[1]);
@@ -513,7 +511,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
// mp_hook_test_completion() also relies on this a bit.
mp_wakeup_core(mpctx);
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
// Note that even if num_clients==0, having set have_terminator keeps mpctx
// and the core thread alive.
@@ -524,17 +522,17 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
mpctx->stop_play = PT_QUIT;
mp_dispatch_unlock(mpctx->dispatch);
- pthread_t playthread;
+ mp_thread playthread;
mp_dispatch_run(mpctx->dispatch, get_thread, &playthread);
// Ask the core thread to stop.
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
clients->terminate_core_thread = true;
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
mp_wakeup_core(mpctx);
// Blocking wait for all clients and core thread to terminate.
- pthread_join(playthread, NULL);
+ mp_thread_join(playthread);
mp_destroy(mpctx);
}
@@ -559,7 +557,7 @@ void mp_shutdown_clients(struct MPContext *mpctx)
// Forcefully abort async work after 2 seconds of waiting.
double abort_time = mp_time_sec() + 2;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
// Prevent that new clients can appear.
clients->shutting_down = true;
@@ -568,7 +566,7 @@ void mp_shutdown_clients(struct MPContext *mpctx)
while (clients->num_clients || mpctx->outstanding_async ||
!(mpctx->is_cli || clients->terminate_core_thread))
{
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
double left = abort_time - mp_time_sec();
if (left >= 0) {
@@ -583,26 +581,26 @@ void mp_shutdown_clients(struct MPContext *mpctx)
mp_client_broadcast_event(mpctx, MPV_EVENT_SHUTDOWN, NULL);
mp_wait_events(mpctx);
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
}
bool mp_is_shutting_down(struct MPContext *mpctx)
{
struct mp_client_api *clients = mpctx->clients;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
bool res = clients->shutting_down;
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
return res;
}
-static void *core_thread(void *p)
+static MP_THREAD_VOID core_thread(void *p)
{
struct MPContext *mpctx = p;
- mpthread_set_name("core");
+ mp_thread_set_name("core");
while (!mpctx->initialized && mpctx->stop_play != PT_QUIT)
mp_idle(mpctx);
@@ -615,7 +613,7 @@ static void *core_thread(void *p)
// the last mpv_handle.
mp_shutdown_clients(mpctx);
- return NULL;
+ MP_THREAD_RETURN();
}
mpv_handle *mpv_create(void)
@@ -632,8 +630,8 @@ mpv_handle *mpv_create(void)
return NULL;
}
- pthread_t thread;
- if (pthread_create(&thread, NULL, core_thread, mpctx) != 0) {
+ mp_thread thread;
+ if (mp_thread_create(&thread, core_thread, mpctx) != 0) {
ctx->clients->have_terminator = true; // avoid blocking
mpv_terminate_destroy(ctx);
mp_destroy(mpctx);
@@ -706,13 +704,13 @@ static void dup_event_data(struct mpv_event *ev)
static int reserve_reply(struct mpv_handle *ctx)
{
int res = MPV_ERROR_EVENT_QUEUE_FULL;
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
if (ctx->reserved_events + ctx->num_events < ctx->max_events && !ctx->choked)
{
ctx->reserved_events++;
res = 0;
}
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return res;
}
@@ -732,7 +730,7 @@ static int append_event(struct mpv_handle *ctx, struct mpv_event event, bool cop
static int send_event(struct mpv_handle *ctx, struct mpv_event *event, bool copy)
{
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
uint64_t mask = 1ULL << event->event_id;
if (ctx->property_event_masks & mask)
notify_property_events(ctx, event->event_id);
@@ -748,7 +746,7 @@ static int send_event(struct mpv_handle *ctx, struct mpv_event *event, bool copy
ctx->choked = true;
}
}
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return r;
}
@@ -758,20 +756,20 @@ static void send_reply(struct mpv_handle *ctx, uint64_t userdata,
struct mpv_event *event)
{
event->reply_userdata = userdata;
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
// If this fails, reserve_reply() probably wasn't called.
assert(ctx->reserved_events > 0);
ctx->reserved_events--;
if (append_event(ctx, *event, false) < 0)
MP_ASSERT_UNREACHABLE();
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
}
void mp_client_broadcast_event(struct MPContext *mpctx, int event, void *data)
{
struct mp_client_api *clients = mpctx->clients;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
for (int n = 0; n < clients->num_clients; n++) {
struct mpv_event event_data = {
@@ -781,7 +779,7 @@ void mp_client_broadcast_event(struct MPContext *mpctx, int event, void *data)
send_event(clients->clients[n], &event_data, true);
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
}
// Like mp_client_broadcast_event(), but can be called from any thread.
@@ -814,7 +812,7 @@ int mp_client_send_event(struct MPContext *mpctx, const char *client_name,
.reply_userdata = reply_userdata,
};
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
struct mpv_handle *ctx = find_client(clients, client_name);
if (ctx) {
@@ -824,7 +822,7 @@ int mp_client_send_event(struct MPContext *mpctx, const char *client_name,
talloc_free(data);
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
return r;
}
@@ -858,7 +856,7 @@ int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable)
if (event == MPV_EVENT_SHUTDOWN && !enable)
return MPV_ERROR_INVALID_PARAMETER;
assert(event < (int)INTERNAL_EVENT_BASE); // excluded above; they have no name
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
uint64_t bit = 1ULL << event;
ctx->event_mask = enable ? ctx->event_mask | bit : ctx->event_mask & ~bit;
if (enable && event < MP_ARRAY_SIZE(deprecated_events) &&
@@ -867,7 +865,7 @@ int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable)
MP_WARN(ctx, "The '%s' event is deprecated and will be removed.\n",
mpv_event_name(event));
}
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return 0;
}
@@ -896,7 +894,7 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
{
mpv_event *event = ctx->cur_event;
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
if (!ctx->fuzzy_initialized)
mp_wakeup_core(ctx->clients->mpctx);
@@ -954,17 +952,17 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
}
ctx->queued_wakeup = false;
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return event;
}
void mpv_wakeup(mpv_handle *ctx)
{
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
ctx->queued_wakeup = true;
wakeup_client(ctx);
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
}
// map client API types to internal types
@@ -1546,7 +1544,7 @@ int mpv_observe_property(mpv_handle *ctx, uint64_t userdata,
if (format == MPV_FORMAT_OSD_STRING)
return MPV_ERROR_PROPERTY_FORMAT;
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
assert(!ctx->destroying);
struct observe_property *prop = talloc_ptrtype(ctx, prop);
talloc_set_destructor(prop, property_free);
@@ -1569,14 +1567,14 @@ int mpv_observe_property(mpv_handle *ctx, uint64_t userdata,
ctx->new_property_events = true;
ctx->cur_property_index = 0;
ctx->has_pending_properties = true;
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
mp_wakeup_core(ctx->mpctx);
return 0;
}
int mpv_unobserve_property(mpv_handle *ctx, uint64_t userdata)
{
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
int count = 0;
for (int n = ctx->num_properties - 1; n >= 0; n--) {
struct observe_property *prop = ctx->properties[n];
@@ -1590,7 +1588,7 @@ int mpv_unobserve_property(mpv_handle *ctx, uint64_t userdata)
count++;
}
}
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return count;
}
@@ -1625,11 +1623,11 @@ void mp_client_property_change(struct MPContext *mpctx, const char *name)
int id = mp_get_property_id(mpctx, name);
bool any_pending = false;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
for (int n = 0; n < clients->num_clients; n++) {
struct mpv_handle *client = clients->clients[n];
- pthread_mutex_lock(&client->lock);
+ mp_mutex_lock(&client->lock);
for (int i = 0; i < client->num_properties; i++) {
if (client->properties[i]->id == id &&
property_shared_prefix(name, client->properties[i]->name)) {
@@ -1638,10 +1636,10 @@ void mp_client_property_change(struct MPContext *mpctx, const char *name)
any_pending = true;
}
}
- pthread_mutex_unlock(&client->lock);
+ mp_mutex_unlock(&client->lock);
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
// If we're inside mp_dispatch_queue_process(), this will cause the playloop
// to be re-run (to get mp_client_send_property_changes() called). If we're
@@ -1698,9 +1696,9 @@ static void send_client_property_changes(struct mpv_handle *ctx)
// or similar things are involved).
prop->refcount += 1; // keep prop alive (esp. prop->name)
ctx->async_counter += 1; // keep ctx alive
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
getproperty_fn(&req);
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
ctx->async_counter -= 1;
prop_unref(prop);
@@ -1757,22 +1755,22 @@ void mp_client_send_property_changes(struct MPContext *mpctx)
{
struct mp_client_api *clients = mpctx->clients;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
uint64_t cur_ts = clients->clients_list_change_ts;
for (int n = 0; n < clients->num_clients; n++) {
struct mpv_handle *ctx = clients->clients[n];
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
if (!ctx->has_pending_properties || ctx->destroying) {
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
continue;
}
// Keep ctx->lock locked (unlock order does not matter).
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
send_client_property_changes(ctx);
- pthread_mutex_unlock(&ctx->lock);
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_unlock(&ctx->lock);
+ mp_mutex_lock(&clients->lock);
if (cur_ts != clients->clients_list_change_ts) {
// List changed; need to start over. Do it in the next iteration.
mp_wakeup_core(mpctx);
@@ -1780,7 +1778,7 @@ void mp_client_send_property_changes(struct MPContext *mpctx)
}
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
}
// Set ctx->cur_event to a generated property change event, if there is any
@@ -1887,7 +1885,7 @@ int mpv_request_log_messages(mpv_handle *ctx, const char *min_level)
if (level < 0 && strcmp(min_level, "no") != 0)
return MPV_ERROR_INVALID_PARAMETER;
- pthread_mutex_lock(&ctx->lock);
+ mp_mutex_lock(&ctx->lock);
if (level < 0 || level != ctx->messages_level) {
mp_msg_log_buffer_destroy(ctx->messages);
ctx->messages = NULL;
@@ -1902,7 +1900,7 @@ int mpv_request_log_messages(mpv_handle *ctx, const char *min_level)
mp_msg_log_buffer_set_silent(ctx->messages, silent);
}
wakeup_client(ctx);
- pthread_mutex_unlock(&ctx->lock);
+ mp_mutex_unlock(&ctx->lock);
return 0;
}
@@ -1934,13 +1932,13 @@ static bool gen_log_message_event(struct mpv_handle *ctx)
int mpv_get_wakeup_pipe(mpv_handle *ctx)
{
- pthread_mutex_lock(&ctx->wakeup_lock);
+ mp_mutex_lock(&ctx->wakeup_lock);
if (ctx->wakeup_pipe[0] == -1) {
if (mp_make_wakeup_pipe(ctx->wakeup_pipe) >= 0)
(void)write(ctx->wakeup_pipe[1], &(char){0}, 1);
}
int fd = ctx->wakeup_pipe[0];
- pthread_mutex_unlock(&ctx->wakeup_lock);
+ mp_mutex_unlock(&ctx->wakeup_lock);
return fd;
}
@@ -2168,14 +2166,14 @@ bool mp_set_main_render_context(struct mp_client_api *client_api,
{
assert(ctx);
- pthread_mutex_lock(&client_api->lock);
+ mp_mutex_lock(&client_api->lock);
bool is_set = !!client_api->render_context;
bool is_same = client_api->render_context == ctx;
// Can set if it doesn't remove another existing ctx.
bool res = is_same || !is_set;
if (res)
client_api->render_context = active ? ctx : NULL;
- pthread_mutex_unlock(&client_api->lock);
+ mp_mutex_unlock(&client_api->lock);
return res;
}
@@ -2184,10 +2182,10 @@ struct mpv_render_context *
mp_client_api_acquire_render_context(struct mp_client_api *ca)
{
struct mpv_render_context *res = NULL;
- pthread_mutex_lock(&ca->lock);
+ mp_mutex_lock(&ca->lock);
if (ca->render_context && mp_render_context_acquire(ca->render_context))
res = ca->render_context;
- pthread_mutex_unlock(&ca->lock);
+ mp_mutex_unlock(&ca->lock);
return res;
}
@@ -2207,7 +2205,7 @@ int mpv_stream_cb_add_ro(mpv_handle *ctx, const char *protocol, void *user_data,
struct mp_client_api *clients = ctx->clients;
int r = 0;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
for (int n = 0; n < clients->num_custom_protocols; n++) {
struct mp_custom_protocol *proto = &clients->custom_protocols[n];
if (strcmp(proto->protocol, protocol) == 0) {
@@ -2226,7 +2224,7 @@ int mpv_stream_cb_add_ro(mpv_handle *ctx, const char *protocol, void *user_data,
MP_TARRAY_APPEND(clients, clients->custom_protocols,
clients->num_custom_protocols, proto);
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
return r;
}
@@ -2235,7 +2233,7 @@ bool mp_streamcb_lookup(struct mpv_global *g, const char *protocol,
{
struct mp_client_api *clients = g->client_api;
bool found = false;
- pthread_mutex_lock(&clients->lock);
+ mp_mutex_lock(&clients->lock);
for (int n = 0; n < clients->num_custom_protocols; n++) {
struct mp_custom_protocol *proto = &clients->custom_protocols[n];
if (strcmp(proto->protocol, protocol) == 0) {
@@ -2245,6 +2243,6 @@ bool mp_streamcb_lookup(struct mpv_global *g, const char *protocol,
break;
}
}
- pthread_mutex_unlock(&clients->lock);
+ mp_mutex_unlock(&clients->lock);
return found;
}
diff --git a/player/command.c b/player/command.c
index 69adf16bd0..69eed884e1 100644
--- a/player/command.c
+++ b/player/command.c
@@ -41,6 +41,7 @@
#include "common/stats.h"
#include "filters/f_decoder_wrapper.h"
#include "command.h"
+#include "osdep/threads.h"
#include "osdep/timer.h"
#include "common/common.h"
#include "input/input.h"
@@ -4847,7 +4848,7 @@ struct cmd_list_ctx {
struct mp_cmd_ctx *parent;
bool current_valid;
- pthread_t current;
+ mp_thread current;
bool completed_recursive;
// list of sub commands yet to run
@@ -4861,7 +4862,7 @@ static void on_cmd_list_sub_completion(struct mp_cmd_ctx *cmd)
{
struct cmd_list_ctx *list = cmd->on_completion_priv;
- if (list->current_valid && pthread_equal(list->current, pthread_self())) {
+ if (list->current_valid && mp_thread_equal(list->current, mp_thread_self())) {
list->completed_recursive = true;
} else {
continue_cmd_list(list);
@@ -4884,7 +4885,7 @@ static void continue_cmd_list(struct cmd_list_ctx *list)
list->completed_recursive = false;
list->current_valid = true;
- list->current = pthread_self();
+ list->current = mp_thread_self();
run_command(list->mpctx, sub, NULL, on_cmd_list_sub_completion, list);
@@ -5882,10 +5883,10 @@ static void cmd_subprocess(void *p)
fdctx[1].capture = cmd->args[3].v.b;
fdctx[2].capture = cmd->args[4].v.b;
- pthread_mutex_lock(&mpctx->abort_lock);
+ mp_mutex_lock(&mpctx->abort_lock);
cmd->abort->coupled_to_playback = playback_only;
mp_abort_recheck_locked(mpctx, cmd->abort);
- pthread_mutex_unlock(&mpctx->abort_lock);
+ mp_mutex_unlock(&mpctx->abort_lock);
mp_core_unlock(mpctx);
diff --git a/player/core.h b/player/core.h
index 70692a0c86..8a49585cdf 100644
--- a/player/core.h
+++ b/player/core.h
@@ -18,18 +18,18 @@
#ifndef MPLAYER_MP_CORE_H
#define MPLAYER_MP_CORE_H
-#include <pthread.h>
#include <stdatomic.h>
#include <stdbool.h>
#include "libmpv/client.h"
+#include "audio/aframe.h"
#include "common/common.h"
-#include "filters/filter.h"
#include "filters/f_output_chain.h"
+#include "filters/filter.h"
#include "options/options.h"
+#include "osdep/threads.h"
#include "sub/osd.h"
-#include "audio/aframe.h"
#include "video/mp_image.h"
#include "video/out/vo.h"
@@ -430,7 +430,7 @@ typedef struct MPContext {
int64_t builtin_script_ids[5];
- pthread_mutex_t abort_lock;
+ mp_mutex abort_lock;
// --- The following fields are protected by abort_lock
struct mp_abort_entry **abort_list;
@@ -438,7 +438,7 @@ typedef struct MPContext {
bool abort_all; // during final termination
// --- Owned by MPContext
- pthread_t open_thread;
+ mp_thread open_thread;
bool open_active; // open_thread is a valid thread handle, all setup
atomic_bool open_done;
// --- All fields below are immutable while open_active is true.
diff --git a/player/loadfile.c b/player/loadfile.c
index 2efdf81e43..206c0cd208 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -74,7 +74,7 @@ void mp_abort_playback_async(struct MPContext *mpctx)
{
mp_cancel_trigger(mpctx->playback_abort);
- pthread_mutex_lock(&mpctx->abort_lock);
+ mp_mutex_lock(&mpctx->abort_lock);
for (int n = 0; n < mpctx->num_abort_list; n++) {
struct mp_abort_entry *abort = mpctx->abort_list[n];
@@ -82,25 +82,25 @@ void mp_abort_playback_async(struct MPContext *mpctx)
mp_abort_trigger_locked(mpctx, abort);
}
- pthread_mutex_unlock(&mpctx->abort_lock);
+ mp_mutex_unlock(&mpctx->abort_lock);
}
// Add it to the global list, and allocate required data structures.
void mp_abort_add(struct MPContext *mpctx, struct mp_abort_entry *abort)
{
- pthread_mutex_lock(&mpctx->abort_lock);
+ mp_mutex_lock(&mpctx->abort_lock);
assert(!abort->cancel);
abort->cancel = mp_cancel_new(NULL);
MP_TARRAY_APPEND(NULL, mpctx->abort_list, mpctx->num_abort_list, abort);
mp_abort_recheck_locked(mpctx, abort);
- pthread_mutex_unlock(&mpctx->abort_lock);
+ mp_mutex_unlock(&mpctx->abort_lock);
}
// Remove Add it to the global list, and free/clear required data structures.
// Does not deallocate the abort value itself.
void mp_abort_remove(struct MPContext *mpctx, struct mp_abort_entry *abort)
{
- pthread_mutex_lock(&mpctx->abort_lock);
+ mp_mutex_lock(&mpctx->abort_lock);
for (int n = 0; n < mpctx->num_abort_list; n++) {
if (mpctx->abort_list[n] == abort) {
MP_TARRAY_REMOVE_AT(mpctx->abort_list, mpctx->num_abort_list, n);
@@ -110,7 +110,7 @@ void mp_abort_remove(struct MPContext *mpctx, struct mp_abort_entry *abort)
}
}
assert(!abort); // should have been in the list
- pthread_mutex_unlock(&mpctx->abort_lock);
+ mp_mutex_unlock(&mpctx->abort_lock);
}
// Verify whether the abort needs to be signaled after changing certain fields
@@ -1155,11 +1155,11 @@ static void load_per_file_options(m_config_t *conf,
}
}
-static void *open_demux_thread(void *ctx)
+static MP_THREAD_VOID open_demux_thread(void *ctx)
{
struct MPContext *mpctx = ctx;
- mpthread_set_name("opener");
+ mp_thread_set_name("opener");
struct demuxer_params p = {
.force_format = mpctx->open_format,
@@ -1197,7 +1197,7 @@ static void *open_demux_thread(void *ctx)
atomic_store(&mpctx->open_done, true);
mp_wakeup_core(mpctx);
- return NULL;
+ MP_THREAD_RETURN();
}
static void cancel_open(struct MPContext *mpctx)
@@ -1206,7 +1206,7 @@ static void cancel_open(struct MPContext *mpctx)
mp_cancel_trigger(mpctx->open_cancel);
if (mpctx->open_active)
- pthread_join(mpctx->open_thread, NULL);
+ mp_thread_join(mpctx->open_thread);
mpctx->open_active = false;
if (mpctx->open_res_demuxer)
@@ -1237,7 +1237,7 @@ static void start_open(struct MPContext *mpctx, char *url, int url_flags,
mpctx->open_url_flags = url_flags;
mpctx->open_for_prefetch = for_prefetch && mpctx->opts->demuxer_thread;
- if (pthread_create(&mpctx->open_thread, NULL, open_demux_thread, mpctx)) {
+ if (mp_thread_create(&mpctx->open_thread, open_demux_thread, mpctx)) {
cancel_open(mpctx);
return;
}
diff --git a/player/main.c b/player/main.c
index fed3c1deab..27cf9b4449 100644
--- a/player/main.c
+++ b/player/main.c
@@ -21,7 +21,6 @@
#include <math.h>
#include <assert.h>
#include <string.h>
-#include <pthread.h>
#include <locale.h>
#include "config.h"
@@ -100,16 +99,16 @@ const char mp_help_text[] =
" --h=<string> print options which contain the given string in their name\n"
"\n";
-static pthread_mutex_t terminal_owner_lock = PTHREAD_MUTEX_INITIALIZER;
+static mp_static_mutex terminal_owner_lock = MP_STATIC_MUTEX_INITIALIZER;
static struct MPContext *terminal_owner;
static bool cas_terminal_owner(struct MPContext *old, struct MPContext *new)
{
- pthread_mutex_lock(&terminal_owner_lock);
+ mp_mutex_lock(&terminal_owner_lock);
bool r = terminal_owner == old;
if (r)
terminal_owner = new;
- pthread_mutex_unlock(&terminal_owner_lock);
+ mp_mutex_unlock(&terminal_owner_lock);
return r;
}
@@ -197,7 +196,7 @@ void mp_destroy(struct MPContext *mpctx)
mp_msg_uninit(mpctx->global);
assert(!mpctx->num_abort_list);
talloc_free(mpctx->abort_list);
- pthread_mutex_destroy(&mpctx->abort_lock);
+ mp_mutex_destroy(&mpctx->abort_lock);
talloc_free(mpctx->mconfig); // destroy before dispatch
talloc_free(mpctx);
}
@@ -269,7 +268,7 @@ struct MPContext *mp_create(void)
.play_dir = 1,
};
- pthread_mutex_init(&mpctx->abort_lock, NULL);
+ mp_mutex_init(&mpctx->abort_lock);
mpctx->global = talloc_zero(mpctx, struct mpv_global);
@@ -420,7 +419,7 @@ int mp_initialize(struct MPContext *mpctx, char **options)
int mpv_main(int argc, char *argv[])
{
- mpthread_set_name("mpv");
+ mp_thread_set_name("mpv");
struct MPContext *mpctx = mp_create();
if (!mpctx)
return 1;
diff --git a/player/scripting.c b/player/scripting.c
index b7268f9b91..962a5e815f 100644
--- a/player/scripting.c
+++ b/player/scripting.c
@@ -20,7 +20,6 @