]> git.proxmox.com Git - libgit2.git/commitdiff
threads: add platform-independent thread initialization function
authorPatrick Steinhardt <ps@pks.im>
Mon, 20 Jun 2016 18:07:33 +0000 (20:07 +0200)
committerPatrick Steinhardt <ps@pks.im>
Mon, 20 Jun 2016 18:07:33 +0000 (20:07 +0200)
src/global.c
src/unix/pthread.h
src/win32/thread.c
src/win32/thread.h

index 32e497507d20ec74e09c64879a2f19bf0c937f7b..eee0aea57c4ed17bc35710eff30d3d85b046b81c 100644 (file)
@@ -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;
index 773ce22f953f6b7f714cf16e7c877aa975f78d72..0f3f1792756dbdd35cc17ef15534826f56719300 100644 (file)
@@ -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) \
index 8222c65fe1d623d722f59b28e68392e822962d5b..80d56ce5d1908c81c156cc4b5a0acd7d2bf196c0 100644 (file)
 
 #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;
-}
index f5dd41ba3a72f39877a2700e008121eda84af811..0d01822a69d58fdc7a9ff9b2210489de4f9903b6 100644 (file)
@@ -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__ */