18#ifndef MAGICKCORE_MUTEX_H
19#define MAGICKCORE_MUTEX_H
21#if defined(__cplusplus) || defined(c_plusplus)
33#if defined(MAGICKCORE_OPENMP_SUPPORT)
34static MagickBooleanType
35 translation_unit_initialized = MagickFalse;
38 translation_unit_mutex;
39#elif defined(MAGICKCORE_THREAD_SUPPORT)
41 translation_unit_mutex = PTHREAD_MUTEX_INITIALIZER;
42#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
44 translation_unit_mutex = 0;
47static inline void DestroyMagickMutex(
void)
49#if defined(MAGICKCORE_OPENMP_SUPPORT)
50 if (translation_unit_initialized != MagickFalse)
51 omp_destroy_lock(&translation_unit_mutex);
52 translation_unit_initialized=MagickFalse;
56static inline void InitializeMagickMutex(
void)
58#if defined(MAGICKCORE_OPENMP_SUPPORT)
59 if (translation_unit_initialized == MagickFalse)
60 omp_init_lock(&translation_unit_mutex);
61 translation_unit_initialized=MagickTrue;
65static inline void LockMagickMutex(
void)
67#if defined(MAGICKCORE_OPENMP_SUPPORT)
68 if (translation_unit_initialized == MagickFalse)
69 InitializeMagickMutex();
70 omp_set_lock(&translation_unit_mutex);
71#elif defined(MAGICKCORE_THREAD_SUPPORT)
76 status=pthread_mutex_lock(&translation_unit_mutex);
80 ThrowFatalException(ResourceLimitFatalError,
"UnableToLockSemaphore");
83#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
84 while (InterlockedCompareExchange(&translation_unit_mutex,1L,0L) != 0)
89static inline void UnlockMagickMutex(
void)
91#if defined(MAGICKCORE_OPENMP_SUPPORT)
92 if (translation_unit_initialized == MagickFalse)
93 InitializeMagickMutex();
94 omp_unset_lock(&translation_unit_mutex);
95#elif defined(MAGICKCORE_THREAD_SUPPORT)
100 status=pthread_mutex_unlock(&translation_unit_mutex);
104 ThrowFatalException(ResourceLimitFatalError,
"UnableToUnlockSemaphore");
107#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
108 InterlockedExchange(&translation_unit_mutex,0L);
112#if defined(__cplusplus) || defined(c_plusplus)