Skip to content

Commit

Permalink
win32/pthread: avoid name clashes with winpthread
Browse files Browse the repository at this point in the history
The mingw-w64 GCC seems to link implicitly to libwinpthread, which does
implement a pthread emulation (that is more complete than Git's). Let's
keep preferring Git's.

To avoid linker errors where it thinks that the `pthread_self` and the
`pthread_create` symbols are defined twice, let's give our version a
`win32_` prefix, just like we already do for `pthread_join()`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 22, 2022
1 parent 033c693 commit 42e3768
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compat/win32/pthread.c
Expand Up @@ -21,7 +21,7 @@ static unsigned __stdcall win32_start_routine(void *arg)
return 0;
}

int pthread_create(pthread_t *thread, const void *unused,
int win32_pthread_create(pthread_t *thread, const void *unused,
void *(*start_routine)(void*), void *arg)
{
thread->arg = arg;
Expand Down Expand Up @@ -50,7 +50,7 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
}
}

pthread_t pthread_self(void)
pthread_t win32_pthread_self(void)
{
pthread_t t = { NULL };
t.tid = GetCurrentThreadId();
Expand Down
8 changes: 5 additions & 3 deletions compat/win32/pthread.h
Expand Up @@ -50,8 +50,9 @@ typedef struct {
DWORD tid;
} pthread_t;

int pthread_create(pthread_t *thread, const void *unused,
void *(*start_routine)(void*), void *arg);
int win32_pthread_create(pthread_t *thread, const void *unused,
void *(*start_routine)(void*), void *arg);
#define pthread_create win32_pthread_create

/*
* To avoid the need of copying a struct, we use small macro wrapper to pass
Expand All @@ -62,7 +63,8 @@ int pthread_create(pthread_t *thread, const void *unused,
int win32_pthread_join(pthread_t *thread, void **value_ptr);

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

static inline void NORETURN pthread_exit(void *ret)
{
Expand Down

0 comments on commit 42e3768

Please sign in to comment.