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 /osdep/threads-posix.h | |
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 'osdep/threads-posix.h')
-rw-r--r-- | osdep/threads-posix.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/osdep/threads-posix.h b/osdep/threads-posix.h index bfae23f1c2..78f0257979 100644 --- a/osdep/threads-posix.h +++ b/osdep/threads-posix.h @@ -28,6 +28,7 @@ typedef pthread_cond_t mp_cond; typedef pthread_mutex_t mp_mutex; typedef pthread_mutex_t mp_static_mutex; typedef pthread_once_t mp_once; +typedef pthread_t mp_thread_id; typedef pthread_t mp_thread; #define MP_STATIC_COND_INITIALIZER PTHREAD_COND_INITIALIZER @@ -105,8 +106,11 @@ static inline int mp_cond_timedwait_until(mp_cond *cond, mp_mutex *mutex, int64_ #define mp_thread_create(t, f, a) pthread_create(t, NULL, f, a) #define mp_thread_join(t) pthread_join(t, NULL) -#define mp_thread_self pthread_self -#define mp_thread_equal pthread_equal +#define mp_thread_join_id(t) pthread_join(t, NULL) +#define mp_thread_detach pthread_detach +#define mp_thread_current_id pthread_self +#define mp_thread_id_equal(a, b) ((a) == (b)) +#define mp_thread_get_id(thread) (thread) static inline void mp_thread_set_name(const char *name) { @@ -123,7 +127,7 @@ static inline void mp_thread_set_name(const char *name) #endif } -static inline int64_t mp_thread_cpu_time_ns(mp_thread thread) +static inline int64_t mp_thread_cpu_time_ns(mp_thread_id thread) { #if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(_POSIX_THREAD_CPUTIME) clockid_t id; |