11#define MAGICKCORE_IMPLEMENTATION 1
12#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
14#include "Magick++/Thread.h"
15#include "Magick++/Exception.h"
20Magick::MutexLock::MutexLock(
void)
21#if defined(MAGICKCORE_HAVE_PTHREAD)
31 if ((sysError=::pthread_mutexattr_init(&attr)) == 0)
32 if ((sysError=::pthread_mutex_init(&_mutex,&attr)) == 0)
34 ::pthread_mutexattr_destroy(&attr);
37 throwExceptionExplicit(MagickCore::OptionError,
"mutex initialization failed",
41#if defined(_VISUALC_) && defined(_MT)
48 security.nLength=
sizeof(security);
49 security.lpSecurityDescriptor=(LPVOID) NULL;
50 security.bInheritHandle=TRUE;
53 _mutex=::CreateSemaphore(&security,1,1,(LPCSTR) NULL);
54 if (_mutex != (HANDLE) NULL)
56 throwExceptionExplicit(MagickCore::OptionError,
57 "mutex initialization failed");
67Magick::MutexLock::~MutexLock(
void)
69#if defined(MAGICKCORE_HAVE_PTHREAD)
70 (void) ::pthread_mutex_destroy(&_mutex);
72#if defined(_MT) && defined(_VISUALC_)
73 (void) ::CloseHandle(_mutex);
78void Magick::MutexLock::lock(
void)
80#if defined(MAGICKCORE_HAVE_PTHREAD)
84 if ((sysError=::pthread_mutex_lock(&_mutex)) == 0)
86 throwExceptionExplicit(MagickCore::OptionError,
"mutex lock failed",
89#if defined(_MT) && defined(_VISUALC_)
90 if (WaitForSingleObject(_mutex,INFINITE) != WAIT_FAILED)
92 throwExceptionExplicit(MagickCore::OptionError,
"mutex lock failed");
97void Magick::MutexLock::unlock(
void)
99#if defined(MAGICKCORE_HAVE_PTHREAD)
103 if ((sysError=::pthread_mutex_unlock(&_mutex)) == 0)
105 throwExceptionExplicit(MagickCore::OptionError,
"mutex unlock failed",
108#if defined(_MT) && defined(_VISUALC_)
109 if (ReleaseSemaphore(_mutex,1,(LPLONG) NULL) == TRUE)
111 throwExceptionExplicit(MagickCore::OptionError,
"mutex unlock failed");