Commit c6289186 by Russell Belfer Committed by Vicent Marti

Fixes for Windows cas/threading stuff

parent e976b56d
...@@ -71,16 +71,15 @@ GIT_INLINE(int) git_atomic_dec(git_atomic *a) ...@@ -71,16 +71,15 @@ GIT_INLINE(int) git_atomic_dec(git_atomic *a)
GIT_INLINE(void *) git___compare_and_swap( GIT_INLINE(void *) git___compare_and_swap(
volatile void **ptr, void *oldval, void *newval) volatile void **ptr, void *oldval, void *newval)
{ {
bool swapped; void *foundval;
#if defined(GIT_WIN32) #if defined(GIT_WIN32)
swapped = ((LONGLONG)oldval == InterlockedCompareExchange64( foundval = InterlockedCompareExchangePointer(ptr, newval, oldval);
(LONGLONG volatile *)ptr, (LONGLONG)newval, (LONGLONG)oldval));
#elif defined(__GNUC__) #elif defined(__GNUC__)
swapped = (__sync_val_compare_and_swap(ptr, oldval, newval) == oldval); foundval = __sync_val_compare_and_swap(ptr, oldval, newval);
#else #else
# error "Unsupported architecture for atomic operations" # error "Unsupported architecture for atomic operations"
#endif #endif
return swapped ? oldval : newval; return (foundval == oldval) ? oldval : newval;
} }
#else #else
......
...@@ -14,18 +14,23 @@ int pthread_create( ...@@ -14,18 +14,23 @@ int pthread_create(
void *GIT_RESTRICT arg) void *GIT_RESTRICT arg)
{ {
GIT_UNUSED(attr); GIT_UNUSED(attr);
*thread = (pthread_t) CreateThread( *thread = CreateThread(
NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
return *thread ? 0 : -1; return *thread ? 0 : -1;
} }
int pthread_join(pthread_t thread, void **value_ptr) int pthread_join(pthread_t thread, void **value_ptr)
{ {
int ret; DWORD ret = WaitForSingleObject(thread, INFINITE);
ret = WaitForSingleObject(thread, INFINITE);
if (ret && value_ptr) if (ret == WAIT_OBJECT_0) {
GetExitCodeThread(thread, (void*) value_ptr); if (value_ptr != NULL)
return -(!!ret); GetExitCodeThread(thread, (void *)value_ptr);
CloseHandle(thread);
return 0;
}
return -1;
} }
int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex, int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex,
......
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