MagickCore  6.9.10
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 
25 #if defined(MAGICKCORE_OPENMP_SUPPORT)
26 static omp_lock_t
28 #elif defined(MAGICKCORE_THREAD_SUPPORT)
29 static pthread_mutex_t
30  semaphore_mutex = PTHREAD_MUTEX_INITIALIZER;
31 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
32 static LONG
33  semaphore_mutex = 0;
34 #else
35 static ssize_t
36  semaphore_mutex = 0;
37 #endif
38 
39 static MagickBooleanType
41 
42 static inline void DestroyMagickMutex(void)
43 {
44 #if defined(MAGICKCORE_OPENMP_SUPPORT)
46  omp_destroy_lock(&semaphore_mutex);
47 #endif
49 }
50 
51 static inline void InitializeMagickMutex(void)
52 {
53 #if defined(MAGICKCORE_OPENMP_SUPPORT)
55  omp_init_lock(&semaphore_mutex);
56 #endif
58 }
59 
60 static inline void LockMagickMutex(void)
61 {
62 #if defined(MAGICKCORE_OPENMP_SUPPORT)
63  omp_set_lock(&semaphore_mutex);
64 #elif defined(MAGICKCORE_THREAD_SUPPORT)
65  {
66  int
67  status;
68 
69  status=pthread_mutex_lock(&semaphore_mutex);
70  if (status != 0)
71  {
72  errno=status;
73  ThrowFatalException(ResourceLimitFatalError,"UnableToLockSemaphore");
74  }
75  }
76 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
77  while (InterlockedCompareExchange(&semaphore_mutex,1L,0L) != 0)
78  Sleep(10);
79 #endif
80 }
81 
82 static inline void UnlockMagickMutex(void)
83 {
84 #if defined(MAGICKCORE_OPENMP_SUPPORT)
85  omp_unset_lock(&semaphore_mutex);
86 #elif defined(MAGICKCORE_THREAD_SUPPORT)
87  {
88  int
89  status;
90 
91  status=pthread_mutex_unlock(&semaphore_mutex);
92  if (status != 0)
93  {
94  errno=status;
95  ThrowFatalException(ResourceLimitFatalError,"UnableToUnlockSemaphore");
96  }
97  }
98 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
99  InterlockedExchange(&semaphore_mutex,0L);
100 #endif
101 }
102 
103 #if defined(__cplusplus) || defined(c_plusplus)
104 }
105 #endif
106 
107 #endif
static void UnlockMagickMutex(void)
Definition: semaphore-private.h:82
#define ThrowFatalException(severity, tag)
Definition: exception-private.h:36
static ssize_t semaphore_mutex
Definition: semaphore-private.h:36
#define pthread_mutex_lock
Definition: vms.h:824
static MagickBooleanType active_mutex
Definition: semaphore-private.h:40
static void InitializeMagickMutex(void)
Definition: semaphore-private.h:51
static void LockMagickMutex(void)
Definition: semaphore-private.h:60
Definition: exception.h:78
MagickBooleanType
Definition: magick-type.h:189
Definition: magick-type.h:192
static void DestroyMagickMutex(void)
Definition: semaphore-private.h:42
#define pthread_mutex_unlock
Definition: vms.h:826
Definition: magick-type.h:191