summaryrefslogtreecommitdiff
path: root/boost/interprocess/detail/windows_intermodule_singleton.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/interprocess/detail/windows_intermodule_singleton.hpp')
-rw-r--r--boost/interprocess/detail/windows_intermodule_singleton.hpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/boost/interprocess/detail/windows_intermodule_singleton.hpp b/boost/interprocess/detail/windows_intermodule_singleton.hpp
index a716e270a7..58102689da 100644
--- a/boost/interprocess/detail/windows_intermodule_singleton.hpp
+++ b/boost/interprocess/detail/windows_intermodule_singleton.hpp
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2009-2011. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2009-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@@ -11,12 +11,13 @@
#ifndef BOOST_INTERPROCESS_WINDOWS_INTERMODULE_SINGLETON_HPP
#define BOOST_INTERPROCESS_WINDOWS_INTERMODULE_SINGLETON_HPP
-#if defined(_MSC_VER)&&(_MSC_VER>=1200)
+#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
+#include <boost/container/string.hpp>
#if !defined(BOOST_INTERPROCESS_WINDOWS)
#error "This header can't be included from non-windows operating systems"
@@ -29,7 +30,7 @@
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/cstdint.hpp>
#include <string>
-#include <map>
+#include <boost/container/map.hpp>
namespace boost{
namespace interprocess{
@@ -49,7 +50,7 @@ namespace intermodule_singleton_helpers {
// max and current semaphore count.
class windows_semaphore_based_map
{
- typedef std::map<std::string, ref_count_ptr> map_type;
+ typedef boost::container::map<boost::container::string, ref_count_ptr> map_type;
public:
windows_semaphore_based_map()
@@ -68,8 +69,8 @@ class windows_semaphore_based_map
//in max_count and initial count parameters.
//Also, max count must be bigger than 0 and bigger or equal than initial count.
if(sizeof(void*) == sizeof(boost::uint32_t)){
- //This means that for 32 bit processes, a semaphore count (31 usable bits) is
- //enough to store 4 byte aligned memory (4GB -> 32 bits - 2 bits = 30 bits).
+ //This means that for 32 bit processes, a semaphore count (31 usable bits) is
+ //enough to store 4 byte aligned memory (4GB -> 32 bits - 2 bits = 30 bits).
//The max count will hold the pointer value and current semaphore count
//will be zero.
//
@@ -135,6 +136,7 @@ class windows_semaphore_based_map
success = success && m_sem_map.open_or_create
(name.c_str(), initial_count, max_count, perm, created);
if(!success){
+ delete m;
//winapi_xxx wrappers do the cleanup...
throw int(0);
}
@@ -181,7 +183,7 @@ class windows_semaphore_based_map
{
scoped_lock<winapi_mutex_wrapper> lck(m_mtx_lock);
map_type &map = this->get_map_unlocked();
- map_type::iterator it = map.find(std::string(name));
+ map_type::iterator it = map.find(boost::container::string(name));
if(it != map.end()){
return &it->second;
}
@@ -194,7 +196,7 @@ class windows_semaphore_based_map
{
scoped_lock<winapi_mutex_wrapper> lck(m_mtx_lock);
map_type &map = this->get_map_unlocked();
- map_type::iterator it = map.insert(map_type::value_type(std::string(name), ref)).first;
+ map_type::iterator it = map.insert(map_type::value_type(boost::container::string(name), ref)).first;
return &it->second;
}
@@ -202,7 +204,7 @@ class windows_semaphore_based_map
{
scoped_lock<winapi_mutex_wrapper> lck(m_mtx_lock);
map_type &map = this->get_map_unlocked();
- return map.erase(std::string(name)) != 0;
+ return map.erase(boost::container::string(name)) != 0;
}
template<class F>
@@ -217,14 +219,16 @@ class windows_semaphore_based_map
scoped_lock<winapi_mutex_wrapper> lck(m_mtx_lock);
m_sem_count.wait();
if(0 == m_sem_count.value()){
- delete &this->get_map_unlocked();
+ map_type &map = this->get_map_unlocked();
+ BOOST_ASSERT(map.empty());
+ delete &map;
}
//First close sems to protect this with the external mutex
m_sem_map.close();
m_sem_count.close();
//Once scoped_lock unlocks the mutex, the destructor will close the handle...
}
-
+
private:
winapi_mutex_wrapper m_mtx_lock;
winapi_semaphore_wrapper m_sem_map;
@@ -287,7 +291,7 @@ struct thread_safe_global_map_dependant<windows_semaphore_based_map>
} //namespace intermodule_singleton_helpers {
-template<typename C, bool LazyInit = true, bool Phoenix = true>
+template<typename C, bool LazyInit = true, bool Phoenix = false>
class windows_intermodule_singleton
: public intermodule_singleton_impl
< C