Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74954 - in trunk/boost/asio/detail: . impl
From: chris_at_[hidden]
Date: 2011-10-15 19:56:22


Author: chris_kohlhoff
Date: 2011-10-15 19:56:21 EDT (Sat, 15 Oct 2011)
New Revision: 74954
URL: http://svn.boost.org/trac/boost/changeset/74954

Log:
Update descriptor state allocation to match approach used in epoll_reactor.

Text files modified:
   trunk/boost/asio/detail/impl/kqueue_reactor.ipp | 32 ++++++++++++++++++++------------
   trunk/boost/asio/detail/kqueue_reactor.hpp | 6 ++++++
   2 files changed, 26 insertions(+), 12 deletions(-)

Modified: trunk/boost/asio/detail/impl/kqueue_reactor.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/kqueue_reactor.ipp (original)
+++ trunk/boost/asio/detail/impl/kqueue_reactor.ipp 2011-10-15 19:56:21 EDT (Sat, 15 Oct 2011)
@@ -126,9 +126,10 @@
 int kqueue_reactor::register_descriptor(socket_type descriptor,
     kqueue_reactor::per_descriptor_data& descriptor_data)
 {
- mutex::scoped_lock lock(registered_descriptors_mutex_);
+ descriptor_data = allocate_descriptor_state();
+
+ mutex::scoped_lock lock(descriptor_data->mutex_);
 
- descriptor_data = registered_descriptors_.alloc();
   descriptor_data->descriptor_ = descriptor;
   descriptor_data->shutdown_ = false;
 
@@ -143,9 +144,10 @@
     int op_type, socket_type descriptor,
     kqueue_reactor::per_descriptor_data& descriptor_data, reactor_op* op)
 {
- mutex::scoped_lock lock(registered_descriptors_mutex_);
+ descriptor_data = allocate_descriptor_state();
+
+ mutex::scoped_lock lock(descriptor_data->mutex_);
 
- descriptor_data = registered_descriptors_.alloc();
   descriptor_data->descriptor_ = descriptor;
   descriptor_data->shutdown_ = false;
   descriptor_data->op_queue_[op_type].push(op);
@@ -304,7 +306,6 @@
     return;
 
   mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
- mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
 
   if (!descriptor_data->shutdown_)
   {
@@ -339,11 +340,9 @@
 
     descriptor_lock.unlock();
 
- registered_descriptors_.free(descriptor_data);
+ free_descriptor_state(descriptor_data);
     descriptor_data = 0;
 
- descriptors_lock.unlock();
-
     io_service_.post_deferred_completions(ops);
   }
 }
@@ -355,7 +354,6 @@
     return;
 
   mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);
- mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
 
   if (!descriptor_data->shutdown_)
   {
@@ -375,10 +373,8 @@
 
     descriptor_lock.unlock();
 
- registered_descriptors_.free(descriptor_data);
+ free_descriptor_state(descriptor_data);
     descriptor_data = 0;
-
- descriptors_lock.unlock();
   }
 }
 
@@ -511,6 +507,18 @@
   return fd;
 }
 
+kqueue_reactor::descriptor_state* kqueue_reactor::allocate_descriptor_state()
+{
+ mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
+ return registered_descriptors_.alloc();
+}
+
+void kqueue_reactor::free_descriptor_state(kqueue_reactor::descriptor_state* s)
+{
+ mutex::scoped_lock descriptors_lock(registered_descriptors_mutex_);
+ registered_descriptors_.free(s);
+}
+
 void kqueue_reactor::do_add_timer_queue(timer_queue_base& queue)
 {
   mutex::scoped_lock lock(mutex_);

Modified: trunk/boost/asio/detail/kqueue_reactor.hpp
==============================================================================
--- trunk/boost/asio/detail/kqueue_reactor.hpp (original)
+++ trunk/boost/asio/detail/kqueue_reactor.hpp 2011-10-15 19:56:21 EDT (Sat, 15 Oct 2011)
@@ -169,6 +169,12 @@
   // cannot be created.
   BOOST_ASIO_DECL static int do_kqueue_create();
 
+ // Allocate a new descriptor state object.
+ BOOST_ASIO_DECL descriptor_state* allocate_descriptor_state();
+
+ // Free an existing descriptor state object.
+ BOOST_ASIO_DECL void free_descriptor_state(descriptor_state* s);
+
   // Helper function to add a new timer queue.
   BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk