1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
| | #ifndef THREAD_COMPAT_H
#define THREAD_COMPAT_H
#ifndef NO_PTHREADS
#include <pthread.h>
#define HAVE_THREADS 1
#else
#define HAVE_THREADS 0
/*
* macros instead of typedefs because pthread definitions may have
* been pulled in by some system dependencies even though the user
* wants to disable pthread.
*/
#define pthread_t int
#define pthread_mutex_t int
#define pthread_cond_t int
#define pthread_key_t git_pthread_key_t
#define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)
#define pthread_mutex_lock(mutex)
#define pthread_mutex_unlock(mutex)
#define pthread_mutex_destroy(mutex)
#define pthread_cond_init(cond, attr) dummy_pthread_init(cond)
#define pthread_cond_wait(cond, mutex)
#define pthread_cond_signal(cond)
#define pthread_cond_broadcast(cond)
#define pthread_cond_destroy(cond)
#define pthread_key_create(key, destroy) git_pthread_key_create(key, destroy)
#define pthread_key_delete(key) git_pthread_key_delete(key)
#define pthread_create(thread, attr, fn, data) \
dummy_pthread_create(thread, attr, fn, data)
#define pthread_join(thread, retval) \
dummy_pthread_join(thread, retval)
#define pthread_setspecific(key, data) git_pthread_setspecific(key, data)
#define pthread_getspecific(key) git_pthread_getspecific(key)
typedef struct {
void *data;
/* extra indirection because setspecific is passed key by value */
void **vdata;
} git_pthread_key_t;
static inline int git_pthread_key_create(git_pthread_key_t *key,
void (*destroy)(void *))
{
key->data = NULL;
key->vdata = &key->data;
/* We don't use this; alternatively we could all via atexit(). */
if (destroy)
BUG("NO_PTHREADS does not support pthread key destructors");
return 0;
}
static inline int git_pthread_key_delete(git_pthread_key_t key)
{
/* noop */
return 0;
}
static inline void git_pthread_setspecific(git_pthread_key_t key, void *data)
{
*(key.vdata) = data;
}
static inline void *git_pthread_getspecific(git_pthread_key_t key)
{
return key.data;
}
int dummy_pthread_create(pthread_t *pthread, const void *attr,
void *(*fn)(void *), void *data);
int dummy_pthread_join(pthread_t pthread, void **retval);
int dummy_pthread_init(void *);
#endif
int online_cpus(void);
int init_recursive_mutex(pthread_mutex_t*);
#endif /* THREAD_COMPAT_H */
|