]>
git.proxmox.com Git - libgit2.git/blob - src/thread-utils.h
2 * Copyright (C) 2009-2012 the libgit2 contributors
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.
7 #ifndef INCLUDE_thread_utils_h__
8 #define INCLUDE_thread_utils_h__
12 /* Common operations even if threading has been disabled */
14 #if defined(GIT_WIN32)
21 GIT_INLINE(void) git_atomic_set(git_atomic
*a
, int val
)
28 #define git_thread pthread_t
29 #define git_thread_create(thread, attr, start_routine, arg) pthread_create(thread, attr, start_routine, arg)
30 #define git_thread_kill(thread) pthread_cancel(thread)
31 #define git_thread_exit(status) pthread_exit(status)
32 #define git_thread_join(id, status) pthread_join(id, status)
35 #define git_mutex pthread_mutex_t
36 #define git_mutex_init(a) pthread_mutex_init(a, NULL)
37 #define git_mutex_lock(a) pthread_mutex_lock(a)
38 #define git_mutex_unlock(a) pthread_mutex_unlock(a)
39 #define git_mutex_free(a) pthread_mutex_destroy(a)
41 /* Pthreads condition vars */
42 #define git_cond pthread_cond_t
43 #define git_cond_init(c) pthread_cond_init(c, NULL)
44 #define git_cond_free(c) pthread_cond_destroy(c)
45 #define git_cond_wait(c, l) pthread_cond_wait(c, l)
46 #define git_cond_signal(c) pthread_cond_signal(c)
47 #define git_cond_broadcast(c) pthread_cond_broadcast(c)
49 GIT_INLINE(int) git_atomic_inc(git_atomic
*a
)
51 #if defined(GIT_WIN32)
52 return InterlockedIncrement(&a
->val
);
53 #elif defined(__GNUC__)
54 return __sync_add_and_fetch(&a
->val
, 1);
56 # error "Unsupported architecture for atomic operations"
60 GIT_INLINE(int) git_atomic_dec(git_atomic
*a
)
62 #if defined(GIT_WIN32)
63 return InterlockedDecrement(&a
->val
);
64 #elif defined(__GNUC__)
65 return __sync_sub_and_fetch(&a
->val
, 1);
67 # error "Unsupported architecture for atomic operations"
73 #define git_thread unsigned int
74 #define git_thread_create(thread, attr, start_routine, arg) (void)0
75 #define git_thread_kill(thread) (void)0
76 #define git_thread_exit(status) (void)0
77 #define git_thread_join(id, status) (void)0
80 #define git_mutex unsigned int
81 #define git_mutex_init(a) (void)0
82 #define git_mutex_lock(a) 0
83 #define git_mutex_unlock(a) (void)0
84 #define git_mutex_free(a) (void)0
86 /* Pthreads condition vars */
87 #define git_cond unsigned int
88 #define git_cond_init(c, a) (void)0
89 #define git_cond_free(c) (void)0
90 #define git_cond_wait(c, l) (void)0
91 #define git_cond_signal(c) (void)0
92 #define git_cond_broadcast(c) (void)0
94 GIT_INLINE(int) git_atomic_inc(git_atomic
*a
)
99 GIT_INLINE(int) git_atomic_dec(git_atomic
*a
)
106 extern int git_online_cpus(void);
108 #endif /* INCLUDE_thread_utils_h__ */