mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-30 22:01:50 +00:00
threads: split up OS-dependent mutex code
This commit is contained in:
parent
faebc1c6ec
commit
1c13540510
@ -40,17 +40,12 @@ typedef git_atomic git_atomic_ssize;
|
|||||||
|
|
||||||
#ifdef GIT_THREADS
|
#ifdef GIT_THREADS
|
||||||
|
|
||||||
#if !defined(GIT_WIN32)
|
#ifdef GIT_WIN32
|
||||||
|
# include "win32/pthread.h"
|
||||||
|
#else
|
||||||
# include "unix/pthread.h"
|
# include "unix/pthread.h"
|
||||||
#endif
|
#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 */
|
/* Pthreads condition vars */
|
||||||
#define git_cond pthread_cond_t
|
#define git_cond pthread_cond_t
|
||||||
#define git_cond_init(c) pthread_cond_init(c, NULL)
|
#define git_cond_init(c) pthread_cond_init(c, NULL)
|
||||||
|
@ -17,4 +17,11 @@ typedef struct {
|
|||||||
#define git_thread_join(git_thread_ptr, status) \
|
#define git_thread_join(git_thread_ptr, status) \
|
||||||
pthread_join((git_thread_ptr)->thread, 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__ */
|
#endif /* INCLUDE_unix_pthread_h__ */
|
||||||
|
@ -67,28 +67,25 @@ int git_thread_join(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_mutex_init(
|
int git_mutex_init(git_mutex *GIT_RESTRICT mutex)
|
||||||
pthread_mutex_t *GIT_RESTRICT mutex,
|
|
||||||
const pthread_mutexattr_t *GIT_RESTRICT mutexattr)
|
|
||||||
{
|
{
|
||||||
GIT_UNUSED(mutexattr);
|
|
||||||
InitializeCriticalSection(mutex);
|
InitializeCriticalSection(mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_mutex_destroy(pthread_mutex_t *mutex)
|
int git_mutex_free(git_mutex *mutex)
|
||||||
{
|
{
|
||||||
DeleteCriticalSection(mutex);
|
DeleteCriticalSection(mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_mutex_lock(pthread_mutex_t *mutex)
|
int git_mutex_lock(git_mutex *mutex)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(mutex);
|
EnterCriticalSection(mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_mutex_unlock(pthread_mutex_t *mutex)
|
int git_mutex_unlock(git_mutex *mutex)
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(mutex);
|
LeaveCriticalSection(mutex);
|
||||||
return 0;
|
return 0;
|
||||||
@ -124,7 +121,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
|
|||||||
return 0;
|
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;
|
int error;
|
||||||
DWORD wait_result;
|
DWORD wait_result;
|
||||||
@ -133,7 +130,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
/* The caller must be holding the mutex. */
|
/* The caller must be holding the mutex. */
|
||||||
error = pthread_mutex_unlock(mutex);
|
error = git_mutex_unlock(mutex);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return 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);
|
assert(WAIT_OBJECT_0 == wait_result);
|
||||||
GIT_UNUSED(wait_result);
|
GIT_UNUSED(wait_result);
|
||||||
|
|
||||||
return pthread_mutex_lock(mutex);
|
return git_mutex_lock(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_cond_signal(pthread_cond_t *cond)
|
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_attr_t;
|
||||||
typedef int pthread_rwlockattr_t;
|
typedef int pthread_rwlockattr_t;
|
||||||
|
|
||||||
typedef CRITICAL_SECTION pthread_mutex_t;
|
typedef CRITICAL_SECTION git_mutex;
|
||||||
typedef HANDLE pthread_cond_t;
|
typedef HANDLE pthread_cond_t;
|
||||||
|
|
||||||
typedef struct { void *Ptr; } GIT_SRWLOCK;
|
typedef struct { void *Ptr; } GIT_SRWLOCK;
|
||||||
@ -47,16 +47,14 @@ int git_thread_create(git_thread *GIT_RESTRICT,
|
|||||||
void *GIT_RESTRICT);
|
void *GIT_RESTRICT);
|
||||||
int git_thread_join(git_thread *, void **);
|
int git_thread_join(git_thread *, void **);
|
||||||
|
|
||||||
int pthread_mutex_init(
|
int git_mutex_init(git_mutex *GIT_RESTRICT mutex);
|
||||||
pthread_mutex_t *GIT_RESTRICT mutex,
|
int git_mutex_free(git_mutex *);
|
||||||
const pthread_mutexattr_t *GIT_RESTRICT mutexattr);
|
int git_mutex_lock(git_mutex *);
|
||||||
int pthread_mutex_destroy(pthread_mutex_t *);
|
int git_mutex_unlock(git_mutex *);
|
||||||
int pthread_mutex_lock(pthread_mutex_t *);
|
|
||||||
int pthread_mutex_unlock(pthread_mutex_t *);
|
|
||||||
|
|
||||||
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
|
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
|
||||||
int pthread_cond_destroy(pthread_cond_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 *);
|
int pthread_cond_signal(pthread_cond_t *);
|
||||||
/* pthread_cond_broadcast is not supported on Win32 yet. */
|
/* pthread_cond_broadcast is not supported on Win32 yet. */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user