MagickCore 7.0.10
semaphore-private.h
Go to the documentation of this file.
1/*
2 Copyright @ 1999 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://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 Wizard's Toolkit private methods to lock and unlock semaphores.
17*/
18#ifndef _WIZARDSTOOLKIT_SEMAPHORE_PRIVATE_H
19#define _WIZARDSTOOLKIT_SEMAPHORE_PRIVATE_H
20
22
23#if defined(__cplusplus) || defined(c_plusplus)
24extern "C" {
25#endif
26
27#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
28static omp_lock_t
30#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
31static pthread_mutex_t
32 semaphore_mutex = PTHREAD_MUTEX_INITIALIZER;
33#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
34static LONG
36#else
37static ssize_t
39#endif
40
43
44static inline void DestroyWizardMutex(void)
45{
46#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
48 omp_destroy_lock(&semaphore_mutex);
49#endif
51}
52
53static inline void InitializeWizardMutex(void)
54{
55#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
57 omp_init_lock(&semaphore_mutex);
58#endif
60}
61
62static inline void LockWizardMutex(void)
63{
64#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
65 omp_set_lock(&semaphore_mutex);
66#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
67 {
68 int
69 status;
70
71 status=pthread_mutex_lock(&semaphore_mutex);
72 if (status != 0)
73 {
74 errno=status;
76 "unable to lock semaphore `%s'");
77 }
78 }
79#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
80 while (InterlockedCompareExchange(&semaphore_mutex,1L,0L) != 0)
81 Sleep(10);
82#endif
83}
84
85static inline void UnlockWizardMutex(void)
86{
87#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
88 omp_unset_lock(&semaphore_mutex);
89#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
90 {
91 int
92 status;
93
94 status=pthread_mutex_unlock(&semaphore_mutex);
95 if (status != 0)
96 {
97 errno=status;
99 "unable to unlock semaphore `%s'");
100 }
101 }
102#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
103 InterlockedExchange(&semaphore_mutex,0L);
104#endif
105}
106
107#if defined(__cplusplus) || defined(c_plusplus)
108}
109#endif
110
111#endif
#define ThrowFatalException(severity, tag)
@ ResourceFatalError
Definition exception.h:121
static void DestroyWizardMutex(void)
static void InitializeWizardMutex(void)
static void UnlockWizardMutex(void)
static WizardBooleanType active_mutex
static void LockWizardMutex(void)
static ssize_t semaphore_mutex
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27