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 /video | |
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 'video')
-rw-r--r-- | video/out/dr_helper.c | 8 | ||||
-rw-r--r-- | video/out/dr_helper.h | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/video/out/dr_helper.c b/video/out/dr_helper.c index 125b2986bc..ac440a745d 100644 --- a/video/out/dr_helper.c +++ b/video/out/dr_helper.c @@ -13,7 +13,7 @@ struct dr_helper { mp_mutex thread_lock; - mp_thread thread; + mp_thread_id thread_id; bool thread_valid; // (POSIX defines no "unset" mp_thread value yet) struct mp_dispatch_queue *dispatch; @@ -57,7 +57,7 @@ void dr_helper_acquire_thread(struct dr_helper *dr) mp_mutex_lock(&dr->thread_lock); assert(!dr->thread_valid); // fails on API user errors dr->thread_valid = true; - dr->thread = mp_thread_self(); + dr->thread_id = mp_thread_current_id(); mp_mutex_unlock(&dr->thread_lock); } @@ -66,7 +66,7 @@ void dr_helper_release_thread(struct dr_helper *dr) mp_mutex_lock(&dr->thread_lock); // Fails on API user errors. assert(dr->thread_valid); - assert(mp_thread_equal(dr->thread, mp_thread_self())); + assert(mp_thread_id_equal(dr->thread_id, mp_thread_current_id())); dr->thread_valid = false; mp_mutex_unlock(&dr->thread_lock); } @@ -94,7 +94,7 @@ static void free_dr_buffer_on_dr_thread(void *opaque, uint8_t *data) mp_mutex_lock(&dr->thread_lock); bool on_this_thread = - dr->thread_valid && mp_thread_equal(ctx->dr->thread, mp_thread_self()); + dr->thread_valid && mp_thread_id_equal(ctx->dr->thread_id, mp_thread_current_id()); mp_mutex_unlock(&dr->thread_lock); // The image could be unreffed even on the DR thread. In practice, this diff --git a/video/out/dr_helper.h b/video/out/dr_helper.h index a86121cd3e..cf2ed14855 100644 --- a/video/out/dr_helper.h +++ b/video/out/dr_helper.h @@ -18,9 +18,9 @@ struct dr_helper *dr_helper_create(struct mp_dispatch_queue *dispatch, int stride_align, int flags), void *get_image_ctx); -// Make DR release calls (freeing images) reentrant if they are called on this -// (mp_thread_self()) thread. That means any free call will directly release the -// image as allocated with get_image(). +// Make DR release calls (freeing images) reentrant if they are called on current +// thread. That means any free call will directly release the image as allocated +// with get_image(). // Only 1 thread can use this at a time. Note that it would make no sense to // call this on more than 1 thread, as get_image is assumed not thread-safe. void dr_helper_acquire_thread(struct dr_helper *dr); |