summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/service_registry.hpp')
-rw-r--r--3rdParty/Boost/src/boost/asio/detail/service_registry.hpp195
1 files changed, 36 insertions, 159 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/service_registry.hpp b/3rdParty/Boost/src/boost/asio/detail/service_registry.hpp
index e640ec8..6ba30f1 100644
--- a/3rdParty/Boost/src/boost/asio/detail/service_registry.hpp
+++ b/3rdParty/Boost/src/boost/asio/detail/service_registry.hpp
@@ -1,6 +1,6 @@
//
-// service_registry.hpp
-// ~~~~~~~~~~~~~~~~~~~~
+// detail/service_registry.hpp
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
@@ -15,16 +15,11 @@
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
-#include <boost/asio/detail/push_options.hpp>
-
-#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/detail/config.hpp>
#include <typeinfo>
-#include <boost/asio/detail/pop_options.hpp>
-
-#include <boost/asio/io_service.hpp>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/noncopyable.hpp>
-#include <boost/asio/detail/service_id.hpp>
+#include <boost/asio/io_service.hpp>
#if defined(BOOST_NO_TYPEID)
# if !defined(BOOST_ASIO_NO_TYPEID)
@@ -32,6 +27,8 @@
# endif // !defined(BOOST_ASIO_NO_TYPEID)
#endif // defined(BOOST_NO_TYPEID)
+#include <boost/asio/detail/push_options.hpp>
+
namespace boost {
namespace asio {
namespace detail {
@@ -56,98 +53,43 @@ class service_registry
{
public:
// Constructor.
- service_registry(boost::asio::io_service& o)
- : owner_(o),
- first_service_(0)
- {
- }
+ BOOST_ASIO_DECL service_registry(boost::asio::io_service& o);
// Destructor.
- ~service_registry()
- {
- // Shutdown all services. This must be done in a separate loop before the
- // services are destroyed since the destructors of user-defined handler
- // objects may try to access other service objects.
- boost::asio::io_service::service* service = first_service_;
- while (service)
- {
- service->shutdown_service();
- service = service->next_;
- }
-
- // Destroy all services.
- while (first_service_)
- {
- boost::asio::io_service::service* next_service = first_service_->next_;
- destroy(first_service_);
- first_service_ = next_service;
- }
- }
+ BOOST_ASIO_DECL ~service_registry();
// Get the service object corresponding to the specified service type. Will
// create a new service object automatically if no such object already
// exists. Ownership of the service object is not transferred to the caller.
template <typename Service>
- Service& use_service()
- {
- boost::asio::io_service::service::key key;
- init_key(key, Service::id);
- factory_type factory = &service_registry::create<Service>;
- return *static_cast<Service*>(do_use_service(key, factory));
- }
+ Service& use_service();
- // Add a service object. Returns false on error, in which case ownership of
- // the object is retained by the caller.
+ // Add a service object. Throws on error, in which case ownership of the
+ // object is retained by the caller.
template <typename Service>
- bool add_service(Service* new_service)
- {
- boost::asio::io_service::service::key key;
- init_key(key, Service::id);
- return do_add_service(key, new_service);
- }
+ void add_service(Service* new_service);
// Check whether a service object of the specified type already exists.
template <typename Service>
- bool has_service() const
- {
- boost::asio::io_service::service::key key;
- init_key(key, Service::id);
- return do_has_service(key);
- }
+ bool has_service() const;
private:
// Initialise a service's key based on its id.
- void init_key(boost::asio::io_service::service::key& key,
- const boost::asio::io_service::id& id)
- {
- key.type_info_ = 0;
- key.id_ = &id;
- }
+ BOOST_ASIO_DECL static void init_key(
+ boost::asio::io_service::service::key& key,
+ const boost::asio::io_service::id& id);
#if !defined(BOOST_ASIO_NO_TYPEID)
// Initialise a service's key based on its id.
template <typename Service>
- void init_key(boost::asio::io_service::service::key& key,
- const boost::asio::detail::service_id<Service>& /*id*/)
- {
- key.type_info_ = &typeid(typeid_wrapper<Service>);
- key.id_ = 0;
- }
+ static void init_key(boost::asio::io_service::service::key& key,
+ const boost::asio::detail::service_id<Service>& /*id*/);
#endif // !defined(BOOST_ASIO_NO_TYPEID)
// Check if a service matches the given id.
- static bool keys_match(
+ BOOST_ASIO_DECL static bool keys_match(
const boost::asio::io_service::service::key& key1,
- const boost::asio::io_service::service::key& key2)
- {
- if (key1.id_ && key2.id_)
- if (key1.id_ == key2.id_)
- return true;
- if (key1.type_info_ && key2.type_info_)
- if (*key1.type_info_ == *key2.type_info_)
- return true;
- return false;
- }
+ const boost::asio::io_service::service::key& key2);
// The type of a factory function used for creating a service instance.
typedef boost::asio::io_service::service*
@@ -156,18 +98,15 @@ private:
// Factory function for creating a service instance.
template <typename Service>
static boost::asio::io_service::service* create(
- boost::asio::io_service& owner)
- {
- return new Service(owner);
- }
+ boost::asio::io_service& owner);
// Destroy a service instance.
- static void destroy(boost::asio::io_service::service* service)
- {
- delete service;
- }
+ BOOST_ASIO_DECL static void destroy(
+ boost::asio::io_service::service* service);
// Helper class to manage service pointers.
+ struct auto_service_ptr;
+ friend struct auto_service_ptr;
struct auto_service_ptr
{
boost::asio::io_service::service* ptr_;
@@ -177,86 +116,19 @@ private:
// Get the service object corresponding to the specified service key. Will
// create a new service object automatically if no such object already
// exists. Ownership of the service object is not transferred to the caller.
- boost::asio::io_service::service* do_use_service(
+ BOOST_ASIO_DECL boost::asio::io_service::service* do_use_service(
const boost::asio::io_service::service::key& key,
- factory_type factory)
- {
- boost::asio::detail::mutex::scoped_lock lock(mutex_);
-
- // First see if there is an existing service object with the given key.
- boost::asio::io_service::service* service = first_service_;
- while (service)
- {
- if (keys_match(service->key_, key))
- return service;
- service = service->next_;
- }
-
- // Create a new service object. The service registry's mutex is not locked
- // at this time to allow for nested calls into this function from the new
- // service's constructor.
- lock.unlock();
- auto_service_ptr new_service = { factory(owner_) };
- new_service.ptr_->key_ = key;
- lock.lock();
-
- // Check that nobody else created another service object of the same type
- // while the lock was released.
- service = first_service_;
- while (service)
- {
- if (keys_match(service->key_, key))
- return service;
- service = service->next_;
- }
-
- // Service was successfully initialised, pass ownership to registry.
- new_service.ptr_->next_ = first_service_;
- first_service_ = new_service.ptr_;
- new_service.ptr_ = 0;
- return first_service_;
- }
+ factory_type factory);
// Add a service object. Returns false on error, in which case ownership of
// the object is retained by the caller.
- bool do_add_service(
+ BOOST_ASIO_DECL void do_add_service(
const boost::asio::io_service::service::key& key,
- boost::asio::io_service::service* new_service)
- {
- boost::asio::detail::mutex::scoped_lock lock(mutex_);
-
- // Check if there is an existing service object with the given key.
- boost::asio::io_service::service* service = first_service_;
- while (service)
- {
- if (keys_match(service->key_, key))
- return false;
- service = service->next_;
- }
-
- // Take ownership of the service object.
- new_service->key_ = key;
- new_service->next_ = first_service_;
- first_service_ = new_service;
-
- return true;
- }
+ boost::asio::io_service::service* new_service);
// Check whether a service object with the specified key already exists.
- bool do_has_service(const boost::asio::io_service::service::key& key) const
- {
- boost::asio::detail::mutex::scoped_lock lock(mutex_);
-
- boost::asio::io_service::service* service = first_service_;
- while (service)
- {
- if (keys_match(service->key_, key))
- return true;
- service = service->next_;
- }
-
- return false;
- }
+ BOOST_ASIO_DECL bool do_has_service(
+ const boost::asio::io_service::service::key& key) const;
// Mutex to protect access to internal data.
mutable boost::asio::detail::mutex mutex_;
@@ -274,4 +146,9 @@ private:
#include <boost/asio/detail/pop_options.hpp>
+#include <boost/asio/detail/impl/service_registry.hpp>
+#if defined(BOOST_ASIO_HEADER_ONLY)
+# include <boost/asio/detail/impl/service_registry.ipp>
+#endif // defined(BOOST_ASIO_HEADER_ONLY)
+
#endif // BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP