Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b4e29b

Browse files
committed
React to review feedback
1 parent fb59176 commit 1b4e29b

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/thread-utils.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,16 @@ typedef git_atomic git_atomic_ssize;
4040

4141
#ifdef GIT_THREADS
4242

43-
#if defined(GIT_WIN32)
44-
45-
#define git_thread git_win32_thread
46-
#define git_thread_create(thread, attr, start_routine, arg) \
47-
git_win32__thread_create(thread, attr, start_routine, arg)
48-
#define git_thread_join(thread_ptr, status) \
49-
git_win32__thread_join(thread_ptr, status)
43+
#if !defined(GIT_WIN32)
5044

51-
#else
45+
typedef struct {
46+
pthread_t thread;
47+
} git_thread;
5248

53-
#define git_thread pthread_t
54-
#define git_thread_create(thread, attr, start_routine, arg) \
55-
pthread_create(thread, attr, start_routine, arg)
56-
#define git_thread_join(thread_ptr, status) \
57-
pthread_join(*(thread_ptr), status)
49+
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
50+
pthread_create(&(git_thread_ptr)->thread, attr, start_routine, arg)
51+
#define git_thread_join(git_thread_ptr, status) \
52+
pthread_join((git_thread_ptr)->thread, status)
5853

5954
#endif
6055

src/win32/pthread.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
1818
{
1919
git_win32_thread *thread = lpParameter;
2020

21-
thread->value = thread->proc(thread->value);
21+
thread->result = thread->proc(thread->param);
2222

2323
return CLEAN_THREAD_EXIT;
2424
}
@@ -31,7 +31,8 @@ int git_win32__thread_create(
3131
{
3232
GIT_UNUSED(attr);
3333

34-
thread->value = arg;
34+
thread->result = NULL;
35+
thread->param = arg;
3536
thread->proc = start_routine;
3637
thread->thread = CreateThread(
3738
NULL, 0, git_win32__threadproc, thread, 0, NULL);
@@ -57,11 +58,11 @@ int git_win32__thread_join(
5758
* then we don't have a return value to give back to the caller. */
5859
if (exit != CLEAN_THREAD_EXIT) {
5960
assert(false);
60-
thread->value = NULL;
61+
thread->result = NULL;
6162
}
6263

6364
if (value_ptr)
64-
*value_ptr = thread->value;
65+
*value_ptr = thread->result;
6566

6667
CloseHandle(thread->thread);
6768
return 0;

src/win32/pthread.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
typedef struct {
2020
HANDLE thread;
2121
void *(*proc)(void *);
22-
void *value;
22+
void *param;
23+
void *result;
2324
} git_win32_thread;
2425

2526
typedef int pthread_mutexattr_t;
@@ -51,6 +52,17 @@ int git_win32__thread_join(
5152
git_win32_thread *,
5253
void **);
5354

55+
#ifdef GIT_THREADS
56+
57+
typedef git_win32_thread git_thread;
58+
59+
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
60+
git_win32__thread_create(git_thread_ptr, attr, start_routine, arg)
61+
#define git_thread_join(git_thread_ptr, status) \
62+
git_win32__thread_join(git_thread_ptr, status)
63+
64+
#endif
65+
5466
int pthread_mutex_init(
5567
pthread_mutex_t *GIT_RESTRICT mutex,
5668
const pthread_mutexattr_t *GIT_RESTRICT mutexattr);

0 commit comments

Comments
 (0)