9#define MAGICKCORE_IMPLEMENTATION 1
10#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
12#include "Magick++/Thread.h"
13#include "Magick++/Exception.h"
18Magick::MutexLock::MutexLock(
void)
19#if defined(MAGICKCORE_HAVE_PTHREAD)
23 ::pthread_mutexattr_t attr;
25 if ( (sysError = ::pthread_mutexattr_init( &attr )) == 0 )
26 if ( (sysError = ::pthread_mutex_init( &_mutex, &attr )) == 0 )
28 ::pthread_mutexattr_destroy( &attr );
31 throwExceptionExplicit( OptionError,
"mutex initialization failed",
35#if defined(_VISUALC_) && defined(_MT)
39 SECURITY_ATTRIBUTES security;
42 security.nLength =
sizeof(security);
43 security.lpSecurityDescriptor = NULL;
44 security.bInheritHandle = TRUE;
47 _mutex.id = ::CreateSemaphore(&security, 1, MAXSEMLEN, NULL);
48 if ( _mutex.id != NULL )
50 throwExceptionExplicit( OptionError,
"mutex initialization failed" );
60Magick::MutexLock::~MutexLock(
void)
62#if defined(MAGICKCORE_HAVE_PTHREAD)
63 (void) ::pthread_mutex_destroy(&_mutex);
65#if defined(_MT) && defined(_VISUALC_)
66 (void) ::CloseHandle(_mutex.id);
71void Magick::MutexLock::lock(
void)
73#if defined(MAGICKCORE_HAVE_PTHREAD)
75 if ( (sysError = ::pthread_mutex_lock( &_mutex )) == 0)
77 throwExceptionExplicit( OptionError,
"mutex lock failed",
80#if defined(_MT) && defined(_VISUALC_)
81 if (WaitForSingleObject(_mutex.id,INFINITE) != WAIT_FAILED)
83 throwExceptionExplicit( OptionError,
"mutex lock failed" );
88void Magick::MutexLock::unlock(
void)
90#if defined(MAGICKCORE_HAVE_PTHREAD)
92 if ( (sysError = ::pthread_mutex_unlock( &_mutex )) == 0)
94 throwExceptionExplicit( OptionError,
"mutex unlock failed",
97#if defined(_MT) && defined(_VISUALC_)
98 if ( ReleaseSemaphore(_mutex.id, 1, NULL) == TRUE )
100 throwExceptionExplicit( OptionError,
"mutex unlock failed" );