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.
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
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 *),