threads: split up OS-dependent rwlock code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 1eb51de..f75e440 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -46,30 +46,6 @@ typedef git_atomic git_atomic_ssize;
# include "unix/pthread.h"
#endif
-/* Pthread (-ish) rwlock
- *
- * This differs from normal pthreads rwlocks in two ways:
- * 1. Separate APIs for releasing read locks and write locks (as
- * opposed to the pure POSIX API which only has one unlock fn)
- * 2. You should not use recursive read locks (i.e. grabbing a read
- * lock in a thread that already holds a read lock) because the
- * Windows implementation doesn't support it
- */
-#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_rdunlock(a)
-#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(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)
{
#if defined(GIT_WIN32)
diff --git a/src/unix/pthread.h b/src/unix/pthread.h
index 0cba59b..773ce22 100644
--- a/src/unix/pthread.h
+++ b/src/unix/pthread.h
@@ -32,4 +32,22 @@ typedef struct {
#define git_cond_signal(c) pthread_cond_signal(c)
#define git_cond_broadcast(c) pthread_cond_broadcast(c)
+/* Pthread (-ish) rwlock
+ *
+ * This differs from normal pthreads rwlocks in two ways:
+ * 1. Separate APIs for releasing read locks and write locks (as
+ * opposed to the pure POSIX API which only has one unlock fn)
+ * 2. You should not use recursive read locks (i.e. grabbing a read
+ * lock in a thread that already holds a read lock) because the
+ * Windows implementation doesn't support it
+ */
+#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_wrlock(a) pthread_rwlock_wrlock(a)
+#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a)
+#define git_rwlock_free(a) pthread_rwlock_destroy(a)
+#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
+
#endif /* INCLUDE_unix_pthread_h__ */
diff --git a/src/win32/pthread.c b/src/win32/pthread.c
index 9ce062a..62a691d 100644
--- a/src/win32/pthread.c
+++ b/src/win32/pthread.c
@@ -172,12 +172,8 @@ static win32_srwlock_fn win32_srwlock_release_shared;
static win32_srwlock_fn win32_srwlock_acquire_exclusive;
static win32_srwlock_fn win32_srwlock_release_exclusive;
-int pthread_rwlock_init(
- pthread_rwlock_t *GIT_RESTRICT lock,
- const pthread_rwlockattr_t *GIT_RESTRICT attr)
+int git_rwlock_init(git_rwlock *GIT_RESTRICT lock)
{
- GIT_UNUSED(attr);
-
if (win32_srwlock_initialize)
win32_srwlock_initialize(&lock->native.srwl);
else
@@ -186,7 +182,7 @@ int pthread_rwlock_init(
return 0;
}
-int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
+int git_rwlock_rdlock(git_rwlock *lock)
{
if (win32_srwlock_acquire_shared)
win32_srwlock_acquire_shared(&lock->native.srwl);
@@ -196,7 +192,7 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
return 0;
}
-int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
+int git_rwlock_rdunlock(git_rwlock *lock)
{
if (win32_srwlock_release_shared)
win32_srwlock_release_shared(&lock->native.srwl);
@@ -206,7 +202,7 @@ int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
return 0;
}
-int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
+int git_rwlock_wrlock(git_rwlock *lock)
{
if (win32_srwlock_acquire_exclusive)
win32_srwlock_acquire_exclusive(&lock->native.srwl);
@@ -216,7 +212,7 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
return 0;
}
-int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
+int git_rwlock_wrunlock(git_rwlock *lock)
{
if (win32_srwlock_release_exclusive)
win32_srwlock_release_exclusive(&lock->native.srwl);
@@ -226,7 +222,7 @@ int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
return 0;
}
-int pthread_rwlock_destroy(pthread_rwlock_t *lock)
+int git_rwlock_free(git_rwlock *lock)
{
if (!win32_srwlock_initialize)
DeleteCriticalSection(&lock->native.csec);
diff --git a/src/win32/pthread.h b/src/win32/pthread.h
index 35cb810..ef92855 100644
--- a/src/win32/pthread.h
+++ b/src/win32/pthread.h
@@ -38,7 +38,7 @@ typedef struct {
GIT_SRWLOCK srwl;
CRITICAL_SECTION csec;
} native;
-} pthread_rwlock_t;
+} git_rwlock;
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
@@ -59,14 +59,12 @@ int git_cond_signal(git_cond *);
int pthread_num_processors_np(void);
-int pthread_rwlock_init(
- pthread_rwlock_t *GIT_RESTRICT lock,
- const pthread_rwlockattr_t *GIT_RESTRICT attr);
-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 *);
+int git_rwlock_init(git_rwlock *GIT_RESTRICT lock);
+int git_rwlock_rdlock(git_rwlock *);
+int git_rwlock_rdunlock(git_rwlock *);
+int git_rwlock_wrlock(git_rwlock *);
+int git_rwlock_wrunlock(git_rwlock *);
+int git_rwlock_free(git_rwlock *);
extern int win32_pthread_initialize(void);