11#define MAGICKCORE_IMPLEMENTATION 1
12#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
14#include "Magick++/Thread.h"
15#include "Magick++/Exception.h"
19Magick::MutexLock::MutexLock(
void)
20#if defined(MAGICKCORE_HAVE_PTHREAD)
30 if ((sysError=::pthread_mutexattr_init(&attr)) == 0)
31 if ((sysError=::pthread_mutex_init(&_mutex,&attr)) == 0)
33 ::pthread_mutexattr_destroy(&attr);
36 throwExceptionExplicit(MagickCore::OptionError,
"mutex initialization failed",
40#if defined(_VISUALC_) && defined(_MT)
47 security.nLength=
sizeof(security);
48 security.lpSecurityDescriptor=(LPVOID) NULL;
49 security.bInheritHandle=TRUE;
52 _mutex=::CreateSemaphore(&security,1,1,(LPCSTR) NULL);
53 if (_mutex != (HANDLE) NULL)
55 throwExceptionExplicit(MagickCore::OptionError,
56 "mutex initialization failed");
66Magick::MutexLock::~MutexLock(
void)
68#if defined(MAGICKCORE_HAVE_PTHREAD)
69 (void) ::pthread_mutex_destroy(&_mutex);
71#if defined(_MT) && defined(_VISUALC_)
72 (void) ::CloseHandle(_mutex);
77void Magick::MutexLock::lock(
void)
79#if defined(MAGICKCORE_HAVE_PTHREAD)
83 if ((sysError=::pthread_mutex_lock(&_mutex)) == 0)
85 throwExceptionExplicit(MagickCore::OptionError,
"mutex lock failed",
88#if defined(_MT) && defined(_VISUALC_)
89 if (WaitForSingleObject(_mutex,INFINITE) != WAIT_FAILED)
91 throwExceptionExplicit(MagickCore::OptionError,
"mutex lock failed");
96void Magick::MutexLock::unlock(
void)
98#if defined(MAGICKCORE_HAVE_PTHREAD)
102 if ((sysError=::pthread_mutex_unlock(&_mutex)) == 0)
104 throwExceptionExplicit(MagickCore::OptionError,
"mutex unlock failed",
107#if defined(_MT) && defined(_VISUALC_)
108 if (ReleaseSemaphore(_mutex,1,(LPLONG) NULL) == TRUE)
110 throwExceptionExplicit(MagickCore::OptionError,
"mutex unlock failed");