Commit 3816debc by Russell Belfer

Fix threading tests when threads disabled

parent 52bb0476
...@@ -16,8 +16,9 @@ git_mutex git__mwindow_mutex; ...@@ -16,8 +16,9 @@ git_mutex git__mwindow_mutex;
#define MAX_SHUTDOWN_CB 8 #define MAX_SHUTDOWN_CB 8
git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB]; static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
git_atomic git__n_shutdown_callbacks; static git_atomic git__n_shutdown_callbacks;
static git_atomic git__n_inits;
void git__on_shutdown(git_global_shutdown_fn callback) void git__on_shutdown(git_global_shutdown_fn callback)
{ {
...@@ -74,7 +75,6 @@ static void git__shutdown(void) ...@@ -74,7 +75,6 @@ static void git__shutdown(void)
static DWORD _tls_index; static DWORD _tls_index;
static DWORD _mutex = 0; static DWORD _mutex = 0;
static DWORD _n_inits = 0;
static int synchronized_threads_init() static int synchronized_threads_init()
{ {
...@@ -101,7 +101,7 @@ int git_threads_init(void) ...@@ -101,7 +101,7 @@ int git_threads_init(void)
while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); } while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
/* Only do work on a 0 -> 1 transition of the refcount */ /* Only do work on a 0 -> 1 transition of the refcount */
if (1 == ++_n_inits) if (1 == git_atomic_inc(&git__n_inits))
error = synchronized_threads_init(); error = synchronized_threads_init();
/* Exit the lock */ /* Exit the lock */
...@@ -124,7 +124,7 @@ void git_threads_shutdown(void) ...@@ -124,7 +124,7 @@ void git_threads_shutdown(void)
while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); } while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
/* Only do work on a 1 -> 0 transition of the refcount */ /* Only do work on a 1 -> 0 transition of the refcount */
if (0 == --_n_inits) if (0 == git_atomic_dec(&git__n_inits))
synchronized_threads_shutdown(); synchronized_threads_shutdown();
/* Exit the lock */ /* Exit the lock */
...@@ -135,7 +135,7 @@ git_global_st *git__global_state(void) ...@@ -135,7 +135,7 @@ git_global_st *git__global_state(void)
{ {
void *ptr; void *ptr;
assert(_n_inits); assert(git_atomic_get(&git__n_inits) > 0);
if ((ptr = TlsGetValue(_tls_index)) != NULL) if ((ptr = TlsGetValue(_tls_index)) != NULL)
return ptr; return ptr;
...@@ -153,7 +153,6 @@ git_global_st *git__global_state(void) ...@@ -153,7 +153,6 @@ git_global_st *git__global_state(void)
static pthread_key_t _tls_key; static pthread_key_t _tls_key;
static pthread_once_t _once_init = PTHREAD_ONCE_INIT; static pthread_once_t _once_init = PTHREAD_ONCE_INIT;
static git_atomic git__n_inits;
int init_error = 0; int init_error = 0;
static void cb__free_status(void *st) static void cb__free_status(void *st)
...@@ -204,7 +203,7 @@ git_global_st *git__global_state(void) ...@@ -204,7 +203,7 @@ git_global_st *git__global_state(void)
{ {
void *ptr; void *ptr;
assert(git__n_inits.val); assert(git_atomic_get(&git__n_inits) > 0);
if ((ptr = pthread_getspecific(_tls_key)) != NULL) if ((ptr = pthread_getspecific(_tls_key)) != NULL)
return ptr; return ptr;
...@@ -224,14 +223,15 @@ static git_global_st __state; ...@@ -224,14 +223,15 @@ static git_global_st __state;
int git_threads_init(void) int git_threads_init(void)
{ {
/* noop */ git_atomic_inc(&git__n_inits);
return 0; return 0;
} }
void git_threads_shutdown(void) void git_threads_shutdown(void)
{ {
/* Shut down any subsystems that have global state */ /* Shut down any subsystems that have global state */
git__shutdown(); if (0 == git_atomic_dec(&git__n_inits))
git__shutdown();
} }
git_global_st *git__global_state(void) git_global_st *git__global_state(void)
......
...@@ -18,11 +18,12 @@ static void run_in_parallel( ...@@ -18,11 +18,12 @@ static void run_in_parallel(
int r, t, *id = git__calloc(threads, sizeof(int)); int r, t, *id = git__calloc(threads, sizeof(int));
#ifdef GIT_THREADS #ifdef GIT_THREADS
git_thread *th = git__calloc(threads, sizeof(git_thread)); git_thread *th = git__calloc(threads, sizeof(git_thread));
cl_assert(th != NULL);
#else #else
void *th = NULL; void *th = NULL;
#endif #endif
cl_assert(id != NULL && th != NULL); cl_assert(id != NULL);
for (r = 0; r < repeats; ++r) { for (r = 0; r < repeats; ++r) {
_repo = cl_git_sandbox_reopen(); /* reopen sandbox to flush caches */ _repo = cl_git_sandbox_reopen(); /* reopen sandbox to flush caches */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment