File Coverage

deps/libgit2/src/util/unix/pthread.h
Criterion Covered Total %
statement 1 1 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 1 1 100.0


line stmt bran cond sub pod time code
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 174           GIT_INLINE(int) git_threads_global_init(void) { return 0; }
16              
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)
21             #define git_thread_currentid() ((size_t)(pthread_self()))
22             #define git_thread_exit(retval) pthread_exit(retval)
23              
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              
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              
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              
57             #endif