React to review feedback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 0cc7b04..daec14e 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -40,21 +40,16 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
-#if defined(GIT_WIN32)
-
-#define git_thread git_win32_thread
-#define git_thread_create(thread, attr, start_routine, arg) \
- git_win32__thread_create(thread, attr, start_routine, arg)
-#define git_thread_join(thread_ptr, status) \
- git_win32__thread_join(thread_ptr, status)
+#if !defined(GIT_WIN32)
-#else
+typedef struct {
+ pthread_t thread;
+} git_thread;
-#define git_thread pthread_t
-#define git_thread_create(thread, attr, start_routine, arg) \
- pthread_create(thread, attr, start_routine, arg)
-#define git_thread_join(thread_ptr, status) \
- pthread_join(*(thread_ptr), status)
+#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
+ pthread_create(&(git_thread_ptr)->thread, attr, start_routine, arg)
+#define git_thread_join(git_thread_ptr, status) \
+ pthread_join((git_thread_ptr)->thread, status)
#endif
diff --git a/src/win32/pthread.c b/src/win32/pthread.c
index b14b356..ec45ecb 100644
--- a/src/win32/pthread.c
+++ b/src/win32/pthread.c
@@ -18,7 +18,7 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
{
git_win32_thread *thread = lpParameter;
- thread->value = thread->proc(thread->value);
+ thread->result = thread->proc(thread->param);
return CLEAN_THREAD_EXIT;
}
@@ -31,7 +31,8 @@ int git_win32__thread_create(
{
GIT_UNUSED(attr);
- thread->value = arg;
+ thread->result = NULL;
+ thread->param = arg;
thread->proc = start_routine;
thread->thread = CreateThread(
NULL, 0, git_win32__threadproc, thread, 0, NULL);
@@ -57,11 +58,11 @@ int git_win32__thread_join(
* then we don't have a return value to give back to the caller. */
if (exit != CLEAN_THREAD_EXIT) {
assert(false);
- thread->value = NULL;
+ thread->result = NULL;
}
if (value_ptr)
- *value_ptr = thread->value;
+ *value_ptr = thread->result;
CloseHandle(thread->thread);
return 0;
diff --git a/src/win32/pthread.h b/src/win32/pthread.h
index a15504e..e4826ca 100644
--- a/src/win32/pthread.h
+++ b/src/win32/pthread.h
@@ -19,7 +19,8 @@
typedef struct {
HANDLE thread;
void *(*proc)(void *);
- void *value;
+ void *param;
+ void *result;
} git_win32_thread;
typedef int pthread_mutexattr_t;
@@ -51,6 +52,17 @@ int git_win32__thread_join(
git_win32_thread *,
void **);
+#ifdef GIT_THREADS
+
+typedef git_win32_thread git_thread;
+
+#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
+ git_win32__thread_create(git_thread_ptr, attr, start_routine, arg)
+#define git_thread_join(git_thread_ptr, status) \
+ git_win32__thread_join(git_thread_ptr, status)
+
+#endif
+
int pthread_mutex_init(
pthread_mutex_t *GIT_RESTRICT mutex,
const pthread_mutexattr_t *GIT_RESTRICT mutexattr);