[3.0] Fix Message Buffer leak and added DEBUG_ASSERT for leaking nodes
[platform/core/uifw/dali-core.git] / dali / internal / update / queue / update-message-queue.cpp
index 185b9bb..f6f7193 100644 (file)
@@ -1,35 +1,28 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/internal/update/queue/update-message-queue.h>
 
-// EXTERNAL INCLUDES
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wall"
-#include <boost/thread/mutex.hpp>
-#pragma clang diagnostic pop
-#else
-#include <boost/thread/mutex.hpp>
-#endif // ifdef __clang
-
 // INTERNAL INCLUDES
 #include <dali/public-api/common/vector-wrapper.h>
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/integration-api/render-controller.h>
+#include <dali/internal/common/message.h>
 #include <dali/internal/common/message-buffer.h>
 #include <dali/internal/render/common/performance-monitor.h>
 
@@ -57,7 +50,7 @@ static const std::size_t MAX_FREE_BUFFER_COUNT = 3; // Allow this number of buff
 typedef vector< MessageBuffer* > MessageBufferQueue;
 typedef MessageBufferQueue::iterator MessageBufferIter;
 
-typedef boost::mutex MessageQueueMutex;
+typedef Dali::Mutex MessageQueueMutex;
 
 } // unnamed namespace
 
@@ -83,7 +76,11 @@ struct MessageQueue::Impl
   ~Impl()
   {
     // Delete the current buffer
-    delete currentMessageBuffer;
+    if( currentMessageBuffer )
+    {
+      DeleteBufferContents( currentMessageBuffer );
+      delete currentMessageBuffer;
+    }
 
     // Delete the unprocessed buffers
     const MessageBufferIter processQueueEndIter = processQueue.end();
@@ -139,7 +136,7 @@ struct MessageQueue::Impl
   MessageBufferQueue       freeQueue;            ///< buffers from the recycleQueue; can be used without locking
 };
 
-MessageQueue::MessageQueue( RenderController& controller, const SceneGraphBuffers& buffers )
+MessageQueue::MessageQueue( Integration::RenderController& controller, const SceneGraph::SceneGraphBuffers& buffers )
 : mImpl(NULL)
 {
   mImpl = new Impl( controller, buffers );
@@ -155,7 +152,7 @@ void MessageQueue::EventProcessingStarted()
   mImpl->processingEvents = true;
 }
 
-unsigned int* MessageQueue::ReserveMessageSlot( std::size_t requestedSize, bool updateScene )
+unsigned int* MessageQueue::ReserveMessageSlot( unsigned int requestedSize, bool updateScene )
 {
   DALI_ASSERT_DEBUG( 0 != requestedSize );
 
@@ -201,11 +198,6 @@ unsigned int* MessageQueue::ReserveMessageSlot( std::size_t requestedSize, bool
   return mImpl->currentMessageBuffer->ReserveMessageSlot( requestedSize );
 }
 
-BufferIndex MessageQueue::GetEventBufferIndex() const
-{
-  return mImpl->sceneGraphBuffers.GetEventBufferIndex();
-}
-
 bool MessageQueue::FlushQueue()
 {
   const bool messagesToProcess = ( NULL != mImpl->currentMessageBuffer );
@@ -214,7 +206,7 @@ bool MessageQueue::FlushQueue()
   if ( messagesToProcess )
   {
     // queueMutex must be locked whilst accessing processQueue or recycleQueue
-    MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
+    MessageQueueMutex::ScopedLock lock( mImpl->queueMutex );
 
     mImpl->processQueue.push_back( mImpl->currentMessageBuffer );
     mImpl->currentMessageBuffer = NULL;
@@ -249,12 +241,12 @@ bool MessageQueue::FlushQueue()
   return messagesToProcess;
 }
 
-void MessageQueue::ProcessMessages()
+void MessageQueue::ProcessMessages( BufferIndex updateBufferIndex )
 {
   PERF_MONITOR_START(PerformanceMonitor::PROCESS_MESSAGES);
 
   // queueMutex must be locked whilst accessing queue
-  MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
+  MessageQueueMutex::ScopedLock lock( mImpl->queueMutex );
 
   const MessageBufferIter processQueueEndIter = mImpl->processQueue.end();
   for ( MessageBufferIter iter = mImpl->processQueue.begin(); iter != processQueueEndIter ; ++iter )
@@ -265,7 +257,7 @@ void MessageQueue::ProcessMessages()
     {
       MessageBase* message = reinterpret_cast< MessageBase* >( iter.Get() );
 
-      message->Process( mImpl->sceneGraphBuffers.GetUpdateBufferIndex() );
+      message->Process( updateBufferIndex  );
 
       // Call virtual destructor explictly; since delete will not be called after placement new
       message->~MessageBase();
@@ -274,10 +266,10 @@ void MessageQueue::ProcessMessages()
 
     // Pass back for use in the event-thread
     mImpl->recycleQueue.push_back( buffer );
-
-    mImpl->sceneUpdate >>= 1;
   }
 
+  mImpl->sceneUpdate >>= 1;
+
   mImpl->queueWasEmpty = mImpl->processQueue.empty(); // Flag whether we processed anything
 
   mImpl->processQueue.clear();