Skip to content

Commit aab266c

Browse files
committed
threads: add platform-independent thread initialization function
1 parent 8aaa9fb commit aab266c

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

src/global.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int synchronized_threads_init(void)
134134

135135
_tls_index = TlsAlloc();
136136

137-
win32_pthread_initialize();
137+
git_threads_init();
138138

139139
if (git_mutex_init(&git__mwindow_mutex))
140140
return -1;

src/unix/pthread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typedef struct {
1212
pthread_t thread;
1313
} git_thread;
1414

15+
#define git_threads_init() (void)0
1516
#define git_thread_create(git_thread_ptr, start_routine, arg) \
1617
pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
1718
#define git_thread_join(git_thread_ptr, status) \

src/win32/thread.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
#define CLEAN_THREAD_EXIT 0x6F012842
1212

13+
typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
14+
15+
static win32_srwlock_fn win32_srwlock_initialize;
16+
static win32_srwlock_fn win32_srwlock_acquire_shared;
17+
static win32_srwlock_fn win32_srwlock_release_shared;
18+
static win32_srwlock_fn win32_srwlock_acquire_exclusive;
19+
static win32_srwlock_fn win32_srwlock_release_exclusive;
20+
1321
/* The thread procedure stub used to invoke the caller's procedure
1422
* and capture the return value for later collection. Windows will
1523
* 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)
2533
return CLEAN_THREAD_EXIT;
2634
}
2735

36+
int git_threads_init(void)
37+
{
38+
HMODULE hModule = GetModuleHandleW(L"kernel32");
39+
40+
if (hModule) {
41+
win32_srwlock_initialize = (win32_srwlock_fn)
42+
GetProcAddress(hModule, "InitializeSRWLock");
43+
win32_srwlock_acquire_shared = (win32_srwlock_fn)
44+
GetProcAddress(hModule, "AcquireSRWLockShared");
45+
win32_srwlock_release_shared = (win32_srwlock_fn)
46+
GetProcAddress(hModule, "ReleaseSRWLockShared");
47+
win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
48+
GetProcAddress(hModule, "AcquireSRWLockExclusive");
49+
win32_srwlock_release_exclusive = (win32_srwlock_fn)
50+
GetProcAddress(hModule, "ReleaseSRWLockExclusive");
51+
}
52+
53+
return 0;
54+
}
55+
2856
int git_thread_create(
2957
git_thread *GIT_RESTRICT thread,
3058
void *(*start_routine)(void*),
@@ -152,15 +180,6 @@ int git_cond_signal(git_cond *cond)
152180
return 0;
153181
}
154182

155-
156-
typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
157-
158-
static win32_srwlock_fn win32_srwlock_initialize;
159-
static win32_srwlock_fn win32_srwlock_acquire_shared;
160-
static win32_srwlock_fn win32_srwlock_release_shared;
161-
static win32_srwlock_fn win32_srwlock_acquire_exclusive;
162-
static win32_srwlock_fn win32_srwlock_release_exclusive;
163-
164183
int git_rwlock_init(git_rwlock *GIT_RESTRICT lock)
165184
{
166185
if (win32_srwlock_initialize)
@@ -218,23 +237,3 @@ int git_rwlock_free(git_rwlock *lock)
218237
git__memzero(lock, sizeof(*lock));
219238
return 0;
220239
}
221-
222-
int win32_pthread_initialize(void)
223-
{
224-
HMODULE hModule = GetModuleHandleW(L"kernel32");
225-
226-
if (hModule) {
227-
win32_srwlock_initialize = (win32_srwlock_fn)
228-
GetProcAddress(hModule, "InitializeSRWLock");
229-
win32_srwlock_acquire_shared = (win32_srwlock_fn)
230-
GetProcAddress(hModule, "AcquireSRWLockShared");
231-
win32_srwlock_release_shared = (win32_srwlock_fn)
232-
GetProcAddress(hModule, "ReleaseSRWLockShared");
233-
win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
234-
GetProcAddress(hModule, "AcquireSRWLockExclusive");
235-
win32_srwlock_release_exclusive = (win32_srwlock_fn)
236-
GetProcAddress(hModule, "ReleaseSRWLockExclusive");
237-
}
238-
239-
return 0;
240-
}

src/win32/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef struct {
3535
} native;
3636
} git_rwlock;
3737

38+
int git_threads_init(void);
39+
3840
int git_thread_create(git_thread *GIT_RESTRICT,
3941
void *(*) (void *),
4042
void *GIT_RESTRICT);
@@ -57,6 +59,4 @@ int git_rwlock_wrlock(git_rwlock *);
5759
int git_rwlock_wrunlock(git_rwlock *);
5860
int git_rwlock_free(git_rwlock *);
5961

60-
extern int win32_pthread_initialize(void);
61-
6262
#endif /* INCLUDE_win32_thread_h__ */

0 commit comments

Comments
 (0)