1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 
8 #ifndef INCLUDE_unix_pthread_h__
9 #define INCLUDE_unix_pthread_h__
10 
11 typedef struct {
12 	pthread_t thread;
13 } git_thread;
14 
15 #define git_threads_init() (void)0
16 #define git_thread_create(git_thread_ptr, start_routine, arg) \
17 	pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
18 #define git_thread_join(git_thread_ptr, status) \
19 	pthread_join((git_thread_ptr)->thread, status)
20 #define git_thread_currentid() ((size_t)(pthread_self()))
21 #define git_thread_exit(retval) pthread_exit(retval)
22 
23 /* Git Mutex */
24 #define git_mutex pthread_mutex_t
25 #define git_mutex_init(a)	pthread_mutex_init(a, NULL)
26 #define git_mutex_lock(a)	pthread_mutex_lock(a)
27 #define git_mutex_unlock(a)     pthread_mutex_unlock(a)
28 #define git_mutex_free(a)	pthread_mutex_destroy(a)
29 
30 /* Git condition vars */
31 #define git_cond pthread_cond_t
32 #define git_cond_init(c)	pthread_cond_init(c, NULL)
33 #define git_cond_free(c) 	pthread_cond_destroy(c)
34 #define git_cond_wait(c, l)	pthread_cond_wait(c, l)
35 #define git_cond_signal(c)	pthread_cond_signal(c)
36 #define git_cond_broadcast(c)	pthread_cond_broadcast(c)
37 
38 /* Pthread (-ish) rwlock
39  *
40  * This differs from normal pthreads rwlocks in two ways:
41  * 1. Separate APIs for releasing read locks and write locks (as
42  *    opposed to the pure POSIX API which only has one unlock fn)
43  * 2. You should not use recursive read locks (i.e. grabbing a read
44  *    lock in a thread that already holds a read lock) because the
45  *    Windows implementation doesn't support it
46  */
47 #define git_rwlock              pthread_rwlock_t
48 #define git_rwlock_init(a)	pthread_rwlock_init(a, NULL)
49 #define git_rwlock_rdlock(a)	pthread_rwlock_rdlock(a)
50 #define git_rwlock_rdunlock(a)	pthread_rwlock_unlock(a)
51 #define git_rwlock_wrlock(a)	pthread_rwlock_wrlock(a)
52 #define git_rwlock_wrunlock(a)	pthread_rwlock_unlock(a)
53 #define git_rwlock_free(a)	pthread_rwlock_destroy(a)
54 #define GIT_RWLOCK_STATIC_INIT	PTHREAD_RWLOCK_INITIALIZER
55 
56 #endif
57