Commit 1c135405 by Patrick Steinhardt

threads: split up OS-dependent mutex code

parent faebc1c6
......@@ -40,17 +40,12 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
#if !defined(GIT_WIN32)
#ifdef GIT_WIN32
# include "win32/pthread.h"
#else
# include "unix/pthread.h"
#endif
/* Pthreads Mutex */
#define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
#define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a)
/* Pthreads condition vars */
#define git_cond pthread_cond_t
#define git_cond_init(c) pthread_cond_init(c, NULL)
......
......@@ -17,4 +17,11 @@ typedef struct {
#define git_thread_join(git_thread_ptr, status) \
pthread_join((git_thread_ptr)->thread, status)
/* Git Mutex */
#define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
#define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a)
#endif /* INCLUDE_unix_pthread_h__ */
......@@ -67,28 +67,25 @@ int git_thread_join(
return 0;
}
int pthread_mutex_init(
pthread_mutex_t *GIT_RESTRICT mutex,
const pthread_mutexattr_t *GIT_RESTRICT mutexattr)
int git_mutex_init(git_mutex *GIT_RESTRICT mutex)
{
GIT_UNUSED(mutexattr);
InitializeCriticalSection(mutex);
return 0;
}
int pthread_mutex_destroy(pthread_mutex_t *mutex)
int git_mutex_free(git_mutex *mutex)
{
DeleteCriticalSection(mutex);
return 0;
}
int pthread_mutex_lock(pthread_mutex_t *mutex)
int git_mutex_lock(git_mutex *mutex)
{
EnterCriticalSection(mutex);
return 0;
}
int pthread_mutex_unlock(pthread_mutex_t *mutex)
int git_mutex_unlock(git_mutex *mutex)
{
LeaveCriticalSection(mutex);
return 0;
......@@ -124,7 +121,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
return 0;
}
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
int pthread_cond_wait(pthread_cond_t *cond, git_mutex *mutex)
{
int error;
DWORD wait_result;
......@@ -133,7 +130,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
return EINVAL;
/* The caller must be holding the mutex. */
error = pthread_mutex_unlock(mutex);
error = git_mutex_unlock(mutex);
if (error)
return error;
......@@ -142,7 +139,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
assert(WAIT_OBJECT_0 == wait_result);
GIT_UNUSED(wait_result);
return pthread_mutex_lock(mutex);
return git_mutex_lock(mutex);
}
int pthread_cond_signal(pthread_cond_t *cond)
......
......@@ -28,7 +28,7 @@ typedef int pthread_condattr_t;
typedef int pthread_attr_t;
typedef int pthread_rwlockattr_t;
typedef CRITICAL_SECTION pthread_mutex_t;
typedef CRITICAL_SECTION git_mutex;
typedef HANDLE pthread_cond_t;
typedef struct { void *Ptr; } GIT_SRWLOCK;
......@@ -47,16 +47,14 @@ int git_thread_create(git_thread *GIT_RESTRICT,
void *GIT_RESTRICT);
int git_thread_join(git_thread *, void **);
int pthread_mutex_init(
pthread_mutex_t *GIT_RESTRICT mutex,
const pthread_mutexattr_t *GIT_RESTRICT mutexattr);
int pthread_mutex_destroy(pthread_mutex_t *);
int pthread_mutex_lock(pthread_mutex_t *);
int pthread_mutex_unlock(pthread_mutex_t *);
int git_mutex_init(git_mutex *GIT_RESTRICT mutex);
int git_mutex_free(git_mutex *);
int git_mutex_lock(git_mutex *);
int git_mutex_unlock(git_mutex *);
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
int pthread_cond_destroy(pthread_cond_t *);
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
int pthread_cond_wait(pthread_cond_t *, git_mutex *);
int pthread_cond_signal(pthread_cond_t *);
/* pthread_cond_broadcast is not supported on Win32 yet. */
......
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