mail[Wesnoth-commits] r44027 - in /trunk/src: network_manager_ana.cpp network_manager_ana.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by billybiset on July 09, 2010 - 00:59:
Author: billynux
Date: Fri Jul  9 00:59:20 2010
New Revision: 44027

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44027&view=rev
Log:
Concurrency bug fix in ana_receive_handler -> please check diff if you have 
time.

Modified:
    trunk/src/network_manager_ana.cpp
    trunk/src/network_manager_ana.hpp

Modified: trunk/src/network_manager_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.cpp?rev=44027&r1=44026&r2=44027&view=diff
==============================================================================
--- trunk/src/network_manager_ana.cpp (original)
+++ trunk/src/network_manager_ana.cpp Fri Jul  9 00:59:20 2010
@@ -71,37 +71,41 @@
 ana_receive_handler::ana_receive_handler( ) :
     mutex_(),
     handler_mutex_(),
-    timeout_mutex_(),
+    timeout_called_mutex_(),
     error_code_(),
     buffer_(),
     receive_timer_( NULL ),
-    received_( false )
+    finished_( false )
 {
     std::cout << "DEBUG: Constructing a new ana_receive_handler...\n";
     mutex_.lock();
-    timeout_mutex_.lock();
+    timeout_called_mutex_.lock();
 }
 
 ana_receive_handler::~ana_receive_handler()
 {
-    boost::mutex::scoped_lock lock( handler_mutex_);
-
-    if ( receive_timer_ != NULL )
-        delete receive_timer_;
-
-    timeout_mutex_.lock();
-    timeout_mutex_.unlock();
+    timeout_called_mutex_.lock();
+    timeout_called_mutex_.unlock();
 }
 
 void ana_receive_handler::wait_completion(ana::detail::timed_sender* 
component, size_t timeout_ms )
 {
-    if (timeout_ms > 0)
-    {
-        receive_timer_ = component->create_timer();
-
-        receive_timer_->wait( ana::time::milliseconds(timeout_ms),
-                            
boost::bind(&ana_receive_handler::handle_timeout, this, ana::timeout_error ) 
);
-    }
+    {
+        boost::mutex::scoped_lock lock( handler_mutex_);
+        if ( finished_ )
+        {
+            mutex_.unlock();
+            timeout_called_mutex_.unlock();
+        }
+        else if ( timeout_ms > 0 )
+        {
+            receive_timer_ = component->create_timer();
+
+            receive_timer_->wait( ana::time::milliseconds(timeout_ms),
+                                
boost::bind(&ana_receive_handler::handle_timeout, this, ana::timeout_error ) 
);
+        }
+    }
+
     mutex_.lock();
     mutex_.unlock();
 }
@@ -110,44 +114,54 @@
 {
     boost::mutex::scoped_lock lock( handler_mutex_);
 
-    received_ = true;
-
     delete receive_timer_;
     receive_timer_ = NULL;
+
     buffer_ = read_buffer;
     error_code_ = error_c;
-    mutex_.unlock();
+
+    if (! finished_ )
+    {
+        finished_ = true;
+        mutex_.unlock();
+    }
 }
 
 void ana_receive_handler::handle_disconnect(ana::error_code error_c, 
ana::net_id)
 {
     boost::mutex::scoped_lock lock( handler_mutex_);
-
-    received_ = true;
 
     delete receive_timer_;
     receive_timer_ = NULL;
+
     error_code_ = error_c;
-    mutex_.unlock();
+    if (! finished_ )
+    {
+        finished_ = true;
+        mutex_.unlock();
+    }
 }
 
 void ana_receive_handler::handle_timeout(ana::error_code error_code)
 {
-    {
-        boost::mutex::scoped_lock lock( handler_mutex_ );
-
-        if (! received_ )
-        {
-            if (error_code)
-                std::cout << "DEBUG: Receive attempt timed out\n";
-            else
-                std::cout << "DEBUG: Shouldn't reach here\n";
-
-            error_code_ = error_code;
-            mutex_.unlock();
-        }
-    }
-    timeout_mutex_.unlock();
+    boost::mutex::scoped_lock lock( handler_mutex_ );
+
+    delete receive_timer_;
+    receive_timer_ = NULL;
+
+    if (! finished_ )
+    {
+        if (error_code)
+            std::cout << "DEBUG: Receive attempt timed out\n";
+        else
+            std::cout << "DEBUG: Shouldn't reach here\n";
+
+        error_code_ = error_code;
+        finished_ = true;
+        mutex_.unlock();
+    }
+
+    timeout_called_mutex_.unlock();
 }
 
 // Begin ana_connect_handler implementation 
------------------------------------------------------------

Modified: trunk/src/network_manager_ana.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.hpp?rev=44027&r1=44026&r2=44027&view=diff
==============================================================================
--- trunk/src/network_manager_ana.hpp (original)
+++ trunk/src/network_manager_ana.hpp Fri Jul  9 00:59:20 2010
@@ -120,11 +120,11 @@
 
         boost::mutex             mutex_;
         boost::mutex             handler_mutex_;
-        boost::mutex             timeout_mutex_;
+        boost::mutex             timeout_called_mutex_;
         ana::error_code          error_code_;
         ana::detail::read_buffer buffer_;
         ana::timer*              receive_timer_;
-        bool                     received_;
+        bool                     finished_;
 };
 
 




Related Messages


Powered by MHonArc, Updated Fri Jul 09 01:20:09 2010