MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
semaphore-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License.
6  obtain a copy of the License at
7 
8  https://www.imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore private methods to lock and unlock semaphores.
17 */
18 #ifndef MAGICKCORE_SEMAPHORE_PRIVATE_H
19 #define MAGICKCORE_SEMAPHORE_PRIVATE_H
20 
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
27 
28 extern MagickPrivate void
30 
31 #if defined(MAGICKCORE_OPENMP_SUPPORT)
32 static omp_lock_t
34 #elif defined(MAGICKCORE_THREAD_SUPPORT)
35 static pthread_mutex_t
36  semaphore_mutex = PTHREAD_MUTEX_INITIALIZER;
37 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
38 static LONG
39  semaphore_mutex = 0;
40 #else
41 static ssize_t
42  semaphore_mutex = 0;
43 #endif
44 
45 static MagickBooleanType
47 
48 static inline void DestroyMagickMutex(void)
49 {
50 #if defined(MAGICKCORE_OPENMP_SUPPORT)
52  omp_destroy_lock(&semaphore_mutex);
53 #endif
55 }
56 
57 static inline void InitializeMagickMutex(void)
58 {
59 #if defined(MAGICKCORE_OPENMP_SUPPORT)
61  omp_init_lock(&semaphore_mutex);
62 #endif
64 }
65 
66 static inline void LockMagickMutex(void)
67 {
68 #if defined(MAGICKCORE_OPENMP_SUPPORT)
69  omp_set_lock(&semaphore_mutex);
70 #elif defined(MAGICKCORE_THREAD_SUPPORT)
71  {
72  int
73  status;
74 
75  status=pthread_mutex_lock(&semaphore_mutex);
76  if (status != 0)
77  {
78  errno=status;
79  ThrowFatalException(ResourceLimitFatalError,"UnableToLockSemaphore");
80  }
81  }
82 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
83  while (InterlockedCompareExchange(&semaphore_mutex,1L,0L) != 0)
84  Sleep(10);
85 #endif
86 }
87 
88 static inline void UnlockMagickMutex(void)
89 {
90 #if defined(MAGICKCORE_OPENMP_SUPPORT)
91  omp_unset_lock(&semaphore_mutex);
92 #elif defined(MAGICKCORE_THREAD_SUPPORT)
93  {
94  int
95  status;
96 
97  status=pthread_mutex_unlock(&semaphore_mutex);
98  if (status != 0)
99  {
100  errno=status;
101  ThrowFatalException(ResourceLimitFatalError,"UnableToUnlockSemaphore");
102  }
103  }
104 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
105  InterlockedExchange(&semaphore_mutex,0L);
106 #endif
107 }
108 
109 #if defined(__cplusplus) || defined(c_plusplus)
110 }
111 #endif
112 
113 #endif
MagickPrivate MagickBooleanType SemaphoreComponentGenesis(void)
Definition: semaphore.c:399
static void UnlockMagickMutex(void)
#define ThrowFatalException(severity, tag)
static ssize_t semaphore_mutex
#define pthread_mutex_lock
Definition: vms.h:824
static MagickBooleanType active_mutex
static void InitializeMagickMutex(void)
static void LockMagickMutex(void)
MagickBooleanType
Definition: magick-type.h:156
static void DestroyMagickMutex(void)
#define pthread_mutex_unlock
Definition: vms.h:826
MagickPrivate void SemaphoreComponentTerminus(void)
Definition: semaphore.c:423
#define MagickPrivate