Commit fe12423a91015e6116773340a8936fece3251339

Edward Thomson 2020-05-12T13:08:22

init: move thread init to git_global_threads_init Instead of treating win32 thread initialization specially in the win32 git_libgit2_init function, add a git_global_threads_init function.

diff --git a/src/global.c b/src/global.c
index 9fe8cd5..4abb5e3 100644
--- a/src/global.c
+++ b/src/global.c
@@ -31,6 +31,7 @@ typedef int (*git_global_init_fn)(void);
 
 static git_global_init_fn git__init_callbacks[] = {
 	git_allocator_global_init,
+	git_threads_global_init,
 	git_hash_global_init,
 	git_sysdir_global_init,
 	git_filter_global_init,
@@ -159,8 +160,6 @@ static int synchronized_threads_init(void)
 	if ((_fls_index = FlsAlloc(fls_free)) == FLS_OUT_OF_INDEXES)
 		return -1;
 
-	git_threads_init();
-
 	if (git_mutex_init(&git__mwindow_mutex))
 		return -1;
 
diff --git a/src/thread-utils.h b/src/thread-utils.h
index ecb4909..8e1e7c9 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -235,6 +235,8 @@ GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a)
 
 #else
 
+GIT_INLINE(int) git_threads_global_init(void) { return 0; }
+
 #define git_thread unsigned int
 #define git_thread_create(thread, start_routine, arg) 0
 #define git_thread_join(id, status) (void)0
diff --git a/src/unix/pthread.h b/src/unix/pthread.h
index 233561b..55f4ae2 100644
--- a/src/unix/pthread.h
+++ b/src/unix/pthread.h
@@ -12,7 +12,8 @@ typedef struct {
 	pthread_t thread;
 } git_thread;
 
-#define git_threads_init() (void)0
+GIT_INLINE(int) git_threads_global_init(void) { return 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 42dba7f..0936c31 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -35,7 +35,7 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
 	return CLEAN_THREAD_EXIT;
 }
 
-int git_threads_init(void)
+int git_threads_global_init(void)
 {
 	HMODULE hModule = GetModuleHandleW(L"kernel32");
 
diff --git a/src/win32/thread.h b/src/win32/thread.h
index 41cbf01..8305036 100644
--- a/src/win32/thread.h
+++ b/src/win32/thread.h
@@ -35,7 +35,7 @@ typedef struct {
 	} native;
 } git_rwlock;
 
-int git_threads_init(void);
+int git_threads_global_init(void);
 
 int git_thread_create(git_thread *GIT_RESTRICT,
 	void *(*) (void *),