diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-10-22 02:34:42 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-11-05 17:36:17 +0000 |
commit | 55ed50ba901e70adda09f1cf8c0de7cf80cabeb3 (patch) | |
tree | 2117e03f8d0046f45d21479b67d67a3ce35bca14 /input | |
parent | 174df99ffa53f1091589eaa4fa0c16cdd55a9326 (diff) | |
download | mpv-55ed50ba901e70adda09f1cf8c0de7cf80cabeb3.tar.bz2 mpv-55ed50ba901e70adda09f1cf8c0de7cf80cabeb3.tar.xz |
mp_thread: prefer tracking threads with id
This change essentially removes mp_thread_self() and instead add
mp_thread_id to track threads and have ability to query current thread
id during runtime.
This will be useful for upcoming win32 implementation, where accessing
thread handle is different than on pthreads. Greatly reduces complexity.
Otherweis locked map of tid <-> handle is required which is completely
unnecessary for all mpv use-cases.
Note that this is the mp_thread_id, not to confuse with system tid. For
example on threads-posix implementation it is simply pthread_t.
Diffstat (limited to 'input')
-rw-r--r-- | input/input.c | 2 | ||||
-rw-r--r-- | input/ipc-unix.c | 3 | ||||
-rw-r--r-- | input/ipc-win.c | 3 |
3 files changed, 3 insertions, 5 deletions
diff --git a/input/input.c b/input/input.c index b1ca1314b5..67e2249e17 100644 --- a/input/input.c +++ b/input/input.c @@ -1610,7 +1610,7 @@ void mp_input_src_init_done(struct mp_input_src *src) { assert(!src->in->init_done); assert(src->in->thread_running); - assert(mp_thread_equal(src->in->thread, mp_thread_self())); + assert(mp_thread_id_equal(mp_thread_get_id(src->in->thread), mp_thread_current_id())); src->in->init_done = true; mp_rendezvous(&src->in->init_done, 0); } diff --git a/input/ipc-unix.c b/input/ipc-unix.c index 595cf7f029..a416b54e1e 100644 --- a/input/ipc-unix.c +++ b/input/ipc-unix.c @@ -92,8 +92,6 @@ static int ipc_write_str(struct client_arg *client, const char *buf) static MP_THREAD_VOID client_thread(void *p) { - 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 }; sigfillset(&sa.sa_mask); @@ -234,6 +232,7 @@ static bool ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client, mp_thread client_thr; if (mp_thread_create(&client_thr, client_thread, client)) goto err; + mp_thread_detach(client_thr); return true; diff --git a/input/ipc-win.c b/input/ipc-win.c index cf80ccdcac..8db6705f3f 100644 --- a/input/ipc-win.c +++ b/input/ipc-win.c @@ -200,8 +200,6 @@ static void report_read_error(struct client_arg *arg, DWORD error) static MP_THREAD_VOID client_thread(void *p) { - pthread_detach(mp_thread_self()); - struct client_arg *arg = p; char buf[4096]; HANDLE wakeup_event = CreateEventW(NULL, TRUE, FALSE, NULL); @@ -321,6 +319,7 @@ static void ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client) CloseHandle(client->client_h); talloc_free(client); } + mp_thread_detach(client_thr); } static void ipc_start_client_json(struct mp_ipc_ctx *ctx, int id, HANDLE h) |