From: dirk Date: Fri, 26 Dec 2014 22:17:54 +0000 (+0000) Subject: Code cleanup. X-Git-Tag: 7.0.1-0~1543 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09ee8ad0257465701592c76666194c81b9251c30;p=imagemagick Code cleanup. --- diff --git a/Magick++/lib/Magick++/Thread.h b/Magick++/lib/Magick++/Thread.h index f646364e3..f50520dea 100644 --- a/Magick++/lib/Magick++/Thread.h +++ b/Magick++/lib/Magick++/Thread.h @@ -15,8 +15,9 @@ #if defined(_VISUALC_) #include #if defined(_MT) -struct win32_mutex { - HANDLE id; +struct win32_mutex +{ + HANDLE id; }; // This is a binary semphore -- increase for a counting semaphore @@ -34,6 +35,7 @@ namespace Magick class MagickPPExport MutexLock { public: + // Default constructor MutexLock(void); @@ -49,16 +51,16 @@ namespace Magick private: // Don't support copy constructor - MutexLock ( const MutexLock& original_ ); + MutexLock(const MutexLock& original_); // Don't support assignment - MutexLock& operator = ( const MutexLock& original_ ); + MutexLock& operator=(const MutexLock& original ); #if defined(MAGICKCORE_HAVE_PTHREAD) - pthread_mutex_t _mutex; + pthread_mutex_t \ _mutex; #endif #if defined(_MT) && defined(_VISUALC_) - win32_mutex _mutex; + win32_mutex _mutex; #endif }; @@ -66,35 +68,37 @@ namespace Magick class MagickPPExport Lock { public: + // Construct with mutex lock (locks mutex) - Lock( MutexLock *mutexLock_ ); + Lock(MutexLock *mutexLock_); // Destrutor (unlocks mutex) - ~Lock( void ); + ~Lock(void); + private: // Don't support copy constructor - Lock ( const Lock& original_ ); - + Lock(const Lock& original_); + // Don't support assignment - Lock& operator = ( const Lock& original_ ); + Lock& operator=(const Lock& original_); MutexLock* _mutexLock; }; } // Construct with mutex lock (locks mutex) -inline Magick::Lock::Lock( MutexLock *mutexLock_ ) +inline Magick::Lock::Lock(MutexLock *mutexLock_) : _mutexLock(mutexLock_) { _mutexLock->lock(); } // Destrutor (unlocks mutex) -inline Magick::Lock::~Lock( void ) +inline Magick::Lock::~Lock(void) { _mutexLock->unlock(); - _mutexLock=0; + _mutexLock=(MutexLock*) NULL; } #endif // Magick_Thread_header diff --git a/Magick++/lib/Thread.cpp b/Magick++/lib/Thread.cpp index 55a4d8fb6..695de5c14 100644 --- a/Magick++/lib/Thread.cpp +++ b/Magick++/lib/Thread.cpp @@ -19,34 +19,39 @@ Magick::MutexLock::MutexLock(void) // POSIX threads : _mutex() { - ::pthread_mutexattr_t attr; - int sysError; - if ( (sysError = ::pthread_mutexattr_init( &attr )) == 0 ) - if ( (sysError = ::pthread_mutex_init( &_mutex, &attr )) == 0 ) + ::pthread_mutexattr_t + attr; + + int + sysError; + + if ((sysError=::pthread_mutexattr_init(&attr)) == 0) + if ((sysError=::pthread_mutex_init(&_mutex,&attr)) == 0) { - ::pthread_mutexattr_destroy( &attr ); + ::pthread_mutexattr_destroy(&attr); return; } - throwExceptionExplicit( OptionError, "mutex initialization failed", - strerror(sysError) ); + throwExceptionExplicit(OptionError,"mutex initialization failed", + strerror(sysError)); } #else #if defined(_VISUALC_) && defined(_MT) // Win32 threads : _mutex() { - SECURITY_ATTRIBUTES security; + SECURITY_ATTRIBUTES + security; /* Allow the semaphore to be inherited */ - security.nLength = sizeof(security); - security.lpSecurityDescriptor = NULL; - security.bInheritHandle = TRUE; + security.nLength=sizeof(security); + security.lpSecurityDescriptor=(LPVOID) NULL; + security.bInheritHandle=TRUE; /* Create the semaphore, with initial value signaled */ - _mutex.id = ::CreateSemaphore(&security, 1, MAXSEMLEN, NULL); - if ( _mutex.id != NULL ) + _mutex.id=::CreateSemaphore(&security,1,MAXSEMLEN,(LPCSTR) NULL); + if (_mutex.id != (HANDLE) NULL) return; - throwExceptionExplicit( OptionError, "mutex initialization failed" ); + throwExceptionExplicit(OptionError,"mutex initialization failed"); } #else // Threads not supported @@ -59,16 +64,18 @@ Magick::MutexLock::MutexLock(void) Magick::MutexLock::~MutexLock(void) { #if defined(MAGICKCORE_HAVE_PTHREAD) - int sysError; - if ( (sysError = ::pthread_mutex_destroy( &_mutex )) == 0 ) + int + sysError; + + if ((sysError=::pthread_mutex_destroy(&_mutex)) == 0) return; - throwExceptionExplicit( OptionError, "mutex destruction failed", - strerror(sysError) ); + throwExceptionExplicit(OptionError,"mutex destruction failed", + strerror(sysError)); #endif #if defined(_MT) && defined(_VISUALC_) - if ( ::CloseHandle(_mutex.id) != 0 ) + if (::CloseHandle(_mutex.id) != 0) return; - throwExceptionExplicit( OptionError, "mutex destruction failed" ); + throwExceptionExplicit(OptionError,"mutex destruction failed"); #endif } @@ -76,16 +83,18 @@ Magick::MutexLock::~MutexLock(void) void Magick::MutexLock::lock(void) { #if defined(MAGICKCORE_HAVE_PTHREAD) - int sysError; - if ( (sysError = ::pthread_mutex_lock( &_mutex )) == 0) + int + sysError; + + if ((sysError=::pthread_mutex_lock(&_mutex)) == 0) return; - throwExceptionExplicit( OptionError, "mutex lock failed", - strerror(sysError)); + throwExceptionExplicit(OptionError,"mutex lock failed", + strerror(sysError)); #endif #if defined(_MT) && defined(_VISUALC_) if (WaitForSingleObject(_mutex.id,INFINITE) != WAIT_FAILED) return; - throwExceptionExplicit( OptionError, "mutex lock failed" ); + throwExceptionExplicit(OptionError,"mutex lock failed"); #endif } @@ -93,15 +102,17 @@ void Magick::MutexLock::lock(void) void Magick::MutexLock::unlock(void) { #if defined(MAGICKCORE_HAVE_PTHREAD) - int sysError; - if ( (sysError = ::pthread_mutex_unlock( &_mutex )) == 0) + int + sysError; + + if ((sysError=::pthread_mutex_unlock(&_mutex)) == 0) return; - throwExceptionExplicit( OptionError, "mutex unlock failed", - strerror(sysError) ); + throwExceptionExplicit(OptionError,"mutex unlock failed", + strerror(sysError)); #endif #if defined(_MT) && defined(_VISUALC_) - if ( ReleaseSemaphore(_mutex.id, 1, NULL) == TRUE ) + if (ReleaseSemaphore(_mutex.id,1,(LPLONG) NULL) == TRUE) return; - throwExceptionExplicit( OptionError, "mutex unlock failed" ); + throwExceptionExplicit(OptionError,"mutex unlock failed"); #endif }