Skip to content

Commit

Permalink
Windows: more pthreads functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Mar 7, 2010
1 parent 5f8763a commit 912b263
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compat/win32/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
static unsigned __stdcall win32_start_routine(void *arg)
{
pthread_t *thread = arg;
thread->tid = GetCurrentThreadId();
thread->arg = thread->start_routine(thread->arg);
return 0;
}
Expand Down Expand Up @@ -49,6 +50,13 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
}
}

pthread_t pthread_self(void)
{
pthread_t t = { 0 };
t.tid = GetCurrentThreadId();
return t;
}

int pthread_cond_init(pthread_cond_t *cond, const void *unused)
{
cond->waiters = 0;
Expand Down
25 changes: 25 additions & 0 deletions compat/win32/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef struct {
HANDLE handle;
void *(*start_routine)(void*);
void *arg;
DWORD tid;
} pthread_t;

extern int pthread_create(pthread_t *thread, const void *unused,
Expand All @@ -65,4 +66,28 @@ extern int pthread_create(pthread_t *thread, const void *unused,

extern int win32_pthread_join(pthread_t *thread, void **value_ptr);

#define pthread_equal(t1, t2) ((t1).tid == (t2).tid)
extern pthread_t pthread_self(void);

static inline int pthread_exit(void *ret)
{
ExitThread((DWORD)ret);
}

typedef DWORD pthread_key_t;
static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value))
{
return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0;
}

static inline int pthread_setspecific(pthread_key_t key, const void *value)
{
return TlsSetValue(key, (void *)value) ? 0 : EINVAL;
}

static inline void *pthread_getspecific(pthread_key_t key)
{
return TlsGetValue(key);
}

#endif /* PTHREAD_H */

0 comments on commit 912b263

Please sign in to comment.