Bug 1883518 - Remove a bunch of unused ServoBindings.toml entries. r=firefox-style...
[gecko.git] / gfx / harfbuzz / src / hb-mutex.hh
blobe329d9864f1c5daad3d2ad3941885569510fe228
1 /*
2 * Copyright © 2007 Chris Wilson
3 * Copyright © 2009,2010 Red Hat, Inc.
4 * Copyright © 2011,2012 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
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.
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.
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.
26 * Contributor(s):
27 * Chris Wilson <chris@chris-wilson.co.uk>
28 * Red Hat Author(s): Behdad Esfahbod
29 * Google Author(s): Behdad Esfahbod
32 #ifndef HB_MUTEX_HH
33 #define HB_MUTEX_HH
35 #include "hb.hh"
38 /* mutex */
40 /* We need external help for these */
42 #if defined(hb_mutex_impl_init) \
43 && defined(hb_mutex_impl_lock) \
44 && defined(hb_mutex_impl_unlock) \
45 && defined(hb_mutex_impl_finish)
47 /* Defined externally, i.e. in config.h; must have typedef'ed hb_mutex_impl_t as well. */
50 #elif !defined(HB_NO_MT) && !defined(HB_MUTEX_IMPL_STD_MUTEX) && (defined(HAVE_PTHREAD) || defined(__APPLE__))
52 #include <pthread.h>
53 typedef pthread_mutex_t hb_mutex_impl_t;
54 #define hb_mutex_impl_init(M) pthread_mutex_init (M, nullptr)
55 #define hb_mutex_impl_lock(M) pthread_mutex_lock (M)
56 #define hb_mutex_impl_unlock(M) pthread_mutex_unlock (M)
57 #define hb_mutex_impl_finish(M) pthread_mutex_destroy (M)
60 #elif !defined(HB_NO_MT) && !defined(HB_MUTEX_IMPL_STD_MUTEX) && defined(_WIN32)
62 typedef CRITICAL_SECTION hb_mutex_impl_t;
63 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
64 #define hb_mutex_impl_init(M) InitializeCriticalSectionEx (M, 0, 0)
65 #else
66 #define hb_mutex_impl_init(M) InitializeCriticalSection (M)
67 #endif
68 #define hb_mutex_impl_lock(M) EnterCriticalSection (M)
69 #define hb_mutex_impl_unlock(M) LeaveCriticalSection (M)
70 #define hb_mutex_impl_finish(M) DeleteCriticalSection (M)
73 #elif !defined(HB_NO_MT)
75 #include <mutex>
76 typedef std::mutex hb_mutex_impl_t;
77 #define hb_mutex_impl_init(M) HB_STMT_START { new (M) hb_mutex_impl_t; } HB_STMT_END
78 #define hb_mutex_impl_lock(M) (M)->lock ()
79 #define hb_mutex_impl_unlock(M) (M)->unlock ()
80 #define hb_mutex_impl_finish(M) HB_STMT_START { (M)->~hb_mutex_impl_t(); } HB_STMT_END
83 #else /* defined(HB_NO_MT) */
85 typedef int hb_mutex_impl_t;
86 #define hb_mutex_impl_init(M) HB_STMT_START {} HB_STMT_END
87 #define hb_mutex_impl_lock(M) HB_STMT_START {} HB_STMT_END
88 #define hb_mutex_impl_unlock(M) HB_STMT_START {} HB_STMT_END
89 #define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END
92 #endif
95 struct hb_mutex_t
97 /* Create space for, but do not initialize m. */
98 alignas(hb_mutex_impl_t) char m[sizeof (hb_mutex_impl_t)];
100 hb_mutex_t () { init (); }
101 ~hb_mutex_t () { fini (); }
103 #pragma GCC diagnostic push
104 #pragma GCC diagnostic ignored "-Wcast-align"
105 void init () { hb_mutex_impl_init ((hb_mutex_impl_t *) m); }
106 void lock () { hb_mutex_impl_lock ((hb_mutex_impl_t *) m); }
107 void unlock () { hb_mutex_impl_unlock ((hb_mutex_impl_t *) m); }
108 void fini () { hb_mutex_impl_finish ((hb_mutex_impl_t *) m); }
109 #pragma GCC diagnostic pop
112 struct hb_lock_t
114 hb_lock_t (hb_mutex_t &mutex_) : mutex (&mutex_) { mutex->lock (); }
115 hb_lock_t (hb_mutex_t *mutex_) : mutex (mutex_) { if (mutex) mutex->lock (); }
116 ~hb_lock_t () { if (mutex) mutex->unlock (); }
117 private:
118 hb_mutex_t *mutex;
122 #endif /* HB_MUTEX_HH */