From fa929eb0d0449bc88aa702f6790da324879c75a5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 10 Apr 2017 13:16:15 +0200 Subject: win32: pthread: avoid using TLS, simplify pthread_t Don't use __thread, which requires heavy runtime in some cases (such as MinGW-w64, at least under some configurations, forcing you to link to its pthread runtime DLL). The pthread_t struct was needed over a simple thread ID, because pthread_join() needed to access some sort of context from pthread_t. Further, pthread_exit() and pthread_detach() need the context of the current thread, for which we relied on TLS. Replace these uses by a global thread array. This includes all threads created by the thread wrapper. Hopefully the number of threads created by mpv is low (say, below 20), and threads are not that often created or destroyed. So just keeping them in an array with linear search lookup should be reasonable. --- osdep/win32/include/pthread.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'osdep/win32/include') diff --git a/osdep/win32/include/pthread.h b/osdep/win32/include/pthread.h index 271cae0f0a..5157b8e342 100644 --- a/osdep/win32/include/pthread.h +++ b/osdep/win32/include/pthread.h @@ -28,7 +28,6 @@ #define pthread_mutex_unlock m_pthread_mutex_unlock #define pthread_cond_timedwait m_pthread_cond_timedwait #define pthread_cond_wait m_pthread_cond_wait -#define pthread_self m_pthread_self #define pthread_exit m_pthread_exit #define pthread_join m_pthread_join #define pthread_detach m_pthread_detach @@ -80,15 +79,11 @@ int pthread_cond_timedwait(pthread_cond_t *restrict cond, int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); -// Unusual, but allowed by POSIX. -typedef struct { - DWORD id; - struct m_thread_info *info; -} pthread_t; +#define pthread_t DWORD -#define pthread_equal(a, b) ((a).id == (b).id) +#define pthread_equal(a, b) ((a) == (b)) +#define pthread_self() (GetCurrentThreadId()) -pthread_t pthread_self(void); void pthread_exit(void *retval); int pthread_join(pthread_t thread, void **retval); int pthread_detach(pthread_t thread); -- cgit v1.2.3