OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007 Chris Wilson | 2 * Copyright © 2007 Chris Wilson |
3 * Copyright © 2009,2010 Red Hat, Inc. | 3 * Copyright © 2009,2010 Red Hat, Inc. |
4 * Copyright © 2011 Google, Inc. | 4 * Copyright © 2011 Google, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
(...skipping 17 matching lines...) Expand all Loading... |
28 * Red Hat Author(s): Behdad Esfahbod | 28 * Red Hat Author(s): Behdad Esfahbod |
29 * Google Author(s): Behdad Esfahbod | 29 * Google Author(s): Behdad Esfahbod |
30 */ | 30 */ |
31 | 31 |
32 #ifndef HB_MUTEX_PRIVATE_HH | 32 #ifndef HB_MUTEX_PRIVATE_HH |
33 #define HB_MUTEX_PRIVATE_HH | 33 #define HB_MUTEX_PRIVATE_HH |
34 | 34 |
35 #include "hb-private.hh" | 35 #include "hb-private.hh" |
36 | 36 |
37 | 37 |
38 | |
39 /* mutex */ | 38 /* mutex */ |
40 | 39 |
41 /* We need external help for these */ | 40 /* We need external help for these */ |
42 | 41 |
43 #ifdef HAVE_GLIB | 42 #if 0 |
44 | |
45 #include <glib.h> | |
46 | |
47 typedef GStaticMutex hb_mutex_impl_t; | |
48 #define HB_MUTEX_IMPL_INIT» G_STATIC_MUTEX_INIT | |
49 #define hb_mutex_impl_init(M)» g_static_mutex_init (M) | |
50 #define hb_mutex_impl_lock(M)» g_static_mutex_lock (M) | |
51 #define hb_mutex_impl_unlock(M)»g_static_mutex_unlock (M) | |
52 #define hb_mutex_impl_free(M)» g_static_mutex_free (M) | |
53 | 43 |
54 | 44 |
55 #elif defined(_MSC_VER) || defined(__MINGW32__) | 45 #elif !defined(HB_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) |
56 | 46 |
57 #include <windows.h> | 47 #include <windows.h> |
58 | |
59 typedef CRITICAL_SECTION hb_mutex_impl_t; | 48 typedef CRITICAL_SECTION hb_mutex_impl_t; |
60 #define HB_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 } | 49 #define HB_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 } |
61 #define hb_mutex_impl_init(M) InitializeCriticalSection (M) | 50 #define hb_mutex_impl_init(M) InitializeCriticalSection (M) |
62 #define hb_mutex_impl_lock(M) EnterCriticalSection (M) | 51 #define hb_mutex_impl_lock(M) EnterCriticalSection (M) |
63 #define hb_mutex_impl_unlock(M) LeaveCriticalSection (M) | 52 #define hb_mutex_impl_unlock(M) LeaveCriticalSection (M) |
64 #define hb_mutex_impl_free(M) DeleteCriticalSection (M) | 53 #define hb_mutex_impl_free(M) DeleteCriticalSection (M) |
65 | 54 |
66 | 55 |
| 56 #elif !defined(HB_NO_MT) && defined(__APPLE__) |
| 57 |
| 58 #include <pthread.h> |
| 59 typedef pthread_mutex_t hb_mutex_impl_t; |
| 60 #define HB_MUTEX_IMPL_INIT PTHREAD_MUTEX_INITIALIZER |
| 61 #define hb_mutex_impl_init(M) pthread_mutex_init (M, NULL) |
| 62 #define hb_mutex_impl_lock(M) pthread_mutex_lock (M) |
| 63 #define hb_mutex_impl_unlock(M) pthread_mutex_unlock (M) |
| 64 #define hb_mutex_impl_free(M) pthread_mutex_destroy (M) |
| 65 |
| 66 |
| 67 #elif !defined(HB_NO_MT) && defined(HAVE_GLIB) |
| 68 |
| 69 #include <glib.h> |
| 70 typedef GStaticMutex hb_mutex_impl_t; |
| 71 #define HB_MUTEX_IMPL_INIT G_STATIC_MUTEX_INIT |
| 72 #define hb_mutex_impl_init(M) g_static_mutex_init (M) |
| 73 #define hb_mutex_impl_lock(M) g_static_mutex_lock (M) |
| 74 #define hb_mutex_impl_unlock(M) g_static_mutex_unlock (M) |
| 75 #define hb_mutex_impl_free(M) g_static_mutex_free (M) |
| 76 |
| 77 |
67 #else | 78 #else |
68 | 79 |
69 #warning "Could not find any system to define platform macros, library will NOT
be thread-safe" | 80 #define HB_MUTEX_IMPL_NIL 1 |
70 | |
71 typedef volatile int hb_mutex_impl_t; | 81 typedef volatile int hb_mutex_impl_t; |
72 #define HB_MUTEX_IMPL_INIT 0 | 82 #define HB_MUTEX_IMPL_INIT 0 |
73 #define hb_mutex_impl_init(M) ((void) (*(M) = 0)) | 83 #define hb_mutex_impl_init(M) ((void) (*(M) = 0)) |
74 #define hb_mutex_impl_lock(M) ((void) (*(M) = 1)) | 84 #define hb_mutex_impl_lock(M) ((void) (*(M) = 1)) |
75 #define hb_mutex_impl_unlock(M) ((void) (*(M) = 0)) | 85 #define hb_mutex_impl_unlock(M) ((void) (*(M) = 0)) |
76 #define hb_mutex_impl_free(M) ((void) (*(M) = 2)) | 86 #define hb_mutex_impl_free(M) ((void) (*(M) = 2)) |
77 | 87 |
78 | |
79 #endif | 88 #endif |
80 | 89 |
81 | 90 |
82 struct hb_mutex_t | 91 struct hb_mutex_t |
83 { | 92 { |
84 hb_mutex_impl_t m; | 93 hb_mutex_impl_t m; |
85 | 94 |
86 inline void init (void) { hb_mutex_impl_init (&m); } | 95 inline void init (void) { hb_mutex_impl_init (&m); } |
87 inline void lock (void) { hb_mutex_impl_lock (&m); } | 96 inline void lock (void) { hb_mutex_impl_lock (&m); } |
88 inline void unlock (void) { hb_mutex_impl_unlock (&m); } | 97 inline void unlock (void) { hb_mutex_impl_unlock (&m); } |
(...skipping 12 matching lines...) Expand all Loading... |
101 hb_static_mutex_t (void) { this->init (); } | 110 hb_static_mutex_t (void) { this->init (); } |
102 ~hb_static_mutex_t (void) { this->free (); } | 111 ~hb_static_mutex_t (void) { this->free (); } |
103 | 112 |
104 private: | 113 private: |
105 NO_COPY (hb_static_mutex_t); | 114 NO_COPY (hb_static_mutex_t); |
106 }; | 115 }; |
107 | 116 |
108 | 117 |
109 | 118 |
110 #endif /* HB_MUTEX_PRIVATE_HH */ | 119 #endif /* HB_MUTEX_PRIVATE_HH */ |
OLD | NEW |