threads: add platform-independent thread initialization function
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/src/global.c b/src/global.c
index 32e4975..eee0aea 100644
--- a/src/global.c
+++ b/src/global.c
@@ -134,7 +134,7 @@ static int synchronized_threads_init(void)
_tls_index = TlsAlloc();
- win32_pthread_initialize();
+ git_threads_init();
if (git_mutex_init(&git__mwindow_mutex))
return -1;
diff --git a/src/unix/pthread.h b/src/unix/pthread.h
index 773ce22..0f3f179 100644
--- a/src/unix/pthread.h
+++ b/src/unix/pthread.h
@@ -12,6 +12,7 @@ typedef struct {
pthread_t thread;
} git_thread;
+#define git_threads_init() (void)0
#define git_thread_create(git_thread_ptr, start_routine, arg) \
pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 8222c65..80d56ce 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -10,6 +10,14 @@
#define CLEAN_THREAD_EXIT 0x6F012842
+typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
+
+static win32_srwlock_fn win32_srwlock_initialize;
+static win32_srwlock_fn win32_srwlock_acquire_shared;
+static win32_srwlock_fn win32_srwlock_release_shared;
+static win32_srwlock_fn win32_srwlock_acquire_exclusive;
+static win32_srwlock_fn win32_srwlock_release_exclusive;
+
/* The thread procedure stub used to invoke the caller's procedure
* and capture the return value for later collection. Windows will
* only hold a DWORD, but we need to be able to store an entire
@@ -25,6 +33,26 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
return CLEAN_THREAD_EXIT;
}
+int git_threads_init(void)
+{
+ HMODULE hModule = GetModuleHandleW(L"kernel32");
+
+ if (hModule) {
+ win32_srwlock_initialize = (win32_srwlock_fn)
+ GetProcAddress(hModule, "InitializeSRWLock");
+ win32_srwlock_acquire_shared = (win32_srwlock_fn)
+ GetProcAddress(hModule, "AcquireSRWLockShared");
+ win32_srwlock_release_shared = (win32_srwlock_fn)
+ GetProcAddress(hModule, "ReleaseSRWLockShared");
+ win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
+ GetProcAddress(hModule, "AcquireSRWLockExclusive");
+ win32_srwlock_release_exclusive = (win32_srwlock_fn)
+ GetProcAddress(hModule, "ReleaseSRWLockExclusive");
+ }
+
+ return 0;
+}
+
int git_thread_create(
git_thread *GIT_RESTRICT thread,
void *(*start_routine)(void*),
@@ -152,15 +180,6 @@ int git_cond_signal(git_cond *cond)
return 0;
}
-
-typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
-
-static win32_srwlock_fn win32_srwlock_initialize;
-static win32_srwlock_fn win32_srwlock_acquire_shared;
-static win32_srwlock_fn win32_srwlock_release_shared;
-static win32_srwlock_fn win32_srwlock_acquire_exclusive;
-static win32_srwlock_fn win32_srwlock_release_exclusive;
-
int git_rwlock_init(git_rwlock *GIT_RESTRICT lock)
{
if (win32_srwlock_initialize)
@@ -218,23 +237,3 @@ int git_rwlock_free(git_rwlock *lock)
git__memzero(lock, sizeof(*lock));
return 0;
}
-
-int win32_pthread_initialize(void)
-{
- HMODULE hModule = GetModuleHandleW(L"kernel32");
-
- if (hModule) {
- win32_srwlock_initialize = (win32_srwlock_fn)
- GetProcAddress(hModule, "InitializeSRWLock");
- win32_srwlock_acquire_shared = (win32_srwlock_fn)
- GetProcAddress(hModule, "AcquireSRWLockShared");
- win32_srwlock_release_shared = (win32_srwlock_fn)
- GetProcAddress(hModule, "ReleaseSRWLockShared");
- win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
- GetProcAddress(hModule, "AcquireSRWLockExclusive");
- win32_srwlock_release_exclusive = (win32_srwlock_fn)
- GetProcAddress(hModule, "ReleaseSRWLockExclusive");
- }
-
- return 0;
-}
diff --git a/src/win32/thread.h b/src/win32/thread.h
index f5dd41b..0d01822 100644
--- a/src/win32/thread.h
+++ b/src/win32/thread.h
@@ -35,6 +35,8 @@ typedef struct {
} native;
} git_rwlock;
+int git_threads_init(void);
+
int git_thread_create(git_thread *GIT_RESTRICT,
void *(*) (void *),
void *GIT_RESTRICT);
@@ -57,6 +59,4 @@ int git_rwlock_wrlock(git_rwlock *);
int git_rwlock_wrunlock(git_rwlock *);
int git_rwlock_free(git_rwlock *);
-extern int win32_pthread_initialize(void);
-
#endif /* INCLUDE_win32_thread_h__ */