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 24, 2024
1 parent 5686029 commit 672e4f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions compat/win32/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ static unsigned __stdcall win32_start_routine(void *arg)
return 0;
}

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)
{
thread->arg = arg;
thread->start_routine = start_routine;
Expand Down Expand Up @@ -53,7 +53,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
Original file line number Diff line number Diff line change
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 672e4f2

Please sign in to comment.