Skip to content

Commit 139bffa

Browse files
committed
threads: split up OS-dependent thread-condition code
1 parent 20d078d commit 139bffa

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/thread-utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ typedef git_atomic git_atomic_ssize;
4646
# include "unix/pthread.h"
4747
#endif
4848

49-
/* Pthreads condition vars */
50-
#define git_cond pthread_cond_t
51-
#define git_cond_init(c) pthread_cond_init(c, NULL)
52-
#define git_cond_free(c) pthread_cond_destroy(c)
53-
#define git_cond_wait(c, l) pthread_cond_wait(c, l)
54-
#define git_cond_signal(c) pthread_cond_signal(c)
55-
5649
/* Pthread (-ish) rwlock
5750
*
5851
* This differs from normal pthreads rwlocks in two ways:

src/unix/pthread.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ typedef struct {
2424
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
2525
#define git_mutex_free(a) pthread_mutex_destroy(a)
2626

27+
/* Git condition vars */
28+
#define git_cond pthread_cond_t
29+
#define git_cond_init(c) pthread_cond_init(c, NULL)
30+
#define git_cond_free(c) pthread_cond_destroy(c)
31+
#define git_cond_wait(c, l) pthread_cond_wait(c, l)
32+
#define git_cond_signal(c) pthread_cond_signal(c)
33+
#define git_cond_broadcast(c) pthread_cond_broadcast(c)
34+
2735
#endif /* INCLUDE_unix_pthread_h__ */

src/win32/pthread.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,8 @@ int git_mutex_unlock(git_mutex *mutex)
9191
return 0;
9292
}
9393

94-
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
94+
int git_cond_init(git_cond *cond)
9595
{
96-
/* We don't support non-default attributes. */
97-
if (attr)
98-
return EINVAL;
99-
10096
/* This is an auto-reset event. */
10197
*cond = CreateEventW(NULL, FALSE, FALSE, NULL);
10298
assert(*cond);
@@ -106,7 +102,7 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
106102
return *cond ? 0 : ENOMEM;
107103
}
108104

109-
int pthread_cond_destroy(pthread_cond_t *cond)
105+
int git_cond_free(git_cond *cond)
110106
{
111107
BOOL closed;
112108

@@ -121,7 +117,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
121117
return 0;
122118
}
123119

124-
int pthread_cond_wait(pthread_cond_t *cond, git_mutex *mutex)
120+
int git_cond_wait(git_cond *cond, git_mutex *mutex)
125121
{
126122
int error;
127123
DWORD wait_result;
@@ -142,7 +138,7 @@ int pthread_cond_wait(pthread_cond_t *cond, git_mutex *mutex)
142138
return git_mutex_lock(mutex);
143139
}
144140

145-
int pthread_cond_signal(pthread_cond_t *cond)
141+
int git_cond_signal(git_cond *cond)
146142
{
147143
BOOL signaled;
148144

src/win32/pthread.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef int pthread_attr_t;
2929
typedef int pthread_rwlockattr_t;
3030

3131
typedef CRITICAL_SECTION git_mutex;
32-
typedef HANDLE pthread_cond_t;
32+
typedef HANDLE git_cond;
3333

3434
typedef struct { void *Ptr; } GIT_SRWLOCK;
3535

@@ -52,10 +52,10 @@ int git_mutex_free(git_mutex *);
5252
int git_mutex_lock(git_mutex *);
5353
int git_mutex_unlock(git_mutex *);
5454

55-
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
56-
int pthread_cond_destroy(pthread_cond_t *);
57-
int pthread_cond_wait(pthread_cond_t *, git_mutex *);
58-
int pthread_cond_signal(pthread_cond_t *);
55+
int git_cond_init(git_cond *);
56+
int git_cond_free(git_cond *);
57+
int git_cond_wait(git_cond *, git_mutex *);
58+
int git_cond_signal(git_cond *);
5959

6060
int pthread_num_processors_np(void);
6161

0 commit comments

Comments
 (0)