summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-10-21 04:55:41 +0200
committerDudemanguy <random342@airmail.cc>2023-11-05 17:36:17 +0000
commit174df99ffa53f1091589eaa4fa0c16cdd55a9326 (patch)
tree3a60d45615f18beed98a9b08267c28ed7e05dd5f /input
parent3a8b107f6216b38a151d5ca1e9d4f2727e3418f5 (diff)
downloadmpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.bz2
mpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.xz
ALL: use new mp_thread abstraction
Diffstat (limited to 'input')
-rw-r--r--input/input.c24
-rw-r--r--input/ipc-unix.c25
-rw-r--r--input/ipc-win.c24
-rw-r--r--input/sdl_gamepad.c10
4 files changed, 42 insertions, 41 deletions
diff --git a/input/input.c b/input/input.c
index 4b13841224..b1ca1314b5 100644
--- a/input/input.c
+++ b/input/input.c
@@ -54,8 +54,8 @@
#include "osdep/macosx_events.h"
#endif
-#define input_lock(ictx) pthread_mutex_lock(&ictx->mutex)
-#define input_unlock(ictx) pthread_mutex_unlock(&ictx->mutex)
+#define input_lock(ictx) mp_mutex_lock(&ictx->mutex)
+#define input_unlock(ictx) mp_mutex_unlock(&ictx->mutex)
#define MP_MAX_KEY_DOWN 4
@@ -97,7 +97,7 @@ struct wheel_state {
};
struct input_ctx {
- pthread_mutex_t mutex;
+ mp_mutex mutex;
struct mp_log *log;
struct mpv_global *global;
struct m_config_cache *opts_cache;
@@ -1322,7 +1322,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global,
ictx->opts = ictx->opts_cache->opts;
- mpthread_mutex_init_recursive(&ictx->mutex);
+ mp_mutex_init_type(&ictx->mutex, MP_MUTEX_RECURSIVE);
// Setup default section, so that it does nothing.
mp_input_enable_section(ictx, NULL, MP_INPUT_ALLOW_VO_DRAGGING |
@@ -1414,7 +1414,7 @@ void mp_input_uninit(struct input_ctx *ictx)
close_input_sources(ictx);
clear_queue(&ictx->cmd_queue);
talloc_free(ictx->current_down_cmd);
- pthread_mutex_destroy(&ictx->mutex);
+ mp_mutex_destroy(&ictx->mutex);
talloc_free(ictx);
}
@@ -1534,7 +1534,7 @@ struct mpv_node mp_input_get_bindings(struct input_ctx *ictx)
}
struct mp_input_src_internal {
- pthread_t thread;
+ mp_thread thread;
bool thread_running;
bool init_done;
@@ -1596,7 +1596,7 @@ static void mp_input_src_kill(struct mp_input_src *src)
if (src->cancel)
src->cancel(src);
if (src->in->thread_running)
- pthread_join(src->in->thread, NULL);
+ mp_thread_join(src->in->thread);
if (src->uninit)
src->uninit(src);
talloc_free(src);
@@ -1610,19 +1610,19 @@ void mp_input_src_init_done(struct mp_input_src *src)
{
assert(!src->in->init_done);
assert(src->in->thread_running);
- assert(pthread_equal(src->in->thread, pthread_self()));
+ assert(mp_thread_equal(src->in->thread, mp_thread_self()));
src->in->init_done = true;
mp_rendezvous(&src->in->init_done, 0);
}
-static void *input_src_thread(void *ptr)
+static MP_THREAD_VOID input_src_thread(void *ptr)
{
void **args = ptr;
struct mp_input_src *src = args[0];
void (*loop_fn)(struct mp_input_src *src, void *ctx) = args[1];
void *ctx = args[2];
- mpthread_set_name("input");
+ mp_thread_set_name("input");
src->in->thread_running = true;
@@ -1631,7 +1631,7 @@ static void *input_src_thread(void *ptr)
if (!src->in->init_done)
mp_rendezvous(&src->in->init_done, -1);
- return NULL;
+ MP_THREAD_RETURN();
}
int mp_input_add_thread_src(struct input_ctx *ictx, void *ctx,
@@ -1642,7 +1642,7 @@ int mp_input_add_thread_src(struct input_ctx *ictx, void *ctx,
return -1;
void *args[] = {src, loop_fn, ctx};
- if (pthread_create(&src->in->thread, NULL, input_src_thread, args)) {
+ if (mp_thread_create(&src->in->thread, input_src_thread, args)) {
mp_input_src_kill(src);
return -1;
}
diff --git a/input/ipc-unix.c b/input/ipc-unix.c
index 2cb53be546..595cf7f029 100644
--- a/input/ipc-unix.c
+++ b/input/ipc-unix.c
@@ -15,7 +15,6 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
@@ -48,7 +47,7 @@ struct mp_ipc_ctx {
struct mp_client_api *client_api;
const char *path;
- pthread_t thread;
+ mp_thread thread;
int death_pipe[2];
};
@@ -91,9 +90,9 @@ static int ipc_write_str(struct client_arg *client, const char *buf)
return 0;
}
-static void *client_thread(void *p)
+static MP_THREAD_VOID client_thread(void *p)
{
- pthread_detach(pthread_self());
+ pthread_detach(mp_thread_self());
// We don't use MSG_NOSIGNAL because the moldy fruit OS doesn't support it.
struct sigaction sa = { .sa_handler = SIG_IGN, .sa_flags = SA_RESTART };
@@ -106,7 +105,7 @@ static void *client_thread(void *p)
bstr client_msg = { talloc_strdup(NULL, ""), 0 };
char *tname = talloc_asprintf(NULL, "ipc/%s", arg->client_name);
- mpthread_set_name(tname);
+ mp_thread_set_name(tname);
talloc_free(tname);
int pipe_fd = mpv_get_wakeup_pipe(arg->client);
@@ -219,7 +218,7 @@ done:
} else {
mpv_destroy(h);
}
- return NULL;
+ MP_THREAD_RETURN();
}
static bool ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client,
@@ -232,8 +231,8 @@ static bool ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client,
client->log = mp_client_get_log(client->client);
- pthread_t client_thr;
- if (pthread_create(&client_thr, NULL, client_thread, client))
+ mp_thread client_thr;
+ if (mp_thread_create(&client_thr, client_thread, client))
goto err;
return true;
@@ -295,7 +294,7 @@ bool mp_ipc_start_anon_client(struct mp_ipc_ctx *ctx, struct mpv_handle *h,
return true;
}
-static void *ipc_thread(void *p)
+static MP_THREAD_VOID ipc_thread(void *p)
{
int rc;
@@ -304,7 +303,7 @@ static void *ipc_thread(void *p)
struct mp_ipc_ctx *arg = p;
- mpthread_set_name("ipc/socket");
+ mp_thread_set_name("ipc/socket");
MP_VERBOSE(arg, "Starting IPC master\n");
@@ -379,7 +378,7 @@ done:
if (ipc_fd >= 0)
close(ipc_fd);
- return NULL;
+ MP_THREAD_RETURN();
}
struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
@@ -418,7 +417,7 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
if (mp_make_wakeup_pipe(arg->death_pipe) < 0)
goto out;
- if (pthread_create(&arg->thread, NULL, ipc_thread, arg))
+ if (mp_thread_create(&arg->thread, ipc_thread, arg))
goto out;
return arg;
@@ -438,7 +437,7 @@ void mp_uninit_ipc(struct mp_ipc_ctx *arg)
return;
(void)write(arg->death_pipe[1], &(char){0}, 1);
- pthread_join(arg->thread, NULL);
+ mp_thread_join(arg->thread);
close(arg->death_pipe[0]);
close(arg->death_pipe[1]);
diff --git a/input/ipc-win.c b/input/ipc-win.c
index 42a519ecf0..cf80ccdcac 100644
--- a/input/ipc-win.c
+++ b/input/ipc-win.c
@@ -36,7 +36,7 @@ struct mp_ipc_ctx {
struct mp_client_api *client_api;
const wchar_t *path;
- pthread_t thread;
+ mp_thread thread;
HANDLE death_event;
};
@@ -198,9 +198,9 @@ static void report_read_error(struct client_arg *arg, DWORD error)
}
}
-static void *client_thread(void *p)
+static MP_THREAD_VOID client_thread(void *p)
{
- pthread_detach(pthread_self());
+ pthread_detach(mp_thread_self());
struct client_arg *arg = p;
char buf[4096];
@@ -211,7 +211,7 @@ static void *client_thread(void *p)
DWORD r;
char *tname = talloc_asprintf(NULL, "ipc/%s", arg->client_name);
- mpthread_set_name(tname);
+ mp_thread_set_name(tname);
talloc_free(tname);
arg->write_ol.hEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
@@ -307,7 +307,7 @@ done:
CloseHandle(arg->client_h);
mpv_destroy(arg->client);
talloc_free(arg);
- return NULL;
+ MP_THREAD_RETURN();
}
static void ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client)
@@ -315,8 +315,8 @@ static void ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client)
client->client = mp_new_client(ctx->client_api, client->client_name),
client->log = mp_client_get_log(client->client);
- pthread_t client_thr;
- if (pthread_create(&client_thr, NULL, client_thread, client)) {
+ mp_thread client_thr;
+ if (mp_thread_create(&client_thr, client_thread, client)) {
mpv_destroy(client->client);
CloseHandle(client->client_h);
talloc_free(client);
@@ -341,7 +341,7 @@ bool mp_ipc_start_anon_client(struct mp_ipc_ctx *ctx, struct mpv_handle *h,
return false;
}
-static void *ipc_thread(void *p)
+static MP_THREAD_VOID ipc_thread(void *p)
{
// Use PIPE_TYPE_MESSAGE | PIPE_READMODE_BYTE so message framing is
// maintained for message-mode clients, but byte-mode clients can still
@@ -358,7 +358,7 @@ static void *ipc_thread(void *p)
HANDLE client = INVALID_HANDLE_VALUE;
int client_num = 0;
- mpthread_set_name("ipc/named-pipe");
+ mp_thread_set_name("ipc/named-pipe");
MP_VERBOSE(arg, "Starting IPC master\n");
SECURITY_ATTRIBUTES sa = {
@@ -450,7 +450,7 @@ done:
CloseHandle(server);
if (ol.hEvent)
CloseHandle(ol.hEvent);
- return NULL;
+ MP_THREAD_RETURN();
}
struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
@@ -482,7 +482,7 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
if (!(arg->death_event = CreateEventW(NULL, TRUE, FALSE, NULL)))
goto out;
- if (pthread_create(&arg->thread, NULL, ipc_thread, arg))
+ if (mp_thread_create(&arg->thread, ipc_thread, arg))
goto out;
talloc_free(opts);
@@ -502,7 +502,7 @@ void mp_uninit_ipc(struct mp_ipc_ctx *arg)
return;
SetEvent(arg->death_event);
- pthread_join(arg->thread, NULL);
+ mp_thread_join(arg->thread);
CloseHandle(arg->death_event);
talloc_free(arg);
diff --git a/input/sdl_gamepad.c b/input/sdl_gamepad.c
index 5a5ca47d53..790c945608 100644
--- a/input/sdl_gamepad.c
+++ b/input/sdl_gamepad.c
@@ -15,13 +15,15 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <SDL.h>
#include <stdbool.h>
-#include <pthread.h>
+
+#include <SDL.h>
+
#include "common/common.h"
#include "common/msg.h"
#include "input.h"
#include "input/keycodes.h"
+#include "osdep/threads.h"
struct gamepad_priv {
SDL_GameController *controller;
@@ -34,7 +36,7 @@ static void initialize_events(void)
gamepad_cancel_wakeup = SDL_RegisterEvents(1);
}
-static pthread_once_t events_initialized = PTHREAD_ONCE_INIT;
+static mp_once events_initialized = MP_STATIC_ONCE_INITIALIZER;
#define INVALID_KEY -1
@@ -212,7 +214,7 @@ static void read_gamepad_thread(struct mp_input_src *src, void *param)
return;
}
- pthread_once(&events_initialized, initialize_events);
+ mp_exec_once(&events_initialized, initialize_events);
if (gamepad_cancel_wakeup == (Uint32)-1) {
MP_ERR(src, "Can't register SDL custom events\n");