summaryrefslogtreecommitdiffstats
path: root/osdep/win32/include
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-04-10 13:16:15 +0200
committerwm4 <wm4@nowhere>2017-06-15 16:33:42 +0200
commitfa929eb0d0449bc88aa702f6790da324879c75a5 (patch)
tree8f666d4cf1a4388b0262eab79c8c657ad4aa1cbc /osdep/win32/include
parenta3f0bf916ddf47ba4e94ad538e32e106756dedf7 (diff)
downloadmpv-fa929eb0d0449bc88aa702f6790da324879c75a5.tar.bz2
mpv-fa929eb0d0449bc88aa702f6790da324879c75a5.tar.xz
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.
Diffstat (limited to 'osdep/win32/include')
-rw-r--r--osdep/win32/include/pthread.h11
1 files changed, 3 insertions, 8 deletions
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);