Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64332 - in trunk/boost/interprocess: . ipc mem_algo mem_algo/detail sync sync/emulation sync/posix
From: igaztanaga_at_[hidden]
Date: 2010-07-25 12:27:19


Author: igaztanaga
Date: 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
New Revision: 64332
URL: http://svn.boost.org/trac/boost/changeset/64332

Log:
Changes for Boost 1.45
Added:
   trunk/boost/interprocess/permissions.hpp (contents, props changed)
   trunk/boost/interprocess/sync/emulation/mutex.hpp (contents, props changed)
   trunk/boost/interprocess/sync/emulation/recursive_mutex.hpp (contents, props changed)
Removed:
   trunk/boost/interprocess/sync/emulation/interprocess_mutex.hpp
   trunk/boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp
Text files modified:
   trunk/boost/interprocess/exceptions.hpp | 23 ++++++++++------
   trunk/boost/interprocess/interprocess_fwd.hpp | 6 ++++
   trunk/boost/interprocess/ipc/message_queue.hpp | 27 ++++++++++++-------
   trunk/boost/interprocess/managed_external_buffer.hpp | 4 +-
   trunk/boost/interprocess/managed_heap_memory.hpp | 2
   trunk/boost/interprocess/managed_mapped_file.hpp | 13 +++++----
   trunk/boost/interprocess/managed_shared_memory.hpp | 9 +++---
   trunk/boost/interprocess/managed_windows_shared_memory.hpp | 10 ++++---
   trunk/boost/interprocess/mapped_region.hpp | 53 +++++++++++++++++++++------------------
   trunk/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp | 2
   trunk/boost/interprocess/mem_algo/rbtree_best_fit.hpp | 2
   trunk/boost/interprocess/offset_ptr.hpp | 9 +++---
   trunk/boost/interprocess/shared_memory_object.hpp | 31 +++++++++++++---------
   trunk/boost/interprocess/sync/emulation/interprocess_condition.hpp | 22 ----------------
   trunk/boost/interprocess/sync/file_lock.hpp | 2
   trunk/boost/interprocess/sync/interprocess_condition.hpp | 4 +-
   trunk/boost/interprocess/sync/interprocess_mutex.hpp | 49 ++++++++++++++++++++++--------------
   trunk/boost/interprocess/sync/interprocess_recursive_mutex.hpp | 50 +++++++++++++++++++++++++++----------
   trunk/boost/interprocess/sync/named_condition.hpp | 15 ++++++----
   trunk/boost/interprocess/sync/named_mutex.hpp | 25 ++++++++++--------
   trunk/boost/interprocess/sync/named_recursive_mutex.hpp | 15 ++++++----
   trunk/boost/interprocess/sync/named_semaphore.hpp | 28 +++++++++++---------
   trunk/boost/interprocess/sync/named_upgradable_mutex.hpp | 15 ++++++----
   trunk/boost/interprocess/sync/posix/interprocess_condition.hpp | 2
   trunk/boost/interprocess/sync/posix/pthread_helpers.hpp | 12 ++++----
   trunk/boost/interprocess/sync/posix/semaphore_wrapper.hpp | 11 ++++---
   trunk/boost/interprocess/windows_shared_memory.hpp | 18 +++++++------
   27 files changed, 259 insertions(+), 200 deletions(-)

Modified: trunk/boost/interprocess/exceptions.hpp
==============================================================================
--- trunk/boost/interprocess/exceptions.hpp (original)
+++ trunk/boost/interprocess/exceptions.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -33,30 +33,34 @@
 class interprocess_exception : public std::exception
 {
    public:
- interprocess_exception(error_code_t ec = other_error )
- : m_err(ec)
+ interprocess_exception(const char *err/*error_code_t ec = other_error*/)
+ : m_err(other_error)
    {
- try { m_str = "boost::interprocess_exception::library_error"; }
+// try { m_str = "boost::interprocess_exception::library_error"; }
+ try { m_str = err; }
       catch (...) {}
    }
-
+/*
    interprocess_exception(native_error_t sys_err_code)
       : m_err(sys_err_code)
    {
       try { fill_system_message(m_err.get_native_error(), m_str); }
       catch (...) {}
- }
+ }*/
 
- interprocess_exception(const error_info &err_info)
+ interprocess_exception(const error_info &err_info, const char *str = 0)
       : m_err(err_info)
    {
       try{
          if(m_err.get_native_error() != 0){
             fill_system_message(m_err.get_native_error(), m_str);
- }/*
+ }
+ else if(str){
+ m_str = str;
+ }
          else{
             m_str = "boost::interprocess_exception::library_error";
- }*/
+ }
       }
       catch(...){}
    }
@@ -132,7 +136,8 @@
 class bad_alloc : public interprocess_exception
 {
  public:
- virtual const char* what() const throw()
+ bad_alloc() : interprocess_exception("::boost::interprocess::bad_alloc"){}
+ virtual const char* what() const throw()
       { return "boost::interprocess::bad_alloc"; }
 };
 

Modified: trunk/boost/interprocess/interprocess_fwd.hpp
==============================================================================
--- trunk/boost/interprocess/interprocess_fwd.hpp (original)
+++ trunk/boost/interprocess/interprocess_fwd.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -56,6 +56,12 @@
 namespace boost { namespace interprocess {
 
 //////////////////////////////////////////////////////////////////////////////
+// permissions
+//////////////////////////////////////////////////////////////////////////////
+
+class permissions;
+
+//////////////////////////////////////////////////////////////////////////////
 // shared_memory
 //////////////////////////////////////////////////////////////////////////////
 

Modified: trunk/boost/interprocess/ipc/message_queue.hpp
==============================================================================
--- trunk/boost/interprocess/ipc/message_queue.hpp (original)
+++ trunk/boost/interprocess/ipc/message_queue.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -22,6 +22,7 @@
 #include <boost/interprocess/offset_ptr.hpp>
 #include <boost/interprocess/creation_tags.hpp>
 #include <boost/interprocess/exceptions.hpp>
+#include <boost/interprocess/permissions.hpp>
 #include <boost/detail/no_exceptions_support.hpp>
 #include <boost/interprocess/detail/type_traits.hpp>
 
@@ -56,7 +57,8 @@
    message_queue(create_only_t create_only,
                  const char *name,
                  std::size_t max_num_msg,
- std::size_t max_msg_size);
+ std::size_t max_msg_size,
+ const permissions &perm = permissions());
 
    //!Opens or creates a process shared message queue with name "name".
    //!If the queue is created, the maximum number of messages will be "max_num_msg"
@@ -66,7 +68,8 @@
    message_queue(open_or_create_t open_or_create,
                  const char *name,
                  std::size_t max_num_msg,
- std::size_t max_msg_size);
+ std::size_t max_msg_size,
+ const permissions &perm = permissions());
 
    //!Opens a previously created process shared message queue with name "name".
    //!If the was not previously created or there are no free resources,
@@ -379,7 +382,8 @@
 inline message_queue::message_queue(create_only_t create_only,
                                     const char *name,
                                     std::size_t max_num_msg,
- std::size_t max_msg_size)
+ std::size_t max_msg_size,
+ const permissions &perm)
       //Create shared memory and execute functor atomically
    : m_shmem(create_only,
               name,
@@ -387,13 +391,15 @@
               read_write,
               static_cast<void*>(0),
               //Prepare initialization functor
- detail::initialization_func_t (max_num_msg, max_msg_size))
+ detail::initialization_func_t (max_num_msg, max_msg_size),
+ perm)
 {}
 
 inline message_queue::message_queue(open_or_create_t open_or_create,
                                     const char *name,
                                     std::size_t max_num_msg,
- std::size_t max_msg_size)
+ std::size_t max_msg_size,
+ const permissions &perm)
       //Create shared memory and execute functor atomically
    : m_shmem(open_or_create,
               name,
@@ -401,7 +407,8 @@
               read_write,
               static_cast<void*>(0),
               //Prepare initialization functor
- detail::initialization_func_t (max_num_msg, max_msg_size))
+ detail::initialization_func_t (max_num_msg, max_msg_size),
+ perm)
 {}
 
 inline message_queue::message_queue(open_only_t open_only,
@@ -474,14 +481,14 @@
                while (p_hdr->is_full());
             break;
             default:
- throw interprocess_exception();
+ break;
          }
       }
       
       //Get the first free message from free message queue
       detail::msg_hdr_t *free_msg = p_hdr->free_msg();
       if (free_msg == 0) {
- throw interprocess_exception();
+ throw interprocess_exception("boost::interprocess::message_queue corrupted");
       }
 
       //Copy control data to the free message
@@ -568,7 +575,7 @@
 
             //Paranoia check
             default:
- throw interprocess_exception();
+ break;
          }
       }
 
@@ -577,7 +584,7 @@
 
       //Paranoia check
       if (top_msg == 0) {
- throw interprocess_exception();
+ throw interprocess_exception("boost::interprocess::message_queue corrupted");
       }
 
       //Get data from the message

Modified: trunk/boost/interprocess/managed_external_buffer.hpp
==============================================================================
--- trunk/boost/interprocess/managed_external_buffer.hpp (original)
+++ trunk/boost/interprocess/managed_external_buffer.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -60,7 +60,7 @@
       //Check if alignment is correct
       assert((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - std::size_t(1u)))));
       if(!base_t::create_impl(addr, size)){
- throw interprocess_exception();
+ throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
       }
    }
 
@@ -71,7 +71,7 @@
       //Check if alignment is correct
       assert((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - std::size_t(1u)))));
       if(!base_t::open_impl(addr, size)){
- throw interprocess_exception();
+ throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
       }
    }
 

Modified: trunk/boost/interprocess/managed_heap_memory.hpp
==============================================================================
--- trunk/boost/interprocess/managed_heap_memory.hpp (original)
+++ trunk/boost/interprocess/managed_heap_memory.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -67,7 +67,7 @@
    {
       if(!base_t::create_impl(&m_heapmem[0], size)){
          this->priv_close();
- throw interprocess_exception();
+ throw interprocess_exception("Could not initialize heap in basic_managed_heap_memory constructor");
       }
    }
 

Modified: trunk/boost/interprocess/managed_mapped_file.hpp
==============================================================================
--- trunk/boost/interprocess/managed_mapped_file.hpp (original)
+++ trunk/boost/interprocess/managed_mapped_file.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -23,6 +23,7 @@
 #include <boost/interprocess/detail/file_wrapper.hpp>
 #include <boost/interprocess/detail/move.hpp>
 #include <boost/interprocess/file_mapping.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 namespace boost {
 namespace interprocess {
@@ -71,9 +72,9 @@
    //!Creates mapped file and creates and places the segment manager.
    //!This can throw.
    basic_managed_mapped_file(create_only_t create_only, const char *name,
- std::size_t size, const void *addr = 0)
+ std::size_t size, const void *addr = 0, const permissions &perm = permissions())
       : m_mfile(create_only, name, size, read_write, addr,
- create_open_func_t(get_this_pointer(), detail::DoCreate))
+ create_open_func_t(get_this_pointer(), detail::DoCreate), perm)
    {}
 
    //!Creates mapped file and creates and places the segment manager if
@@ -82,17 +83,17 @@
    //!This can throw.
    basic_managed_mapped_file (open_or_create_t open_or_create,
                               const char *name, std::size_t size,
- const void *addr = 0)
- : m_mfile(open_or_create, name, size, read_write, addr,
+ const void *addr = 0, const permissions &perm = permissions())
+ : m_mfile(open_or_create, name, size, read_write, addr,
                 create_open_func_t(get_this_pointer(),
- detail::DoOpenOrCreate))
+ detail::DoOpenOrCreate), perm)
    {}
 
    //!Connects to a created mapped file and its segment manager.
    //!This can throw.
    basic_managed_mapped_file (open_only_t open_only, const char* name,
                               const void *addr = 0)
- : m_mfile(open_only, name, read_write, addr,
+ : m_mfile(open_only, name, read_write, addr,
                 create_open_func_t(get_this_pointer(),
                 detail::DoOpen))
    {}

Modified: trunk/boost/interprocess/managed_shared_memory.hpp
==============================================================================
--- trunk/boost/interprocess/managed_shared_memory.hpp (original)
+++ trunk/boost/interprocess/managed_shared_memory.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -23,6 +23,7 @@
 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
 #include <boost/interprocess/shared_memory_object.hpp>
 #include <boost/interprocess/creation_tags.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 namespace boost {
 
@@ -83,10 +84,10 @@
    //!Creates shared memory and creates and places the segment manager.
    //!This can throw.
    basic_managed_shared_memory(create_only_t create_only, const char *name,
- std::size_t size, const void *addr = 0)
+ std::size_t size, const void *addr = 0, const permissions& perm = permissions())
       : base_t()
       , base2_t(create_only, name, size, read_write, addr,
- create_open_func_t(get_this_pointer(), detail::DoCreate))
+ create_open_func_t(get_this_pointer(), detail::DoCreate), perm)
    {}
 
    //!Creates shared memory and creates and places the segment manager if
@@ -95,11 +96,11 @@
    //!This can throw.
    basic_managed_shared_memory (open_or_create_t open_or_create,
                               const char *name, std::size_t size,
- const void *addr = 0)
+ const void *addr = 0, const permissions& perm = permissions())
       : base_t()
       , base2_t(open_or_create, name, size, read_write, addr,
                 create_open_func_t(get_this_pointer(),
- detail::DoOpenOrCreate))
+ detail::DoOpenOrCreate), perm)
    {}
 
    //!Connects to a created shared memory and its segment manager.

Modified: trunk/boost/interprocess/managed_windows_shared_memory.hpp
==============================================================================
--- trunk/boost/interprocess/managed_windows_shared_memory.hpp (original)
+++ trunk/boost/interprocess/managed_windows_shared_memory.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -21,6 +21,7 @@
 #include <boost/interprocess/detail/managed_memory_impl.hpp>
 #include <boost/interprocess/creation_tags.hpp>
 #include <boost/interprocess/windows_shared_memory.hpp>
+#include <boost/interprocess/permissions.hpp>
 #include <boost/interprocess/detail/move.hpp>
 
 namespace boost {
@@ -74,9 +75,9 @@
    //!This can throw.
    basic_managed_windows_shared_memory
       (create_only_t create_only, const char *name,
- std::size_t size, const void *addr = 0)
+ std::size_t size, const void *addr = 0, const permissions &perm = permissions())
       : m_wshm(create_only, name, size, read_write, addr,
- create_open_func_t(get_this_pointer(), detail::DoCreate))
+ create_open_func_t(get_this_pointer(), detail::DoCreate), perm)
    {}
 
    //!Creates shared memory and creates and places the segment manager if
@@ -86,10 +87,11 @@
    basic_managed_windows_shared_memory
       (open_or_create_t open_or_create,
       const char *name, std::size_t size,
- const void *addr = 0)
+ const void *addr = 0,
+ const permissions &perm = permissions())
       : m_wshm(open_or_create, name, size, read_write, addr,
                 create_open_func_t(get_this_pointer(),
- detail::DoOpenOrCreate))
+ detail::DoOpenOrCreate), perm)
    {}
 
    //!Connects to a created shared memory and its segment manager.

Modified: trunk/boost/interprocess/mapped_region.hpp
==============================================================================
--- trunk/boost/interprocess/mapped_region.hpp (original)
+++ trunk/boost/interprocess/mapped_region.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -42,7 +42,7 @@
 #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
 
 //!\file
-//!Describes memory_mappable and mapped region classes
+//!Describes mapped region class
 
 namespace boost {
 namespace interprocess {
@@ -81,7 +81,17 @@
 
    //!Move constructor. *this will be constructed taking ownership of "other"'s
    //!region and "other" will be left in default constructor state.
- mapped_region(BOOST_INTERPROCESS_RV_REF(mapped_region) other);
+ mapped_region(BOOST_INTERPROCESS_RV_REF(mapped_region) other)
+ #if defined (BOOST_INTERPROCESS_WINDOWS)
+ : m_base(0), m_size(0), m_offset(0)
+ , m_extra_offset(0)
+ , m_mode(read_only)
+ , m_file_mapping_hnd(detail::invalid_file())
+ #else
+ : m_base(MAP_FAILED), m_size(0), m_offset(0), m_extra_offset(0), m_mode(read_only), m_is_xsi(false)
+ #endif
+ { this->swap(other); }
+
 
    //!Destroys the mapped region.
    //!Does not throw
@@ -89,7 +99,12 @@
 
    //!Move assignment. If *this owns a memory mapped region, it will be
    //!destroyed and it will take ownership of "other"'s memory mapped region.
- mapped_region &operator=(BOOST_INTERPROCESS_RV_REF(mapped_region) other);
+ mapped_region &operator=(BOOST_INTERPROCESS_RV_REF(mapped_region) other)
+ {
+ mapped_region tmp(boost::interprocess::move(other));
+ this->swap(tmp);
+ return *this;
+ }
 
    //!Returns the size of the mapping. Note for windows users: If
    //!windows_shared_memory is mapped using 0 as the size, it returns 0
@@ -154,13 +169,6 @@
 inline void swap(mapped_region &x, mapped_region &y)
 { x.swap(y); }
 
-inline mapped_region &mapped_region::operator=(BOOST_INTERPROCESS_RV_REF(mapped_region) moved)
-{
- mapped_region tmp(boost::interprocess::move(moved));
- this->swap(tmp);
- return *this;
-}
-
 inline mapped_region::~mapped_region()
 { this->priv_close(); }
 
@@ -176,20 +184,13 @@
 inline void* mapped_region::get_address() const
 { return m_base; }
 
-#if (defined BOOST_INTERPROCESS_WINDOWS)
+#if defined (BOOST_INTERPROCESS_WINDOWS)
 
 inline mapped_region::mapped_region()
    : m_base(0), m_size(0), m_offset(0), m_extra_offset(0), m_mode(read_only)
    , m_file_mapping_hnd(detail::invalid_file())
 {}
 
-inline mapped_region::mapped_region(BOOST_INTERPROCESS_RV_REF(mapped_region) other)
- : m_base(0), m_size(0), m_offset(0)
- , m_extra_offset(0)
- , m_mode(read_only)
- , m_file_mapping_hnd(detail::invalid_file())
-{ this->swap(other); }
-
 template<int dummy>
 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size()
 {
@@ -218,6 +219,7 @@
    switch(mode)
    {
       case read_only:
+ case read_private:
          file_map_access |= winapi::page_readonly;
          map_access |= winapi::file_map_read;
       break;
@@ -259,7 +261,7 @@
       //Create file mapping
       native_mapping_handle =
          winapi::create_file_mapping
- (detail::file_handle_from_mapping_handle(mapping.get_mapping_handle()), file_map_access, 0, 0, 0);
+ (detail::file_handle_from_mapping_handle(mapping.get_mapping_handle()), file_map_access, 0, 0, 0, 0);
 
       //Check if all is correct
       if(!native_mapping_handle){
@@ -350,7 +352,7 @@
    }
 
    //Flush it all
- return 0 == winapi::flush_view_of_file
+ return winapi::flush_view_of_file
       (static_cast<char*>(m_base)+mapping_offset,
        static_cast<std::size_t>(numbytes));
 }
@@ -378,10 +380,6 @@
    : m_base(MAP_FAILED), m_size(0), m_offset(0), m_extra_offset(0), m_mode(read_only), m_is_xsi(false)
 {}
 
-inline mapped_region::mapped_region(BOOST_INTERPROCESS_RV_REF(mapped_region) other)
- : m_base(MAP_FAILED), m_size(0), m_offset(0), m_extra_offset(0), m_mode(read_only), m_is_xsi(false)
-{ this->swap(other); }
-
 template<int dummy>
 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size()
 { return std::size_t(sysconf(_SC_PAGESIZE)); }
@@ -467,6 +465,11 @@
          flags |= MAP_SHARED;
       break;
 
+ case read_private:
+ prot |= (PROT_READ);
+ flags |= MAP_PRIVATE;
+ break;
+
       case read_write:
          prot |= (PROT_WRITE | PROT_READ);
          flags |= MAP_SHARED;
@@ -538,7 +541,7 @@
    }
    //Flush it all
    return msync(static_cast<char*>(m_base)+mapping_offset,
- numbytes, MS_SYNC) == 0;
+ numbytes, MS_ASYNC) == 0;
 }
 
 inline void mapped_region::priv_close()

Modified: trunk/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp
==============================================================================
--- trunk/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp (original)
+++ trunk/boost/interprocess/mem_algo/detail/simple_seq_fit_impl.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -595,7 +595,7 @@
                         void *reuse_ptr, std::size_t sizeof_object)
 {
    if(!sizeof_object)
- return std::pair<void *, bool>(static_cast<void*>(0), 0);
+ return std::pair<void *, bool>(static_cast<void*>(0), false);
    if(command & boost::interprocess::try_shrink_in_place){
       bool success = algo_impl_t::try_shrink
          ( this, reuse_ptr, limit_objects*sizeof_object

Modified: trunk/boost/interprocess/mem_algo/rbtree_best_fit.hpp
==============================================================================
--- trunk/boost/interprocess/mem_algo/rbtree_best_fit.hpp (original)
+++ trunk/boost/interprocess/mem_algo/rbtree_best_fit.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -656,7 +656,7 @@
                         void *reuse_ptr, std::size_t sizeof_object)
 {
    if(!sizeof_object)
- return std::pair<void *, bool>(static_cast<void*>(0), 0);
+ return std::pair<void *, bool>(static_cast<void*>(0), false);
    if(command & boost::interprocess::try_shrink_in_place){
       bool success = algo_impl_t::try_shrink
          ( this, reuse_ptr, limit_objects*sizeof_object

Modified: trunk/boost/interprocess/offset_ptr.hpp
==============================================================================
--- trunk/boost/interprocess/offset_ptr.hpp (original)
+++ trunk/boost/interprocess/offset_ptr.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -22,6 +22,7 @@
 #include <boost/interprocess/detail/utilities.hpp>
 #include <boost/interprocess/detail/cast_tags.hpp>
 #include <boost/interprocess/detail/mpl.hpp>
+#include <boost/pointer_cast.hpp>
 #include <boost/assert.hpp>
 #include <ostream>
 #include <istream>
@@ -330,7 +331,7 @@
 //!Simulation of static_cast between pointers. Never throws.
 template<class T, class U>
 inline boost::interprocess::offset_ptr<T>
- static_pointer_cast(boost::interprocess::offset_ptr<U> const & r)
+ static_pointer_cast(const boost::interprocess::offset_ptr<U> & r)
 {
    return boost::interprocess::offset_ptr<T>
             (r, boost::interprocess::detail::static_cast_tag());
@@ -339,7 +340,7 @@
 //!Simulation of const_cast between pointers. Never throws.
 template<class T, class U>
 inline boost::interprocess::offset_ptr<T>
- const_pointer_cast(boost::interprocess::offset_ptr<U> const & r)
+ const_pointer_cast(const boost::interprocess::offset_ptr<U> & r)
 {
    return boost::interprocess::offset_ptr<T>
             (r, boost::interprocess::detail::const_cast_tag());
@@ -348,7 +349,7 @@
 //!Simulation of dynamic_cast between pointers. Never throws.
 template<class T, class U>
 inline boost::interprocess::offset_ptr<T>
- dynamic_pointer_cast(boost::interprocess::offset_ptr<U> const & r)
+ dynamic_pointer_cast(const boost::interprocess::offset_ptr<U> & r)
 {
    return boost::interprocess::offset_ptr<T>
             (r, boost::interprocess::detail::dynamic_cast_tag());
@@ -357,7 +358,7 @@
 //!Simulation of reinterpret_cast between pointers. Never throws.
 template<class T, class U>
 inline boost::interprocess::offset_ptr<T>
- reinterpret_pointer_cast(boost::interprocess::offset_ptr<U> const & r)
+ reinterpret_pointer_cast(const boost::interprocess::offset_ptr<U> & r)
 {
    return boost::interprocess::offset_ptr<T>
             (r, boost::interprocess::detail::reinterpret_cast_tag());

Added: trunk/boost/interprocess/permissions.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/interprocess/permissions.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -0,0 +1,108 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2005-2009. 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)
+//
+// See http://www.boost.org/libs/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTERPROCESS_PERMISSIONS_HPP
+#define BOOST_INTERPROCESS_PERMISSIONS_HPP
+
+#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif
+
+#include <boost/interprocess/detail/config_begin.hpp>
+#include <boost/interprocess/detail/workaround.hpp>
+#include <boost/interprocess/interprocess_fwd.hpp>
+
+#if (defined BOOST_INTERPROCESS_WINDOWS)
+
+#include <boost/interprocess/detail/win32_api.hpp>
+
+#endif
+
+//!\file
+//!Describes permissions class
+
+namespace boost {
+namespace interprocess {
+
+#if (defined BOOST_INTERPROCESS_WINDOWS)
+
+namespace detail {
+
+template <int Dummy>
+struct unrestricted_permissions_holder
+{
+ static winapi::interprocess_all_access_security unrestricted;
+};
+
+template<int Dummy>
+winapi::interprocess_all_access_security unrestricted_permissions_holder<Dummy>::unrestricted;
+
+} //namespace detail {
+
+#endif //defined BOOST_INTERPROCESS_WINDOWS
+
+//!The permissions class represents permissions to be set to shared memory or
+//!files, that can be constructed form usual permission representations:
+//!a SECURITY_ATTRIBUTES pointer in windows or ORed rwx chmod integer in UNIX.
+class permissions
+{
+ /// @cond
+ #if (defined BOOST_INTERPROCESS_WINDOWS)
+ typedef void* os_permissions_type;
+ #else
+ typedef int os_permissions_type;
+ #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
+ os_permissions_type m_perm;
+ /// @endcond
+
+ public:
+ //!Constructs a permissions object from a user provided os-dependent
+ //!permissions.
+ permissions(os_permissions_type type)
+ : m_perm(type)
+ {}
+
+ //!Constructs a default permissions object:
+ //!A null security descriptor pointer for windows or 0644
+ //!for UNIX.
+ permissions()
+ { set_default(); }
+
+ void set_default()
+ {
+ #if (defined BOOST_INTERPROCESS_WINDOWS)
+ m_perm = 0;
+ #else
+ m_perm = 0644;
+ #endif
+ }
+
+ void set_unrestricted()
+ {
+ #if (defined BOOST_INTERPROCESS_WINDOWS)
+ m_perm = &detail::unrestricted_permissions_holder<0>::unrestricted;
+ #else
+ m_perm = 0666;
+ #endif
+ }
+
+ void set_permissions(os_permissions_type perm)
+ { m_perm = perm; }
+
+ os_permissions_type get_permissions() const
+ { return m_perm; }
+};
+
+} //namespace interprocess {
+} //namespace boost {
+
+#include <boost/interprocess/detail/config_end.hpp>
+
+#endif //BOOST_INTERPROCESS_PERMISSIONS_HPP

Modified: trunk/boost/interprocess/shared_memory_object.hpp
==============================================================================
--- trunk/boost/interprocess/shared_memory_object.hpp (original)
+++ trunk/boost/interprocess/shared_memory_object.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -20,6 +20,7 @@
 #include <boost/interprocess/exceptions.hpp>
 #include <boost/interprocess/detail/os_file_functions.hpp>
 #include <boost/interprocess/detail/tmp_dir_helpers.hpp>
+#include <boost/interprocess/permissions.hpp>
 #include <cstddef>
 #include <string>
 #include <algorithm>
@@ -56,19 +57,19 @@
 
    //!Creates a shared memory object with name "name" and mode "mode", with the access mode "mode"
    //!If the file previously exists, throws an error.*/
- shared_memory_object(create_only_t, const char *name, mode_t mode)
- { this->priv_open_or_create(detail::DoCreate, name, mode); }
+ shared_memory_object(create_only_t, const char *name, mode_t mode, const permissions &perm = permissions())
+ { this->priv_open_or_create(detail::DoCreate, name, mode, perm); }
 
    //!Tries to create a shared memory object with name "name" and mode "mode", with the
    //!access mode "mode". If the file previously exists, it tries to open it with mode "mode".
    //!Otherwise throws an error.
- shared_memory_object(open_or_create_t, const char *name, mode_t mode)
- { this->priv_open_or_create(detail::DoOpenOrCreate, name, mode); }
+ shared_memory_object(open_or_create_t, const char *name, mode_t mode, const permissions &perm = permissions())
+ { this->priv_open_or_create(detail::DoOpenOrCreate, name, mode, perm); }
 
    //!Tries to open a shared memory object with name "name", with the access mode "mode".
    //!If the file does not previously exist, it throws an error.
    shared_memory_object(open_only_t, const char *name, mode_t mode)
- { this->priv_open_or_create(detail::DoOpen, name, mode); }
+ { this->priv_open_or_create(detail::DoOpen, name, mode, permissions()); }
 
    //!Moves the ownership of "moved"'s shared memory object to *this.
    //!After the call, "moved" does not represent any shared memory object.
@@ -126,7 +127,7 @@
    void priv_close();
 
    //!Closes a previously opened file mapping. Never throws.
- bool priv_open_or_create(detail::create_enum_t type, const char *filename, mode_t mode);
+ bool priv_open_or_create(detail::create_enum_t type, const char *filename, mode_t mode, const permissions &perm);
 
    file_handle_t m_handle;
    mode_t m_mode;
@@ -168,11 +169,11 @@
 #if !defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
 
 inline bool shared_memory_object::priv_open_or_create
- (detail::create_enum_t type, const char *filename, mode_t mode)
+ (detail::create_enum_t type, const char *filename, mode_t mode, const permissions &perm)
 {
    m_filename = filename;
    std::string shmfile;
- detail::create_tmp_dir_and_get_filename(filename, shmfile);
+ detail::create_tmp_and_clean_old_and_get_filename(filename, shmfile);
 
    //Set accesses
    if (mode != read_write && mode != read_only){
@@ -185,10 +186,10 @@
          m_handle = detail::open_existing_file(shmfile.c_str(), mode, true);
       break;
       case detail::DoCreate:
- m_handle = detail::create_new_file(shmfile.c_str(), mode, true);
+ m_handle = detail::create_new_file(shmfile.c_str(), mode, perm, true);
       break;
       case detail::DoOpenOrCreate:
- m_handle = detail::create_or_open_file(shmfile.c_str(), mode, true);
+ m_handle = detail::create_or_open_file(shmfile.c_str(), mode, perm, true);
       break;
       default:
          {
@@ -242,12 +243,12 @@
 inline bool shared_memory_object::priv_open_or_create
    (detail::create_enum_t type,
     const char *filename,
- mode_t mode)
+ mode_t mode, const permissions &perm)
 {
    #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
    detail::add_leading_slash(filename, m_filename);
    #else
- detail::create_tmp_dir_and_get_filename(filename, m_filename);
+ detail::create_tmp_and_clean_old_and_get_filename(filename, m_filename);
    #endif
 
    //Create new mapping
@@ -281,7 +282,11 @@
    }
 
    //Open file using POSIX API
- m_handle = shm_open(m_filename.c_str(), oflag, S_IRWXO | S_IRWXG | S_IRWXU);
+ m_handle = shm_open(m_filename.c_str(), oflag, perm.get_permissions());
+
+ if(m_handle >= 0){
+ ::fchmod(m_handle, perm.get_permissions());
+ }
 
    //Check for error
    if(m_handle == -1){

Modified: trunk/boost/interprocess/sync/emulation/interprocess_condition.hpp
==============================================================================
--- trunk/boost/interprocess/sync/emulation/interprocess_condition.hpp (original)
+++ trunk/boost/interprocess/sync/emulation/interprocess_condition.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -155,28 +155,6 @@
          break;
       }
       else{
- //Notification occurred, we will lock the checking interprocess_mutex so that
- //if a notify_one notification occurs, only one thread can exit
- //---------------------------------------------------------------
- /*
- InternalLock lock;
- if(tout_enabled){
- InternalLock dummy(m_check_mut, abs_time);
- lock = boost::interprocess::move(dummy);
- }
- else{
- InternalLock dummy(m_check_mut);
- lock = boost::interprocess::move(dummy);
- }
- if(!lock){
- timed_out = true;
- unlock_enter_mut = true;
- detail::atomic_dec32(const_cast<boost::uint32_t*>(&m_num_waiters));
- break;
- }
- //---------------------------------------------------------------
- */
- //InternalLock lock(m_check_mut);
          boost::uint32_t result = detail::atomic_cas32
                         (const_cast<boost::uint32_t*>(&m_command), SLEEP, NOTIFY_ONE);
          if(result == SLEEP){

Deleted: trunk/boost/interprocess/sync/emulation/interprocess_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/emulation/interprocess_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
+++ (empty file)
@@ -1,81 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Ion Gaztanaga 2005-2009. 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)
-//
-// See http://www.boost.org/libs/interprocess for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
-
-namespace boost {
-
-namespace interprocess {
-
-inline interprocess_mutex::interprocess_mutex()
- : m_s(0)
-{
- //Note that this class is initialized to zero.
- //So zeroed memory can be interpreted as an
- //initialized mutex
-}
-
-inline interprocess_mutex::~interprocess_mutex()
-{
- //Trivial destructor
-}
-
-inline void interprocess_mutex::lock(void)
-{
- do{
- boost::uint32_t prev_s = detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
-
- if (m_s == 1 && prev_s == 0){
- break;
- }
- // relinquish current timeslice
- detail::thread_yield();
- }while (true);
-}
-
-inline bool interprocess_mutex::try_lock(void)
-{
- boost::uint32_t prev_s = detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
- return m_s == 1 && prev_s == 0;
-}
-
-inline bool interprocess_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
-{
- if(abs_time == boost::posix_time::pos_infin){
- this->lock();
- return true;
- }
- //Obtain current count and target time
- boost::posix_time::ptime now = microsec_clock::universal_time();
-
- if(now >= abs_time) return false;
-
- do{
- if(this->try_lock()){
- break;
- }
- now = microsec_clock::universal_time();
-
- if(now >= abs_time){
- return false;
- }
- // relinquish current time slice
- detail::thread_yield();
- }while (true);
-
- return true;
-}
-
-inline void interprocess_mutex::unlock(void)
-{ detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 0, 1); }
-
-} //namespace interprocess {
-
-} //namespace boost {

Deleted: trunk/boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
+++ (empty file)
@@ -1,128 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Ion Gaztanaga 2005-2009. 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)
-//
-// See http://www.boost.org/libs/interprocess for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-// Parts of the pthread code come from Boost Threads code:
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-// Copyright (C) 2001-2003
-// William E. Kempf
-//
-// Permission to use, copy, modify, distribute and sell this software
-// and its documentation for any purpose is hereby granted without fee,
-// provided that the above copyright notice appear in all copies and
-// that both that copyright notice and this permission notice appear
-// in supporting documentation. William E. Kempf makes no representations
-// about the suitability of this software for any purpose.
-// It is provided "as is" without express or implied warranty.
-//////////////////////////////////////////////////////////////////////////////
-
-#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
-#include <boost/interprocess/detail/os_thread_functions.hpp>
-#include <boost/interprocess/exceptions.hpp>
-
-namespace boost {
-
-namespace interprocess {
-
-inline interprocess_recursive_mutex::interprocess_recursive_mutex()
- : m_nLockCount(0), m_nOwner(detail::get_invalid_systemwide_thread_id()){}
-
-inline interprocess_recursive_mutex::~interprocess_recursive_mutex(){}
-
-inline void interprocess_recursive_mutex::lock()
-{
- typedef detail::OS_systemwide_thread_id_t handle_t;
- const handle_t thr_id(detail::get_current_systemwide_thread_id());
- handle_t old_id;
- detail::systemwide_thread_id_copy(m_nOwner, old_id);
- if(detail::equal_systemwide_thread_id(thr_id , old_id)){
- if((unsigned int)(m_nLockCount+1) == 0){
- //Overflow, throw an exception
- throw interprocess_exception();
- }
- ++m_nLockCount;
- }
- else{
- m_mutex.lock();
- detail::systemwide_thread_id_copy(thr_id, m_nOwner);
- m_nLockCount = 1;
- }
-}
-
-inline bool interprocess_recursive_mutex::try_lock()
-{
- typedef detail::OS_systemwide_thread_id_t handle_t;
- handle_t thr_id(detail::get_current_systemwide_thread_id());
- handle_t old_id;
- detail::systemwide_thread_id_copy(m_nOwner, old_id);
- if(detail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
- if((unsigned int)(m_nLockCount+1) == 0){
- //Overflow, throw an exception
- throw interprocess_exception();
- }
- ++m_nLockCount;
- return true;
- }
- if(m_mutex.try_lock()){
- detail::systemwide_thread_id_copy(thr_id, m_nOwner);
- m_nLockCount = 1;
- return true;
- }
- return false;
-}
-
-inline bool interprocess_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
-{
- typedef detail::OS_systemwide_thread_id_t handle_t;
- if(abs_time == boost::posix_time::pos_infin){
- this->lock();
- return true;
- }
- const handle_t thr_id(detail::get_current_systemwide_thread_id());
- handle_t old_id;
- detail::systemwide_thread_id_copy(m_nOwner, old_id);
- if(detail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
- if((unsigned int)(m_nLockCount+1) == 0){
- //Overflow, throw an exception
- throw interprocess_exception();
- }
- ++m_nLockCount;
- return true;
- }
- if(m_mutex.timed_lock(abs_time)){
- detail::systemwide_thread_id_copy(thr_id, m_nOwner);
- m_nLockCount = 1;
- return true;
- }
- return false;
-}
-
-inline void interprocess_recursive_mutex::unlock()
-{
- typedef detail::OS_systemwide_thread_id_t handle_t;
- handle_t old_id;
- detail::systemwide_thread_id_copy(m_nOwner, old_id);
- const handle_t thr_id(detail::get_current_systemwide_thread_id());
- (void)old_id;
- (void)thr_id;
- assert(detail::equal_systemwide_thread_id(thr_id, old_id));
- --m_nLockCount;
- if(!m_nLockCount){
- const handle_t new_id(detail::get_invalid_systemwide_thread_id());
- detail::systemwide_thread_id_copy(new_id, m_nOwner);
- m_mutex.unlock();
- }
-}
-
-} //namespace interprocess {
-
-} //namespace boost {
-

Added: trunk/boost/interprocess/sync/emulation/mutex.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/interprocess/sync/emulation/mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -0,0 +1,114 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2005-2009. 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)
+//
+// See http://www.boost.org/libs/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP
+#define BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP
+
+#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif
+
+#include <boost/interprocess/detail/config_begin.hpp>
+#include <boost/interprocess/detail/workaround.hpp>
+#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
+#include <cassert>
+#include <boost/interprocess/detail/atomic.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/interprocess/detail/os_thread_functions.hpp>
+
+namespace boost {
+namespace interprocess {
+namespace detail {
+
+class emulation_mutex
+{
+ emulation_mutex(const emulation_mutex &);
+ emulation_mutex &operator=(const emulation_mutex &);
+ public:
+
+ emulation_mutex();
+ ~emulation_mutex();
+
+ void lock();
+ bool try_lock();
+ bool timed_lock(const boost::posix_time::ptime &abs_time);
+ void unlock();
+ void take_ownership(){};
+ private:
+ volatile boost::uint32_t m_s;
+};
+
+inline emulation_mutex::emulation_mutex()
+ : m_s(0)
+{
+ //Note that this class is initialized to zero.
+ //So zeroed memory can be interpreted as an
+ //initialized mutex
+}
+
+inline emulation_mutex::~emulation_mutex()
+{
+ //Trivial destructor
+}
+
+inline void emulation_mutex::lock(void)
+{
+ do{
+ boost::uint32_t prev_s = detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
+
+ if (m_s == 1 && prev_s == 0){
+ break;
+ }
+ // relinquish current timeslice
+ detail::thread_yield();
+ }while (true);
+}
+
+inline bool emulation_mutex::try_lock(void)
+{
+ boost::uint32_t prev_s = detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
+ return m_s == 1 && prev_s == 0;
+}
+
+inline bool emulation_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
+{
+ if(abs_time == boost::posix_time::pos_infin){
+ this->lock();
+ return true;
+ }
+ //Obtain current count and target time
+ boost::posix_time::ptime now = microsec_clock::universal_time();
+
+ if(now >= abs_time) return false;
+
+ do{
+ if(this->try_lock()){
+ break;
+ }
+ now = microsec_clock::universal_time();
+
+ if(now >= abs_time){
+ return false;
+ }
+ // relinquish current time slice
+ detail::thread_yield();
+ }while (true);
+
+ return true;
+}
+
+inline void emulation_mutex::unlock(void)
+{ detail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 0, 1); }
+
+} //namespace detail {
+} //namespace interprocess {
+} //namespace boost {
+
+#endif //BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP

Added: trunk/boost/interprocess/sync/emulation/recursive_mutex.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/interprocess/sync/emulation/recursive_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -0,0 +1,166 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2005-2009. 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)
+//
+// See http://www.boost.org/libs/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// Parts of the pthread code come from Boost Threads code:
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2001-2003
+// William E. Kempf
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. William E. Kempf makes no representations
+// about the suitability of this software for any purpose.
+// It is provided "as is" without express or implied warranty.
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP
+#define BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP
+
+#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
+#include <boost/interprocess/detail/os_thread_functions.hpp>
+#include <boost/interprocess/exceptions.hpp>
+#include <boost/interprocess/detail/atomic.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/interprocess/detail/os_thread_functions.hpp>
+#include <boost/interprocess/sync/emulation/mutex.hpp>
+
+namespace boost {
+namespace interprocess {
+namespace detail {
+
+class emulation_recursive_mutex
+{
+ emulation_recursive_mutex(const emulation_recursive_mutex &);
+ emulation_recursive_mutex &operator=(const emulation_recursive_mutex &);
+ public:
+
+ emulation_recursive_mutex();
+ ~emulation_recursive_mutex();
+
+ void lock();
+ bool try_lock();
+ bool timed_lock(const boost::posix_time::ptime &abs_time);
+ void unlock();
+ void take_ownership();
+ private:
+ emulation_mutex m_mutex;
+ unsigned int m_nLockCount;
+ volatile detail::OS_systemwide_thread_id_t m_nOwner;
+ volatile boost::uint32_t m_s;
+};
+
+inline emulation_recursive_mutex::emulation_recursive_mutex()
+ : m_nLockCount(0), m_nOwner(detail::get_invalid_systemwide_thread_id()){}
+
+inline emulation_recursive_mutex::~emulation_recursive_mutex(){}
+
+inline void emulation_recursive_mutex::lock()
+{
+ typedef detail::OS_systemwide_thread_id_t handle_t;
+ const handle_t thr_id(detail::get_current_systemwide_thread_id());
+ handle_t old_id;
+ detail::systemwide_thread_id_copy(m_nOwner, old_id);
+ if(detail::equal_systemwide_thread_id(thr_id , old_id)){
+ if((unsigned int)(m_nLockCount+1) == 0){
+ //Overflow, throw an exception
+ throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
+ }
+ ++m_nLockCount;
+ }
+ else{
+ m_mutex.lock();
+ detail::systemwide_thread_id_copy(thr_id, m_nOwner);
+ m_nLockCount = 1;
+ }
+}
+
+inline bool emulation_recursive_mutex::try_lock()
+{
+ typedef detail::OS_systemwide_thread_id_t handle_t;
+ handle_t thr_id(detail::get_current_systemwide_thread_id());
+ handle_t old_id;
+ detail::systemwide_thread_id_copy(m_nOwner, old_id);
+ if(detail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
+ if((unsigned int)(m_nLockCount+1) == 0){
+ //Overflow, throw an exception
+ throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
+ }
+ ++m_nLockCount;
+ return true;
+ }
+ if(m_mutex.try_lock()){
+ detail::systemwide_thread_id_copy(thr_id, m_nOwner);
+ m_nLockCount = 1;
+ return true;
+ }
+ return false;
+}
+
+inline bool emulation_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
+{
+ typedef detail::OS_systemwide_thread_id_t handle_t;
+ if(abs_time == boost::posix_time::pos_infin){
+ this->lock();
+ return true;
+ }
+ const handle_t thr_id(detail::get_current_systemwide_thread_id());
+ handle_t old_id;
+ detail::systemwide_thread_id_copy(m_nOwner, old_id);
+ if(detail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
+ if((unsigned int)(m_nLockCount+1) == 0){
+ //Overflow, throw an exception
+ throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
+ }
+ ++m_nLockCount;
+ return true;
+ }
+ if(m_mutex.timed_lock(abs_time)){
+ detail::systemwide_thread_id_copy(thr_id, m_nOwner);
+ m_nLockCount = 1;
+ return true;
+ }
+ return false;
+}
+
+inline void emulation_recursive_mutex::unlock()
+{
+ typedef detail::OS_systemwide_thread_id_t handle_t;
+ handle_t old_id;
+ detail::systemwide_thread_id_copy(m_nOwner, old_id);
+ const handle_t thr_id(detail::get_current_systemwide_thread_id());
+ (void)old_id;
+ (void)thr_id;
+ assert(detail::equal_systemwide_thread_id(thr_id, old_id));
+ --m_nLockCount;
+ if(!m_nLockCount){
+ const handle_t new_id(detail::get_invalid_systemwide_thread_id());
+ detail::systemwide_thread_id_copy(new_id, m_nOwner);
+ m_mutex.unlock();
+ }
+}
+
+inline void emulation_recursive_mutex::take_ownership()
+{
+ typedef detail::OS_systemwide_thread_id_t handle_t;
+ this->m_nLockCount = 1;
+ const handle_t thr_id(detail::get_current_systemwide_thread_id());
+ detail::systemwide_thread_id_copy
+ (thr_id, m_nOwner);
+}
+
+} //namespace detail {
+} //namespace interprocess {
+} //namespace boost {
+
+#endif //BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP

Modified: trunk/boost/interprocess/sync/file_lock.hpp
==============================================================================
--- trunk/boost/interprocess/sync/file_lock.hpp (original)
+++ trunk/boost/interprocess/sync/file_lock.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -201,7 +201,7 @@
 
 inline file_lock::file_lock(const char *name)
 {
- m_file_hnd = detail::open_existing_file(name);
+ m_file_hnd = detail::open_existing_file(name, read_write);
 
    if(m_file_hnd == detail::invalid_file()){
       error_info err(system_error_code());

Modified: trunk/boost/interprocess/sync/interprocess_condition.hpp
==============================================================================
--- trunk/boost/interprocess/sync/interprocess_condition.hpp (original)
+++ trunk/boost/interprocess/sync/interprocess_condition.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -148,8 +148,8 @@
 
    #if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
       enum { SLEEP = 0, NOTIFY_ONE, NOTIFY_ALL };
- interprocess_mutex m_enter_mut;
- //interprocess_mutex m_check_mut;
+ interprocess_mutex m_enter_mut;
+ //interprocess_mutex m_check_mut;
       volatile boost::uint32_t m_command;
       volatile boost::uint32_t m_num_waiters;
       bool do_timed_wait(bool tout_enabled, const boost::posix_time::ptime &abs_time, interprocess_mutex &mut);

Modified: trunk/boost/interprocess/sync/interprocess_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/interprocess_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/interprocess_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -11,18 +11,6 @@
 // Parts of the pthread code come from Boost Threads code.
 //
 //////////////////////////////////////////////////////////////////////////////
-//
-// Copyright (C) 2001-2003
-// William E. Kempf
-//
-// Permission to use, copy, modify, distribute and sell this software
-// and its documentation for any purpose is hereby granted without fee,
-// provided that the above copyright notice appear in all copies and
-// that both that copyright notice and this permission notice appear
-// in supporting documentation. William E. Kempf makes no representations
-// about the suitability of this software for any purpose.
-// It is provided "as is" without express or implied warranty.
-//////////////////////////////////////////////////////////////////////////////
 
 #ifndef BOOST_INTERPROCESS_MUTEX_HPP
 #define BOOST_INTERPROCESS_MUTEX_HPP
@@ -44,10 +32,19 @@
    #include <boost/interprocess/sync/posix/pthread_helpers.hpp>
    #define BOOST_INTERPROCESS_USE_POSIX
 #else
- #include <boost/interprocess/detail/atomic.hpp>
- #include <boost/cstdint.hpp>
- #include <boost/interprocess/detail/os_thread_functions.hpp>
+ #include <boost/interprocess/sync/emulation/mutex.hpp>
    #define BOOST_INTERPROCESS_USE_GENERIC_EMULATION
+
+namespace boost {
+namespace interprocess {
+namespace detail{
+namespace robust_emulation_helpers {
+
+template<class T>
+class mutex_traits;
+
+}}}}
+
 #endif
 
 /// @endcond
@@ -111,7 +108,9 @@
    private:
 
    #if defined(BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
- volatile boost::uint32_t m_s;
+ friend class detail::robust_emulation_helpers::mutex_traits<interprocess_mutex>;
+ void take_ownership(){ mutex.take_ownership(); }
+ detail::emulation_mutex mutex;
    #elif defined(BOOST_INTERPROCESS_USE_POSIX)
       pthread_mutex_t m_mut;
    #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
@@ -119,17 +118,29 @@
 };
 
 } //namespace interprocess {
-
 } //namespace boost {
 
 #ifdef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
 # undef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
-# include <boost/interprocess/sync/emulation/interprocess_mutex.hpp>
+
+namespace boost {
+namespace interprocess {
+
+inline interprocess_mutex::interprocess_mutex(){}
+inline interprocess_mutex::~interprocess_mutex(){}
+inline void interprocess_mutex::lock(){ mutex.lock(); }
+inline bool interprocess_mutex::try_lock(){ return mutex.try_lock(); }
+inline bool interprocess_mutex::timed_lock(const boost::posix_time::ptime &abs_time){ return mutex.timed_lock(abs_time); }
+inline void interprocess_mutex::unlock(){ mutex.unlock(); }
+
+} //namespace interprocess {
+} //namespace boost {
+
 #endif
 
 #ifdef BOOST_INTERPROCESS_USE_POSIX
+#include <boost/interprocess/sync/posix/interprocess_mutex.hpp>
 # undef BOOST_INTERPROCESS_USE_POSIX
-# include <boost/interprocess/sync/posix/interprocess_mutex.hpp>
 #endif
 
 #include <boost/interprocess/detail/config_end.hpp>

Modified: trunk/boost/interprocess/sync/interprocess_recursive_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/interprocess_recursive_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/interprocess_recursive_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -45,20 +45,29 @@
    #include <boost/interprocess/sync/posix/pthread_helpers.hpp>
    #define BOOST_INTERPROCESS_USE_POSIX
 #else
- #include <boost/interprocess/detail/atomic.hpp>
- #include <boost/cstdint.hpp>
- #include <boost/interprocess/detail/os_thread_functions.hpp>
- #include <boost/interprocess/sync/interprocess_mutex.hpp>
+ #include <boost/interprocess/sync/emulation/recursive_mutex.hpp>
    #define BOOST_INTERPROCESS_USE_GENERIC_EMULATION
 #endif
 
+#if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
+namespace boost {
+namespace interprocess {
+namespace detail{
+namespace robust_emulation_helpers {
+
+template<class T>
+class mutex_traits;
+
+}}}}
+
+#endif
+
 /// @endcond
 
 //!\file
 //!Describes interprocess_recursive_mutex and shared_recursive_try_mutex classes
 
 namespace boost {
-
 namespace interprocess {
 
 //!Wraps a interprocess_mutex that can be placed in shared memory and can be
@@ -86,13 +95,13 @@
    //! mutex must be unlocked by the same mutex. The mutex must be unlocked
    //! the same number of times it is locked.
    //!Throws: interprocess_exception on error.
- void lock(void);
+ void lock();
 
    //!Tries to lock the interprocess_mutex, returns false when interprocess_mutex
    //!is already locked, returns true when success. The mutex must be unlocked
    //!the same number of times it is locked.
    //!Throws: interprocess_exception if a severe error is found
- bool try_lock(void);
+ bool try_lock();
 
    //!Tries to lock the interprocess_mutex, if interprocess_mutex can't be locked before
    //!abs_time time, returns false. The mutex must be unlocked
@@ -104,13 +113,14 @@
    //! If the mutex supports recursive locking, the mutex must be unlocked the
    //! same number of times it is locked.
    //!Throws: interprocess_exception on error.
- void unlock(void);
+ void unlock();
    /// @cond
    private:
+
    #if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
- interprocess_mutex m_mutex;
- unsigned int m_nLockCount;
- volatile detail::OS_systemwide_thread_id_t m_nOwner;
+ void take_ownership(){ mutex.take_ownership(); }
+ friend class detail::robust_emulation_helpers::mutex_traits<interprocess_recursive_mutex>;
+ detail::emulation_recursive_mutex mutex;
    #else //#if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
    pthread_mutex_t m_mut;
    #endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
@@ -118,17 +128,29 @@
 };
 
 } //namespace interprocess {
-
 } //namespace boost {
 
 #ifdef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
 # undef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
-# include <boost/interprocess/sync/emulation/interprocess_recursive_mutex.hpp>
+
+namespace boost {
+namespace interprocess {
+
+inline interprocess_recursive_mutex::interprocess_recursive_mutex(){}
+inline interprocess_recursive_mutex::~interprocess_recursive_mutex(){}
+inline void interprocess_recursive_mutex::lock(){ mutex.lock(); }
+inline bool interprocess_recursive_mutex::try_lock(){ return mutex.try_lock(); }
+inline bool interprocess_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time){ return mutex.timed_lock(abs_time); }
+inline void interprocess_recursive_mutex::unlock(){ mutex.unlock(); }
+
+} //namespace interprocess {
+} //namespace boost {
+
 #endif
 
 #ifdef BOOST_INTERPROCESS_USE_POSIX
 # undef BOOST_INTERPROCESS_USE_POSIX
-# include <boost/interprocess/sync/posix/interprocess_recursive_mutex.hpp>
+#include <boost/interprocess/sync/posix/interprocess_recursive_mutex.hpp>
 #endif
 
 #include <boost/interprocess/detail/config_end.hpp>

Modified: trunk/boost/interprocess/sync/named_condition.hpp
==============================================================================
--- trunk/boost/interprocess/sync/named_condition.hpp (original)
+++ trunk/boost/interprocess/sync/named_condition.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -27,6 +27,7 @@
 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
 #include <boost/interprocess/sync/emulation/named_creation_functor.hpp>
 #include <boost/interprocess/sync/named_mutex.hpp>
+#include <boost/interprocess/permissions.hpp>
 #if defined BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES
 #include <boost/interprocess/sync/interprocess_mutex.hpp>
 #include <boost/interprocess/sync/scoped_lock.hpp>
@@ -57,7 +58,7 @@
    public:
    //!Creates a global condition with a name.
    //!If the condition can't be created throws interprocess_exception
- named_condition(create_only_t create_only, const char *name);
+ named_condition(create_only_t create_only, const char *name, const permissions &perm = permissions());
 
    //!Opens or creates a global condition with a name.
    //!If the condition is created, this call is equivalent to
@@ -65,7 +66,7 @@
    //!If the condition is already created, this call is equivalent
    //!named_condition(open_only_t, ... )
    //!Does not throw
- named_condition(open_or_create_t open_or_create, const char *name);
+ named_condition(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
 
    //!Opens a global condition with a name if that condition is previously
    //!created. If it is not previously created this function throws
@@ -199,7 +200,7 @@
 inline named_condition::~named_condition()
 {}
 
-inline named_condition::named_condition(create_only_t, const char *name)
+inline named_condition::named_condition(create_only_t, const char *name, const permissions &perm)
    : m_shmem (create_only
                ,name
                ,sizeof(condition_holder) +
@@ -207,10 +208,11 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoCreate))
+ ,construct_func_t(detail::DoCreate)
+ ,perm)
 {}
 
-inline named_condition::named_condition(open_or_create_t, const char *name)
+inline named_condition::named_condition(open_or_create_t, const char *name, const permissions &perm)
    : m_shmem (open_or_create
                ,name
                ,sizeof(condition_holder) +
@@ -218,7 +220,8 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoOpenOrCreate))
+ ,construct_func_t(detail::DoOpenOrCreate)
+ ,perm)
 {}
 
 inline named_condition::named_condition(open_only_t, const char *name)

Modified: trunk/boost/interprocess/sync/named_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/named_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/named_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -21,6 +21,7 @@
 #include <boost/interprocess/exceptions.hpp>
 #include <boost/interprocess/sync/emulation/named_creation_functor.hpp>
 #include <boost/interprocess/detail/interprocess_tester.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 #if defined(BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES)
    #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
@@ -56,7 +57,7 @@
    public:
    //!Creates a global interprocess_mutex with a name.
    //!Throws interprocess_exception on error.
- named_mutex(create_only_t create_only, const char *name);
+ named_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions());
 
    //!Opens or creates a global mutex with a name.
    //!If the mutex is created, this call is equivalent to
@@ -64,7 +65,7 @@
    //!If the mutex is already created, this call is equivalent
    //!named_mutex(open_only_t, ... )
    //!Does not throw
- named_mutex(open_or_create_t open_or_create, const char *name);
+ named_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
 
    //!Opens a global mutex with a name if that mutex is previously
    //!created. If it is not previously created this function throws
@@ -122,16 +123,16 @@
 
 #if defined(BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES)
 
-inline named_mutex::named_mutex(create_only_t, const char *name)
- : m_sem(detail::DoCreate, name, read_write, 1)
+inline named_mutex::named_mutex(create_only_t, const char *name, const permissions &perm)
+ : m_sem(detail::DoCreate, name, read_write, 1, perm)
 {}
 
-inline named_mutex::named_mutex(open_or_create_t, const char *name)
- : m_sem(detail::DoOpenOrCreate, name, read_write, 1)
+inline named_mutex::named_mutex(open_or_create_t, const char *name, const permissions &perm)
+ : m_sem(detail::DoOpenOrCreate, name, read_write, 1, perm)
 {}
 
 inline named_mutex::named_mutex(open_only_t, const char *name)
- : m_sem(detail::DoOpen, name, read_write, 1)
+ : m_sem(detail::DoOpen, name, read_write, 1, permissions())
 {}
 
 inline void named_mutex::dont_close_on_destruction()
@@ -169,7 +170,7 @@
 inline named_mutex::~named_mutex()
 {}
 
-inline named_mutex::named_mutex(create_only_t, const char *name)
+inline named_mutex::named_mutex(create_only_t, const char *name, const permissions &perm)
    : m_shmem (create_only
                ,name
                ,sizeof(interprocess_mutex) +
@@ -177,10 +178,11 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoCreate))
+ ,construct_func_t(detail::DoCreate)
+ ,perm)
 {}
 
-inline named_mutex::named_mutex(open_or_create_t, const char *name)
+inline named_mutex::named_mutex(open_or_create_t, const char *name, const permissions &perm)
    : m_shmem (open_or_create
                ,name
                ,sizeof(interprocess_mutex) +
@@ -188,7 +190,8 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoOpenOrCreate))
+ ,construct_func_t(detail::DoOpenOrCreate)
+ ,perm)
 {}
 
 inline named_mutex::named_mutex(open_only_t, const char *name)

Modified: trunk/boost/interprocess/sync/named_recursive_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/named_recursive_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/named_recursive_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -24,6 +24,7 @@
 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
 #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
 #include <boost/interprocess/sync/emulation/named_creation_functor.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 //!\file
 //!Describes a named named_recursive_mutex class for inter-process synchronization
@@ -50,7 +51,7 @@
 
    //!Creates a global recursive_mutex with a name.
    //!If the recursive_mutex can't be created throws interprocess_exception
- named_recursive_mutex(create_only_t create_only, const char *name);
+ named_recursive_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions());
 
    //!Opens or creates a global recursive_mutex with a name.
    //!If the recursive_mutex is created, this call is equivalent to
@@ -58,7 +59,7 @@
    //!If the recursive_mutex is already created, this call is equivalent
    //!named_recursive_mutex(open_only_t, ... )
    //!Does not throw
- named_recursive_mutex(open_or_create_t open_or_create, const char *name);
+ named_recursive_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
 
    //!Opens a global recursive_mutex with a name if that recursive_mutex is previously
    //!created. If it is not previously created this function throws
@@ -116,7 +117,7 @@
 inline void named_recursive_mutex::dont_close_on_destruction()
 { detail::interprocess_tester::dont_close_on_destruction(m_shmem); }
 
-inline named_recursive_mutex::named_recursive_mutex(create_only_t, const char *name)
+inline named_recursive_mutex::named_recursive_mutex(create_only_t, const char *name, const permissions &perm)
    : m_shmem (create_only
                ,name
                ,sizeof(interprocess_recursive_mutex) +
@@ -124,10 +125,11 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoCreate))
+ ,construct_func_t(detail::DoCreate)
+ ,perm)
 {}
 
-inline named_recursive_mutex::named_recursive_mutex(open_or_create_t, const char *name)
+inline named_recursive_mutex::named_recursive_mutex(open_or_create_t, const char *name, const permissions &perm)
    : m_shmem (open_or_create
                ,name
                ,sizeof(interprocess_recursive_mutex) +
@@ -135,7 +137,8 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoOpenOrCreate))
+ ,construct_func_t(detail::DoOpenOrCreate)
+ ,perm)
 {}
 
 inline named_recursive_mutex::named_recursive_mutex(open_only_t, const char *name)

Modified: trunk/boost/interprocess/sync/named_semaphore.hpp
==============================================================================
--- trunk/boost/interprocess/sync/named_semaphore.hpp (original)
+++ trunk/boost/interprocess/sync/named_semaphore.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -19,6 +19,7 @@
 #include <boost/interprocess/detail/workaround.hpp>
 #include <boost/interprocess/creation_tags.hpp>
 #include <boost/interprocess/exceptions.hpp>
+#include <boost/interprocess/permissions.hpp>
 #include <boost/interprocess/detail/interprocess_tester.hpp>
 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
 
@@ -53,7 +54,7 @@
    public:
    //!Creates a global semaphore with a name, and an initial count.
    //!If the semaphore can't be created throws interprocess_exception
- named_semaphore(create_only_t, const char *name, unsigned int initialCount);
+ named_semaphore(create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
 
    //!Opens or creates a global semaphore with a name, and an initial count.
    //!If the semaphore is created, this call is equivalent to
@@ -61,7 +62,7 @@
    //!If the semaphore is already created, this call is equivalent to
    //!named_semaphore(open_only_t, ... )
    //!and initialCount is ignored.
- named_semaphore(open_or_create_t, const char *name, unsigned int initialCount);
+ named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
 
    //!Opens a global semaphore with a name if that semaphore is previously.
    //!created. If it is not previously created this function throws
@@ -124,18 +125,17 @@
 #if defined(BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES)
 
 inline named_semaphore::named_semaphore
- (create_only_t, const char *name, unsigned int initialCount)
- : m_sem(detail::DoCreate, name, read_write, initialCount)
+ (create_only_t, const char *name, unsigned int initialCount, const permissions &perm)
+ : m_sem(detail::DoCreate, name, read_write, initialCount, perm)
 {}
 
 inline named_semaphore::named_semaphore
- (open_or_create_t, const char *name, unsigned int initialCount)
- : m_sem(detail::DoOpenOrCreate, name, read_write, initialCount)
+ (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm)
+ : m_sem(detail::DoOpenOrCreate, name, read_write, initialCount, perm)
 {}
 
-inline named_semaphore::named_semaphore
- (open_only_t, const char *name)
- : m_sem(detail::DoOpen, name, read_write, 1)
+inline named_semaphore::named_semaphore(open_only_t, const char *name)
+ : m_sem(detail::DoOpen, name, read_write, 1, permissions())
 {}
 
 inline named_semaphore::~named_semaphore()
@@ -174,7 +174,7 @@
 { detail::interprocess_tester::dont_close_on_destruction(m_shmem); }
 
 inline named_semaphore::named_semaphore
- (create_only_t, const char *name, unsigned int initialCount)
+ (create_only_t, const char *name, unsigned int initialCount, const permissions &perm)
    : m_shmem (create_only
                ,name
                ,sizeof(interprocess_semaphore) +
@@ -182,11 +182,12 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoCreate, initialCount))
+ ,construct_func_t(detail::DoCreate, initialCount)
+ ,perm)
 {}
 
 inline named_semaphore::named_semaphore
- (open_or_create_t, const char *name, unsigned int initialCount)
+ (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm)
    : m_shmem (open_or_create
                ,name
                ,sizeof(interprocess_semaphore) +
@@ -194,7 +195,8 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoOpenOrCreate, initialCount))
+ ,construct_func_t(detail::DoOpenOrCreate, initialCount)
+ ,perm)
 {}
 
 inline named_semaphore::named_semaphore

Modified: trunk/boost/interprocess/sync/named_upgradable_mutex.hpp
==============================================================================
--- trunk/boost/interprocess/sync/named_upgradable_mutex.hpp (original)
+++ trunk/boost/interprocess/sync/named_upgradable_mutex.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -24,6 +24,7 @@
 #include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
 #include <boost/interprocess/sync/emulation/named_creation_functor.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 //!\file
 //!Describes a named upgradable mutex class for inter-process synchronization
@@ -53,14 +54,14 @@
 
    //!Creates a global upgradable mutex with a name.
    //!If the upgradable mutex can't be created throws interprocess_exception
- named_upgradable_mutex(create_only_t create_only, const char *name);
+ named_upgradable_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions());
 
    //!Opens or creates a global upgradable mutex with a name, and an initial count.
    //!If the upgradable mutex is created, this call is equivalent to
    //!named_upgradable_mutex(create_only_t, ...)
    //!If the upgradable mutex is already created, this call is equivalent to
    //!named_upgradable_mutex(open_only_t, ... ).
- named_upgradable_mutex(open_or_create_t open_or_create, const char *name);
+ named_upgradable_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
 
    //!Opens a global upgradable mutex with a name if that upgradable mutex
    //!is previously.
@@ -239,7 +240,7 @@
 {}
 
 inline named_upgradable_mutex::named_upgradable_mutex
- (create_only_t, const char *name)
+ (create_only_t, const char *name, const permissions &perm)
    : m_shmem (create_only
                ,name
                ,sizeof(interprocess_upgradable_mutex) +
@@ -247,11 +248,12 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoCreate))
+ ,construct_func_t(detail::DoCreate)
+ ,perm)
 {}
 
 inline named_upgradable_mutex::named_upgradable_mutex
- (open_or_create_t, const char *name)
+ (open_or_create_t, const char *name, const permissions &perm)
    : m_shmem (open_or_create
                ,name
                ,sizeof(interprocess_upgradable_mutex) +
@@ -259,7 +261,8 @@
                      ManagedOpenOrCreateUserOffset
                ,read_write
                ,0
- ,construct_func_t(detail::DoOpenOrCreate))
+ ,construct_func_t(detail::DoOpenOrCreate)
+ ,perm)
 {}
 
 inline named_upgradable_mutex::named_upgradable_mutex

Modified: trunk/boost/interprocess/sync/posix/interprocess_condition.hpp
==============================================================================
--- trunk/boost/interprocess/sync/posix/interprocess_condition.hpp (original)
+++ trunk/boost/interprocess/sync/posix/interprocess_condition.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -21,7 +21,7 @@
    pthread_condattr_t cond_attr;
    res = pthread_condattr_init(&cond_attr);
    if(res != 0){
- throw interprocess_exception();
+ throw interprocess_exception("pthread_condattr_init failed");
    }
    res = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
    if(res != 0){

Modified: trunk/boost/interprocess/sync/posix/pthread_helpers.hpp
==============================================================================
--- trunk/boost/interprocess/sync/posix/pthread_helpers.hpp (original)
+++ trunk/boost/interprocess/sync/posix/pthread_helpers.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -38,7 +38,7 @@
             pthread_mutexattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED)!= 0 ||
              (recursive &&
               pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE)!= 0 ))
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_mutexattr_xxxx failed");
       }
 
       //!Destructor
@@ -58,7 +58,7 @@
       {
          if(pthread_condattr_init(&m_attr)!=0 ||
             pthread_condattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED)!= 0)
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_condattr_xxxx failed");
       }
 
       //!Destructor
@@ -79,7 +79,7 @@
       : mp_mut(&mut)
       {
          if(pthread_mutex_init(mp_mut, &mut_attr) != 0)
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_mutex_init failed");
       }
 
      ~mutex_initializer() { if(mp_mut) pthread_mutex_destroy(mp_mut); }
@@ -98,7 +98,7 @@
       : mp_cond(&cond)
       {
          if(pthread_cond_init(mp_cond, &cond_attr)!= 0)
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_cond_init failed");
       }
 
      ~condition_initializer() { if(mp_cond) pthread_cond_destroy(mp_cond); }
@@ -121,7 +121,7 @@
       {
          if(pthread_barrierattr_init(&m_attr)!=0 ||
             pthread_barrierattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED)!= 0)
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_barrierattr_xxx failed");
       }
 
       //!Destructor
@@ -144,7 +144,7 @@
       : mp_barrier(&mut)
       {
          if(pthread_barrier_init(mp_barrier, &mut_attr, count) != 0)
- throw boost::interprocess::interprocess_exception();
+ throw interprocess_exception("pthread_barrier_init failed");
       }
 
      ~barrier_initializer() { if(mp_barrier) pthread_barrier_destroy(mp_barrier); }

Modified: trunk/boost/interprocess/sync/posix/semaphore_wrapper.hpp
==============================================================================
--- trunk/boost/interprocess/sync/posix/semaphore_wrapper.hpp (original)
+++ trunk/boost/interprocess/sync/posix/semaphore_wrapper.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -16,6 +16,7 @@
 #include <boost/interprocess/creation_tags.hpp>
 #include <boost/interprocess/detail/os_file_functions.hpp>
 #include <boost/interprocess/detail/tmp_dir_helpers.hpp>
+#include <boost/interprocess/permissions.hpp>
 #include <string>
 #include <semaphore.h>
 
@@ -42,13 +43,13 @@
 
 inline bool semaphore_open
    (sem_t *&handle, detail::create_enum_t type, const char *origname, mode_t mode,
- unsigned int count)
+ unsigned int count, const permissions &perm = permissions())
 {
    std::string name;
    #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
    detail::add_leading_slash(origname, name);
    #else
- detail::create_tmp_dir_and_get_filename(origname, name);
+ detail::create_tmp_and_clean_old_and_get_filename(origname, name);
    #endif
 
    //Create new mapping
@@ -83,7 +84,7 @@
 
    //Open file using POSIX API
    if(oflag & O_CREAT)
- handle = sem_open(name.c_str(), oflag, S_IRWXO | S_IRWXG | S_IRWXU, count);
+ handle = sem_open(name.c_str(), oflag, perm.get_permissions(), count);
    else
       handle = sem_open(name.c_str(), oflag);
 
@@ -204,8 +205,8 @@
 
    public:
    named_semaphore_wrapper
- (detail::create_enum_t type, const char *name, mode_t mode, unsigned int count)
- { semaphore_open(mp_sem, type, name, mode, count); }
+ (detail::create_enum_t type, const char *name, mode_t mode, unsigned int count, const permissions &perm = permissions())
+ { semaphore_open(mp_sem, type, name, mode, count, perm); }
 
    ~named_semaphore_wrapper()
    {

Modified: trunk/boost/interprocess/windows_shared_memory.hpp
==============================================================================
--- trunk/boost/interprocess/windows_shared_memory.hpp (original)
+++ trunk/boost/interprocess/windows_shared_memory.hpp 2010-07-25 12:27:15 EDT (Sun, 25 Jul 2010)
@@ -14,6 +14,7 @@
 #include <boost/interprocess/detail/config_begin.hpp>
 #include <boost/interprocess/detail/workaround.hpp>
 #include <boost/detail/workaround.hpp>
+#include <boost/interprocess/permissions.hpp>
 
 #if !defined(BOOST_INTERPROCESS_WINDOWS)
 #error "This header can only be used in Windows operating systems"
@@ -62,19 +63,19 @@
    //!Creates a new native shared memory with name "name" and mode "mode",
    //!with the access mode "mode".
    //!If the file previously exists, throws an error.
- windows_shared_memory(create_only_t, const char *name, mode_t mode, std::size_t size)
- { this->priv_open_or_create(detail::DoCreate, name, mode, size); }
+ windows_shared_memory(create_only_t, const char *name, mode_t mode, std::size_t size, const permissions& perm = permissions())
+ { this->priv_open_or_create(detail::DoCreate, name, mode, size, perm); }
 
    //!Tries to create a shared memory object with name "name" and mode "mode", with the
    //!access mode "mode". If the file previously exists, it tries to open it with mode "mode".
    //!Otherwise throws an error.
- windows_shared_memory(open_or_create_t, const char *name, mode_t mode, std::size_t size)
- { this->priv_open_or_create(detail::DoOpenOrCreate, name, mode, size); }
+ windows_shared_memory(open_or_create_t, const char *name, mode_t mode, std::size_t size, const permissions& perm = permissions())
+ { this->priv_open_or_create(detail::DoOpenOrCreate, name, mode, size, perm); }
 
    //!Tries to open a shared memory object with name "name", with the access mode "mode".
    //!If the file does not previously exist, it throws an error.
    windows_shared_memory(open_only_t, const char *name, mode_t mode)
- { this->priv_open_or_create(detail::DoOpen, name, mode, 0); }
+ { this->priv_open_or_create(detail::DoOpen, name, mode, 0, permissions()); }
 
    //!Moves the ownership of "moved"'s shared memory object to *this.
    //!After the call, "moved" does not represent any shared memory object.
@@ -118,7 +119,7 @@
    void priv_close();
 
    //!Closes a previously opened file mapping. Never throws.
- bool priv_open_or_create(detail::create_enum_t type, const char *filename, mode_t mode, std::size_t size);
+ bool priv_open_or_create(detail::create_enum_t type, const char *filename, mode_t mode, std::size_t size, const permissions& perm = permissions());
 
    void * m_handle;
    mode_t m_mode;
@@ -152,7 +153,7 @@
 { return m_mode; }
 
 inline bool windows_shared_memory::priv_open_or_create
- (detail::create_enum_t type, const char *filename, mode_t mode, std::size_t size)
+ (detail::create_enum_t type, const char *filename, mode_t mode, std::size_t size, const permissions& perm)
 {
    m_name = filename ? filename : "";
 
@@ -192,7 +193,8 @@
          __int64 s = size;
          unsigned long high_size(s >> 32), low_size((boost::uint32_t)s);
          m_handle = winapi::create_file_mapping
- (winapi::invalid_handle_value, file_map_access, high_size, low_size, filename);
+ ( winapi::invalid_handle_value, file_map_access, high_size, low_size, filename
+ , (winapi::interprocess_security_attributes*)perm.get_permissions());
       }
       break;
       default:


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