diff options
| author | Russell Belfer <rb@github.com> | 2013-08-22 14:10:56 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-08-22 14:10:56 -0700 |
| commit | 972bb689c4a69ba5a5dfaeebacc7198622c4f051 (patch) | |
| tree | 563f1ac8a33f5d44f32be76ea5d7fc862cec8457 /src | |
| parent | 2b6e1908476c95c84d3e3a62ac069f789156b070 (diff) | |
| download | libgit2-972bb689c4a69ba5a5dfaeebacc7198622c4f051.tar.gz | |
Add SRWLock implementation of rwlocks for Win32
Diffstat (limited to 'src')
| -rw-r--r-- | src/thread-utils.h | 9 | ||||
| -rw-r--r-- | src/win32/pthread.c | 38 | ||||
| -rw-r--r-- | src/win32/pthread.h | 14 |
3 files changed, 58 insertions, 3 deletions
diff --git a/src/thread-utils.h b/src/thread-utils.h index ffcdb4ab0..819e24e7b 100644 --- a/src/thread-utils.h +++ b/src/thread-utils.h @@ -66,12 +66,17 @@ typedef git_atomic git_atomic_ssize; #define git_rwlock pthread_rwlock_t #define git_rwlock_init(a) pthread_rwlock_init(a, NULL) #define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a) -#define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a) +#define git_rwlock_rdunlock(a) pthread_rwlock_rdunlock(a) #define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a) -#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a) +#define git_rwlock_wrunlock(a) pthread_rwlock_wrunlock(a) #define git_rwlock_free(a) pthread_rwlock_destroy(a) #define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER +#ifndef GIT_WIN32 +#define pthread_rwlock_rdunlock pthread_rwlock_unlock +#define pthread_rwlock_wrunlock pthread_rwlock_unlock +#endif + GIT_INLINE(void) git_atomic_set(git_atomic *a, int val) { diff --git a/src/win32/pthread.c b/src/win32/pthread.c index 2f263b3e0..41cb7a4c0 100644 --- a/src/win32/pthread.c +++ b/src/win32/pthread.c @@ -142,3 +142,41 @@ int pthread_num_processors_np(void) return n ? n : 1; } +int pthread_rwlock_init( + pthread_rwlock_t *GIT_RESTRICT lock, + const pthread_rwlockattr_t *GIT_RESTRICT attr) +{ + (void)attr; + InitializeSRWLock(lock); + return 0; +} + +int pthread_rwlock_rdlock(pthread_rwlock_t *lock) +{ + AcquireSRWLockShared(lock); + return 0; +} + +int pthread_rwlock_rdunlock(pthread_rwlock_t *lock) +{ + ReleaseSRWLockShared(lock); + return 0; +} + +int pthread_rwlock_wrlock(pthread_rwlock_t *lock) +{ + AcquireSRWLockExclusive(lock); + return 0; +} + +int pthread_rwlock_wrunlock(pthread_rwlock_t *lock) +{ + ReleaseSRWLockExclusive(lock); + return 0; +} + +int pthread_rwlock_destroy(pthread_rwlock_t *lock) +{ + (void)lock; + return 0; +} diff --git a/src/win32/pthread.h b/src/win32/pthread.h index 8277ecf6e..54e5286a6 100644 --- a/src/win32/pthread.h +++ b/src/win32/pthread.h @@ -19,11 +19,15 @@ typedef int pthread_mutexattr_t; typedef int pthread_condattr_t; typedef int pthread_attr_t; +typedef int pthread_rwlockattr_t; + typedef CRITICAL_SECTION pthread_mutex_t; typedef HANDLE pthread_t; typedef HANDLE pthread_cond_t; +typedef SRWLOCK pthread_rwlock_t; -#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}; +#define PTHREAD_MUTEX_INITIALIZER {(void*)-1} +#define PTHREAD_RWLOCK_INITIALIZER SRWLOCK_INIT int pthread_create( pthread_t *GIT_RESTRICT, @@ -47,4 +51,12 @@ int pthread_cond_signal(pthread_cond_t *); int pthread_num_processors_np(void); +int pthread_rwlock_init( + pthread_rwlock_t *GIT_RESTRICT, const pthread_rwlockattr_t *GIT_RESTRICT); +int pthread_rwlock_rdlock(pthread_rwlock_t *); +int pthread_rwlock_rdunlock(pthread_rwlock_t *); +int pthread_rwlock_wrlock(pthread_rwlock_t *); +int pthread_rwlock_wrunlock(pthread_rwlock_t *); +int pthread_rwlock_destroy(pthread_rwlock_t *); + #endif |
