]> granicus.if.org Git - imagemagick/commitdiff
Code cleanup.
authordirk <dirk@git.imagemagick.org>
Fri, 26 Dec 2014 22:17:54 +0000 (22:17 +0000)
committerdirk <dirk@git.imagemagick.org>
Fri, 26 Dec 2014 22:17:54 +0000 (22:17 +0000)
Magick++/lib/Magick++/Thread.h
Magick++/lib/Thread.cpp

index f646364e3131a0c7d559f991cd1933f7ccc8cb79..f50520deab66b5904bbee5553ee81e2a17d2b8e3 100644 (file)
@@ -15,8 +15,9 @@
 #if defined(_VISUALC_)
 #include <windows.h>
 #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
index 55a4d8fb66c8e704f420c996020ab9300b9be010..695de5c14859af78b9e6fade7a8bbf62941ef532 100644 (file)
@@ -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
 }