Fix Klocwork errors in ConditionalWait, Mutex & ImageAttributes 40/51640/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 11 Nov 2015 15:35:04 +0000 (15:35 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 11 Nov 2015 15:35:04 +0000 (15:35 +0000)
Change-Id: Ib4423ab2670d8825cd41f0a9e6c696cd9f97582b

dali/devel-api/threading/conditional-wait.cpp
dali/devel-api/threading/mutex.cpp
dali/internal/common/image-attributes.cpp
dali/internal/common/mutex-impl.cpp

index 969d175..4a1ed8b 100644 (file)
 // CLASS HEADER
 #include <dali/devel-api/threading/conditional-wait.h>
 
-// INTERNAL INCLUDES
-#include <dali/internal/common/mutex-impl.h>
-
 // EXTERNAL INCLUDES
 #include <pthread.h>
+
+// INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/internal/common/mutex-impl.h>
 
 namespace Dali
 {
@@ -50,15 +50,27 @@ ConditionalWait::ScopedLock::~ScopedLock()
 ConditionalWait::ConditionalWait()
 : mImpl( new ConditionalWaitImpl )
 {
-  pthread_mutex_init( &mImpl->mutex, NULL );
-  pthread_cond_init( &mImpl->condition, NULL );
+  if( pthread_mutex_init( &mImpl->mutex, NULL ) )
+  {
+    DALI_LOG_ERROR( "Unable to initialise mutex in ConditionalWait" );
+  }
+  if( pthread_cond_init( &mImpl->condition, NULL ) )
+  {
+    DALI_LOG_ERROR( "Unable to initialise conditional" );
+  }
   mImpl->count = 0;
 }
 
 ConditionalWait::~ConditionalWait()
 {
-  pthread_cond_destroy( &mImpl->condition );
-  pthread_mutex_destroy( &mImpl->mutex );
+  if( pthread_cond_destroy( &mImpl->condition ) )
+  {
+    DALI_LOG_ERROR( "Unable to destroy conditional" );
+  }
+  if( pthread_mutex_destroy( &mImpl->mutex ) )
+  {
+    DALI_LOG_ERROR( "Unable to destroy mutex in ConditionalWait" );
+  }
   delete mImpl;
 }
 
@@ -72,7 +84,10 @@ void ConditionalWait::Notify()
   // broadcast all threads to continue
   if( 0 != previousCount )
   {
-    pthread_cond_broadcast( &mImpl->condition );
+    if( pthread_cond_broadcast( &mImpl->condition ) )
+    {
+      DALI_LOG_ERROR( "Error calling pthread_cond_broadcast" );
+    }
   }
   Internal::Mutex::Unlock( &mImpl->mutex );
 }
@@ -88,7 +103,10 @@ void ConditionalWait::Notify( const ScopedLock& scope )
   // broadcast all threads to continue
   if( 0 != previousCount )
   {
-    pthread_cond_broadcast( &mImpl->condition );
+    if( pthread_cond_broadcast( &mImpl->condition ) )
+    {
+      DALI_LOG_ERROR( "Error calling pthread_cond_broadcast" );
+    }
   }
 }
 
@@ -101,7 +119,11 @@ void ConditionalWait::Wait()
   do
   {
     // wait while condition changes
-    pthread_cond_wait( &mImpl->condition, &mImpl->mutex ); // releases the lock whilst waiting
+    if( pthread_cond_wait( &mImpl->condition, &mImpl->mutex ) ) // releases the lock whilst waiting
+    {
+      DALI_LOG_ERROR( "Error calling pthread_cond_wait" );
+      break;
+    }
   }
   while( 0 != mImpl->count );
   // when condition returns the mutex is locked so release the lock
@@ -120,7 +142,11 @@ void ConditionalWait::Wait( const ScopedLock& scope )
   do
   {
     // wait while condition changes
-    pthread_cond_wait( &mImpl->condition, &mImpl->mutex ); // releases the lock whilst waiting
+    if( pthread_cond_wait( &mImpl->condition, &mImpl->mutex ) ) // releases the lock whilst waiting
+    {
+      DALI_LOG_ERROR( "Error calling pthread_cond_wait" );
+      break;
+    }
   }
   while( 0 != mImpl->count );
 
index 8309b3b..fdb9cde 100644 (file)
 // CLASS HEADER
 #include <dali/devel-api/threading/mutex.h>
 
-// INTERNAL INCLUDES
-#include <dali/internal/common/mutex-impl.h>
-
 // EXTERNAL INCLUDES
 #include <pthread.h>
 
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali/internal/common/mutex-impl.h>
+
 namespace Dali
 {
 
@@ -36,13 +37,19 @@ struct Mutex::MutexImpl
 Mutex::Mutex()
 : mImpl( new MutexImpl )
 {
-  pthread_mutex_init( &mImpl->mutex, NULL );
+  if( pthread_mutex_init( &mImpl->mutex, NULL ) )
+  {
+    DALI_LOG_ERROR( "Unable to initialise Mutex" );
+  }
   mImpl->locked = false;
 }
 
 Mutex::~Mutex()
 {
-  pthread_mutex_destroy( &mImpl->mutex );
+  if( pthread_mutex_destroy( &mImpl->mutex ) )
+  {
+    DALI_LOG_ERROR( "Unable to destroy Mutex" );
+  }
   // nothing else to do as there is no Lock/Unlock API
   // ScopedLock destructor will always unlock the mutex
   delete mImpl;
index 134debc..25e53b8 100644 (file)
@@ -72,7 +72,6 @@ struct ImageAttributes::ImageAttributesImpl
   ScalingMode   scaling : 3;      ///< scaling option, ShrinkToFit is default
   FilterMode    filtering : 3;    ///< filtering option. Box is the default
   bool          mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
-  bool          isDistanceField : 1;  ///< true, if the image is a distancefield. Default is false.
 };
 
 
@@ -184,12 +183,6 @@ ImageAttributes ImageAttributes::New(unsigned int imageWidth, unsigned int image
  */
 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
 {
-  // Bail out if one is distance field and the other is not.
-  if (a.impl->isDistanceField != b.impl->isDistanceField)
-  {
-    return a.impl->isDistanceField < b.impl->isDistanceField;
-  }
-
   if (a.impl->width != b.impl->width)
   {
     return a.impl->width < b.impl->width;
index 9c57c7f..c046dc3 100644 (file)
@@ -30,6 +30,9 @@
 
 #endif // LOCK_BACKTRACE_ENABLED
 
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
 namespace Dali
 {
 #ifdef LOCK_BACKTRACE_ENABLED
@@ -104,12 +107,18 @@ void Lock( pthread_mutex_t* mutex )
 
 #endif // LOCK_BACKTRACE_ENABLED
 
-  pthread_mutex_lock( mutex );
+  if( pthread_mutex_lock( mutex ) )
+  {
+    DALI_LOG_ERROR( "Error calling pthread_mutex_lock" );
+  }
 }
 
 void Unlock( pthread_mutex_t* mutex )
 {
-  pthread_mutex_unlock( mutex );
+  if( pthread_mutex_unlock( mutex ) )
+  {
+    DALI_LOG_ERROR( "Error calling pthread_mutex_unlock" );
+  }
   --gThreadLockCount;
 }