/work/workdir/UnpackedTarball/fontconfig/src/fcmutex.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Atomic int and pointer operations. Originally copied from HarfBuzz. |
3 | | * |
4 | | * Copyright © 2007 Chris Wilson |
5 | | * Copyright © 2009,2010 Red Hat, Inc. |
6 | | * Copyright © 2011,2012,2013 Google, Inc. |
7 | | * |
8 | | * Permission is hereby granted, without written agreement and without |
9 | | * license or royalty fees, to use, copy, modify, and distribute this |
10 | | * software and its documentation for any purpose, provided that the |
11 | | * above copyright notice and the following two paragraphs appear in |
12 | | * all copies of this software. |
13 | | * |
14 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
15 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
16 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
17 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
18 | | * DAMAGE. |
19 | | * |
20 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
21 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
22 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
23 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
24 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
25 | | * |
26 | | * Contributor(s): |
27 | | * Chris Wilson <chris@chris-wilson.co.uk> |
28 | | * Red Hat Author(s): Behdad Esfahbod |
29 | | * Google Author(s): Behdad Esfahbod |
30 | | */ |
31 | | |
32 | | #ifndef _FCMUTEX_H_ |
33 | | #define _FCMUTEX_H_ |
34 | | |
35 | | #ifdef HAVE_CONFIG_H |
36 | | # include <config.h> |
37 | | #endif |
38 | | |
39 | | #define FC_STMT_START do |
40 | | #define FC_STMT_END while (0) |
41 | | |
42 | | /* mutex */ |
43 | | |
44 | | /* We need external help for these */ |
45 | | |
46 | | #if 0 |
47 | | |
48 | | #elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) |
49 | | |
50 | | # include "fcwindows.h" |
51 | | typedef CRITICAL_SECTION fc_mutex_impl_t; |
52 | | # define FC_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 } |
53 | | # define fc_mutex_impl_init(M) InitializeCriticalSection (M) |
54 | | # define fc_mutex_impl_lock(M) EnterCriticalSection (M) |
55 | | # define fc_mutex_impl_unlock(M) LeaveCriticalSection (M) |
56 | | # define fc_mutex_impl_finish(M) DeleteCriticalSection (M) |
57 | | |
58 | | #elif !defined(FC_NO_MT) && (defined(HAVE_PTHREAD) || defined(__APPLE__)) |
59 | | |
60 | | # include <pthread.h> |
61 | | typedef pthread_mutex_t fc_mutex_impl_t; |
62 | | # define FC_MUTEX_IMPL_INIT PTHREAD_MUTEX_INITIALIZER |
63 | 108 | # define fc_mutex_impl_init(M) pthread_mutex_init (M, NULL) |
64 | 12.9k | # define fc_mutex_impl_lock(M) pthread_mutex_lock (M) |
65 | 12.9k | # define fc_mutex_impl_unlock(M) pthread_mutex_unlock (M) |
66 | 0 | # define fc_mutex_impl_finish(M) pthread_mutex_destroy (M) |
67 | | |
68 | | #elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) |
69 | | |
70 | | # if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) |
71 | | # include <sched.h> |
72 | | # define FC_SCHED_YIELD() sched_yield() |
73 | | # else |
74 | | # define FC_SCHED_YIELD() \ |
75 | | FC_STMT_START {} \ |
76 | | FC_STMT_END |
77 | | # endif |
78 | | |
79 | | /* This actually is not a totally awful implementation. */ |
80 | | typedef volatile int fc_mutex_impl_t; |
81 | | # define FC_MUTEX_IMPL_INIT 0 |
82 | | # define fc_mutex_impl_init(M) *(M) = 0 |
83 | | # define fc_mutex_impl_lock(M) \ |
84 | | FC_STMT_START \ |
85 | | { \ |
86 | | while (__sync_lock_test_and_set ((M), 1)) \ |
87 | | FC_SCHED_YIELD(); \ |
88 | | } \ |
89 | | FC_STMT_END |
90 | | # define fc_mutex_impl_unlock(M) __sync_lock_release (M) |
91 | | # define fc_mutex_impl_finish(M) \ |
92 | | FC_STMT_START {} \ |
93 | | FC_STMT_END |
94 | | |
95 | | #elif !defined(FC_NO_MT) |
96 | | |
97 | | # if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) |
98 | | # include <sched.h> |
99 | | # define FC_SCHED_YIELD() sched_yield() |
100 | | # else |
101 | | # define FC_SCHED_YIELD() \ |
102 | | FC_STMT_START {} \ |
103 | | FC_STMT_END |
104 | | # endif |
105 | | |
106 | | # define FC_MUTEX_INT_NIL 1 /* Warn that fallback implementation is in use. */ |
107 | | typedef volatile int fc_mutex_impl_t; |
108 | | # define FC_MUTEX_IMPL_INIT 0 |
109 | | # define fc_mutex_impl_init(M) *(M) = 0 |
110 | | # define fc_mutex_impl_lock(M) \ |
111 | | FC_STMT_START \ |
112 | | { \ |
113 | | while (*(M)) \ |
114 | | FC_SCHED_YIELD(); \ |
115 | | (*(M))++; \ |
116 | | } \ |
117 | | FC_STMT_END |
118 | | # define fc_mutex_impl_unlock(M) (*(M))--; |
119 | | # define fc_mutex_impl_finish(M) \ |
120 | | FC_STMT_START {} \ |
121 | | FC_STMT_END |
122 | | |
123 | | #else /* FC_NO_MT */ |
124 | | |
125 | | typedef int fc_mutex_impl_t; |
126 | | # define FC_MUTEX_IMPL_INIT 0 |
127 | | # define fc_mutex_impl_init(M) \ |
128 | | FC_STMT_START {} \ |
129 | | FC_STMT_END |
130 | | # define fc_mutex_impl_lock(M) \ |
131 | | FC_STMT_START {} \ |
132 | | FC_STMT_END |
133 | | # define fc_mutex_impl_unlock(M) \ |
134 | | FC_STMT_START {} \ |
135 | | FC_STMT_END |
136 | | # define fc_mutex_impl_finish(M) \ |
137 | | FC_STMT_START {} \ |
138 | | FC_STMT_END |
139 | | |
140 | | #endif |
141 | | |
142 | | #define FC_MUTEX_INIT { FC_MUTEX_IMPL_INIT } |
143 | | typedef fc_mutex_impl_t FcMutex; |
144 | 108 | static inline void FcMutexInit (FcMutex *m) { fc_mutex_impl_init (m); } Line | Count | Source | 144 | 2 | static inline void FcMutexInit (FcMutex *m) { fc_mutex_impl_init (m); } |
Unexecuted instantiation: fccharset.c:FcMutexInit Unexecuted instantiation: fccompat.c:FcMutexInit Unexecuted instantiation: fcdbg.c:FcMutexInit Unexecuted instantiation: fcdefault.c:FcMutexInit Unexecuted instantiation: fcdir.c:FcMutexInit Unexecuted instantiation: fcfreetype.c:FcMutexInit Unexecuted instantiation: fcfs.c:FcMutexInit Unexecuted instantiation: fcptrlist.c:FcMutexInit Unexecuted instantiation: fchash.c:FcMutexInit Unexecuted instantiation: fcinit.c:FcMutexInit Unexecuted instantiation: fclang.c:FcMutexInit Unexecuted instantiation: fclist.c:FcMutexInit Unexecuted instantiation: fcmatch.c:FcMutexInit Unexecuted instantiation: fcmatrix.c:FcMutexInit Unexecuted instantiation: fcname.c:FcMutexInit Unexecuted instantiation: fcobjs.c:FcMutexInit Unexecuted instantiation: fcpat.c:FcMutexInit Unexecuted instantiation: fcrange.c:FcMutexInit Unexecuted instantiation: fcserialize.c:FcMutexInit Unexecuted instantiation: fcstat.c:FcMutexInit Unexecuted instantiation: fcstr.c:FcMutexInit Unexecuted instantiation: fcweight.c:FcMutexInit Unexecuted instantiation: fcxml.c:FcMutexInit Unexecuted instantiation: ftglue.c:FcMutexInit Line | Count | Source | 144 | 106 | static inline void FcMutexInit (FcMutex *m) { fc_mutex_impl_init (m); } |
Unexecuted instantiation: fcatomic.c:FcMutexInit |
145 | 12.9k | static inline void FcMutexLock (FcMutex *m) { fc_mutex_impl_lock (m); } Line | Count | Source | 145 | 241 | static inline void FcMutexLock (FcMutex *m) { fc_mutex_impl_lock (m); } |
Unexecuted instantiation: fccharset.c:FcMutexLock Unexecuted instantiation: fccompat.c:FcMutexLock Unexecuted instantiation: fcdbg.c:FcMutexLock Unexecuted instantiation: fcdefault.c:FcMutexLock Unexecuted instantiation: fcdir.c:FcMutexLock Unexecuted instantiation: fcfreetype.c:FcMutexLock Unexecuted instantiation: fcfs.c:FcMutexLock Unexecuted instantiation: fcptrlist.c:FcMutexLock Unexecuted instantiation: fchash.c:FcMutexLock Unexecuted instantiation: fcinit.c:FcMutexLock Unexecuted instantiation: fclang.c:FcMutexLock Unexecuted instantiation: fclist.c:FcMutexLock Unexecuted instantiation: fcmatch.c:FcMutexLock Unexecuted instantiation: fcmatrix.c:FcMutexLock Unexecuted instantiation: fcname.c:FcMutexLock Unexecuted instantiation: fcobjs.c:FcMutexLock Unexecuted instantiation: fcpat.c:FcMutexLock Unexecuted instantiation: fcrange.c:FcMutexLock Unexecuted instantiation: fcserialize.c:FcMutexLock Unexecuted instantiation: fcstat.c:FcMutexLock Unexecuted instantiation: fcstr.c:FcMutexLock Unexecuted instantiation: fcweight.c:FcMutexLock Unexecuted instantiation: fcxml.c:FcMutexLock Unexecuted instantiation: ftglue.c:FcMutexLock Line | Count | Source | 145 | 12.7k | static inline void FcMutexLock (FcMutex *m) { fc_mutex_impl_lock (m); } |
Unexecuted instantiation: fcatomic.c:FcMutexLock |
146 | 12.9k | static inline void FcMutexUnlock (FcMutex *m) { fc_mutex_impl_unlock (m); } Line | Count | Source | 146 | 241 | static inline void FcMutexUnlock (FcMutex *m) { fc_mutex_impl_unlock (m); } |
Unexecuted instantiation: fccharset.c:FcMutexUnlock Unexecuted instantiation: fccompat.c:FcMutexUnlock Unexecuted instantiation: fcdbg.c:FcMutexUnlock Unexecuted instantiation: fcdefault.c:FcMutexUnlock Unexecuted instantiation: fcdir.c:FcMutexUnlock Unexecuted instantiation: fcfreetype.c:FcMutexUnlock Unexecuted instantiation: fcfs.c:FcMutexUnlock Unexecuted instantiation: fcptrlist.c:FcMutexUnlock Unexecuted instantiation: fchash.c:FcMutexUnlock Unexecuted instantiation: fcinit.c:FcMutexUnlock Unexecuted instantiation: fclang.c:FcMutexUnlock Unexecuted instantiation: fclist.c:FcMutexUnlock Unexecuted instantiation: fcmatch.c:FcMutexUnlock Unexecuted instantiation: fcmatrix.c:FcMutexUnlock Unexecuted instantiation: fcname.c:FcMutexUnlock Unexecuted instantiation: fcobjs.c:FcMutexUnlock Unexecuted instantiation: fcpat.c:FcMutexUnlock Unexecuted instantiation: fcrange.c:FcMutexUnlock Unexecuted instantiation: fcserialize.c:FcMutexUnlock Unexecuted instantiation: fcstat.c:FcMutexUnlock Unexecuted instantiation: fcstr.c:FcMutexUnlock Unexecuted instantiation: fcweight.c:FcMutexUnlock Unexecuted instantiation: fcxml.c:FcMutexUnlock Unexecuted instantiation: ftglue.c:FcMutexUnlock Line | Count | Source | 146 | 12.7k | static inline void FcMutexUnlock (FcMutex *m) { fc_mutex_impl_unlock (m); } |
Unexecuted instantiation: fcatomic.c:FcMutexUnlock |
147 | 0 | static inline void FcMutexFinish (FcMutex *m) { fc_mutex_impl_finish (m); } Unexecuted instantiation: fccfg.c:FcMutexFinish Unexecuted instantiation: fccharset.c:FcMutexFinish Unexecuted instantiation: fccompat.c:FcMutexFinish Unexecuted instantiation: fcdbg.c:FcMutexFinish Unexecuted instantiation: fcdefault.c:FcMutexFinish Unexecuted instantiation: fcdir.c:FcMutexFinish Unexecuted instantiation: fcfreetype.c:FcMutexFinish Unexecuted instantiation: fcfs.c:FcMutexFinish Unexecuted instantiation: fcptrlist.c:FcMutexFinish Unexecuted instantiation: fchash.c:FcMutexFinish Unexecuted instantiation: fcinit.c:FcMutexFinish Unexecuted instantiation: fclang.c:FcMutexFinish Unexecuted instantiation: fclist.c:FcMutexFinish Unexecuted instantiation: fcmatch.c:FcMutexFinish Unexecuted instantiation: fcmatrix.c:FcMutexFinish Unexecuted instantiation: fcname.c:FcMutexFinish Unexecuted instantiation: fcobjs.c:FcMutexFinish Unexecuted instantiation: fcpat.c:FcMutexFinish Unexecuted instantiation: fcrange.c:FcMutexFinish Unexecuted instantiation: fcserialize.c:FcMutexFinish Unexecuted instantiation: fcstat.c:FcMutexFinish Unexecuted instantiation: fcstr.c:FcMutexFinish Unexecuted instantiation: fcweight.c:FcMutexFinish Unexecuted instantiation: fcxml.c:FcMutexFinish Unexecuted instantiation: ftglue.c:FcMutexFinish Unexecuted instantiation: fccache.c:FcMutexFinish Unexecuted instantiation: fcatomic.c:FcMutexFinish |
148 | | |
149 | | #endif /* _FCMUTEX_H_ */ |