Windows: more pthreads functions
This adds: pthread_self pthread_equal pthread_exit pthread_key_create pthread_setspecific pthread_getspecific Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Mar 6, 2010 at 16:40 UTC
912b26324dbc1eb9500e49c90d271a330cbcb30b
2 files changed
+33
compat/win32/pthread.c
+8
@@ -16,6 +16,7 @@
16
static unsigned __stdcall win32_start_routine(void *arg)
17
{
18
pthread_t *thread = arg;
19
+ thread->tid = GetCurrentThreadId();
20
thread->arg = thread->start_routine(thread->arg);
21
return 0;
22
}
@@ -49,6 +50,13 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
50
}
51
}
52
53
+pthread_t pthread_self(void)
54
+{
55
+ pthread_t t = { 0 };
56
+ t.tid = GetCurrentThreadId();
57
+ return t;
58
+}
59
+
60
int pthread_cond_init(pthread_cond_t *cond, const void *unused)
61
{
62
cond->waiters = 0;
compat/win32/pthread.h
+25
@@ -52,6 +52,7 @@ typedef struct {
52
HANDLE handle;
53
void *(*start_routine)(void*);
54
void *arg;
55
+ DWORD tid;
56
} pthread_t;
57
58
extern int pthread_create(pthread_t *thread, const void *unused,
@@ -65,4 +66,28 @@ extern int pthread_create(pthread_t *thread, const void *unused,
66
67
extern int win32_pthread_join(pthread_t *thread, void **value_ptr);
68
69
+#define pthread_equal(t1, t2) ((t1).tid == (t2).tid)
70
+extern pthread_t pthread_self(void);
71
+
72
+static inline int pthread_exit(void *ret)
73
+{
74
+ ExitThread((DWORD)ret);
75
+}
76
+
77
+typedef DWORD pthread_key_t;
78
+static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value))
79
+{
80
+ return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0;
81
+}
82
+
83
+static inline int pthread_setspecific(pthread_key_t key, const void *value)
84
+{
85
+ return TlsSetValue(key, (void *)value) ? 0 : EINVAL;
86
+}
87
+
88
+static inline void *pthread_getspecific(pthread_key_t key)
89
+{
90
+ return TlsGetValue(key);
91
+}
92
+
93
#endif /* PTHREAD_H */