]>
Commit | Line | Data |
---|---|---|
faebc1c6 PS |
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 | ||
c25aa7cd PP |
15 | GIT_INLINE(int) git_threads_global_init(void) { return 0; } |
16 | ||
faebc1c6 PS |
17 | #define git_thread_create(git_thread_ptr, start_routine, arg) \ |
18 | pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg) | |
19 | #define git_thread_join(git_thread_ptr, status) \ | |
20 | pthread_join((git_thread_ptr)->thread, status) | |
82f15896 ET |
21 | #define git_thread_currentid() ((size_t)(pthread_self())) |
22 | #define git_thread_exit(retval) pthread_exit(retval) | |
faebc1c6 | 23 | |
1c135405 PS |
24 | /* Git Mutex */ |
25 | #define git_mutex pthread_mutex_t | |
26 | #define git_mutex_init(a) pthread_mutex_init(a, NULL) | |
27 | #define git_mutex_lock(a) pthread_mutex_lock(a) | |
28 | #define git_mutex_unlock(a) pthread_mutex_unlock(a) | |
29 | #define git_mutex_free(a) pthread_mutex_destroy(a) | |
30 | ||
139bffa0 PS |
31 | /* Git condition vars */ |
32 | #define git_cond pthread_cond_t | |
33 | #define git_cond_init(c) pthread_cond_init(c, NULL) | |
34 | #define git_cond_free(c) pthread_cond_destroy(c) | |
35 | #define git_cond_wait(c, l) pthread_cond_wait(c, l) | |
36 | #define git_cond_signal(c) pthread_cond_signal(c) | |
37 | #define git_cond_broadcast(c) pthread_cond_broadcast(c) | |
38 | ||
6551004f PS |
39 | /* Pthread (-ish) rwlock |
40 | * | |
41 | * This differs from normal pthreads rwlocks in two ways: | |
42 | * 1. Separate APIs for releasing read locks and write locks (as | |
43 | * opposed to the pure POSIX API which only has one unlock fn) | |
44 | * 2. You should not use recursive read locks (i.e. grabbing a read | |
45 | * lock in a thread that already holds a read lock) because the | |
46 | * Windows implementation doesn't support it | |
47 | */ | |
48 | #define git_rwlock pthread_rwlock_t | |
49 | #define git_rwlock_init(a) pthread_rwlock_init(a, NULL) | |
50 | #define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a) | |
51 | #define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a) | |
52 | #define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a) | |
53 | #define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a) | |
54 | #define git_rwlock_free(a) pthread_rwlock_destroy(a) | |
55 | #define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER | |
56 | ||
eae0bfdc | 57 | #endif |