threads: split up OS-dependent thread-condition 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
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 5073c2a..1eb51de 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -46,13 +46,6 @@ typedef git_atomic git_atomic_ssize;
# include "unix/pthread.h"
#endif
-/* Pthreads condition vars */
-#define git_cond pthread_cond_t
-#define git_cond_init(c) pthread_cond_init(c, NULL)
-#define git_cond_free(c) pthread_cond_destroy(c)
-#define git_cond_wait(c, l) pthread_cond_wait(c, l)
-#define git_cond_signal(c) pthread_cond_signal(c)
-
/* Pthread (-ish) rwlock
*
* This differs from normal pthreads rwlocks in two ways:
diff --git a/src/unix/pthread.h b/src/unix/pthread.h
index 7487cb5..0cba59b 100644
--- a/src/unix/pthread.h
+++ b/src/unix/pthread.h
@@ -24,4 +24,12 @@ typedef struct {
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a)
+/* Git condition vars */
+#define git_cond pthread_cond_t
+#define git_cond_init(c) pthread_cond_init(c, NULL)
+#define git_cond_free(c) pthread_cond_destroy(c)
+#define git_cond_wait(c, l) pthread_cond_wait(c, l)
+#define git_cond_signal(c) pthread_cond_signal(c)
+#define git_cond_broadcast(c) pthread_cond_broadcast(c)
+
#endif /* INCLUDE_unix_pthread_h__ */
diff --git a/src/win32/pthread.c b/src/win32/pthread.c
index abf0470..9ce062a 100644
--- a/src/win32/pthread.c
+++ b/src/win32/pthread.c
@@ -91,12 +91,8 @@ int git_mutex_unlock(git_mutex *mutex)
return 0;
}
-int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
+int git_cond_init(git_cond *cond)
{
- /* We don't support non-default attributes. */
- if (attr)
- return EINVAL;
-
/* This is an auto-reset event. */
*cond = CreateEventW(NULL, FALSE, FALSE, NULL);
assert(*cond);
@@ -106,7 +102,7 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
return *cond ? 0 : ENOMEM;
}
-int pthread_cond_destroy(pthread_cond_t *cond)
+int git_cond_free(git_cond *cond)
{
BOOL closed;
@@ -121,7 +117,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
return 0;
}
-int pthread_cond_wait(pthread_cond_t *cond, git_mutex *mutex)
+int git_cond_wait(git_cond *cond, git_mutex *mutex)
{
int error;
DWORD wait_result;
@@ -142,7 +138,7 @@ int pthread_cond_wait(pthread_cond_t *cond, git_mutex *mutex)
return git_mutex_lock(mutex);
}
-int pthread_cond_signal(pthread_cond_t *cond)
+int git_cond_signal(git_cond *cond)
{
BOOL signaled;
diff --git a/src/win32/pthread.h b/src/win32/pthread.h
index 9d314c8..35cb810 100644
--- a/src/win32/pthread.h
+++ b/src/win32/pthread.h
@@ -29,7 +29,7 @@ typedef int pthread_attr_t;
typedef int pthread_rwlockattr_t;
typedef CRITICAL_SECTION git_mutex;
-typedef HANDLE pthread_cond_t;
+typedef HANDLE git_cond;
typedef struct { void *Ptr; } GIT_SRWLOCK;
@@ -52,10 +52,10 @@ 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 *, git_mutex *);
-int pthread_cond_signal(pthread_cond_t *);
+int git_cond_init(git_cond *);
+int git_cond_free(git_cond *);
+int git_cond_wait(git_cond *, git_mutex *);
+int git_cond_signal(git_cond *);
int pthread_num_processors_np(void);