|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52417 - in branches/release/boost/interprocess: containers/container containers/container/detail detail
From: igaztanaga_at_[hidden]
Date: 2009-04-16 06:01:05
Author: igaztanaga
Date: 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
New Revision: 52417
URL: http://svn.boost.org/trac/boost/changeset/52417
Log:
Fixed C++0x and MacOS X bugs
Text files modified:
branches/release/boost/interprocess/containers/container/detail/tree.hpp | 4 +
branches/release/boost/interprocess/containers/container/list.hpp | 4 +
branches/release/boost/interprocess/containers/container/slist.hpp | 4 +
branches/release/boost/interprocess/containers/container/stable_vector.hpp | 35 ++++------
branches/release/boost/interprocess/detail/os_file_functions.hpp | 57 ++++++++++++++++
branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp | 133 +++++++++++++++++++++------------------
branches/release/boost/interprocess/detail/workaround.hpp | 4
7 files changed, 154 insertions(+), 87 deletions(-)
Modified: branches/release/boost/interprocess/containers/container/detail/tree.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/detail/tree.hpp (original)
+++ branches/release/boost/interprocess/containers/container/detail/tree.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -146,6 +146,10 @@
#else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
+ rbtree_node()
+ : m_data()
+ {}
+
template<class ...Args>
rbtree_node(Args &&...args)
: m_data(boost::interprocess::forward<Args>(args)...)
Modified: branches/release/boost/interprocess/containers/container/list.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/list.hpp (original)
+++ branches/release/boost/interprocess/containers/container/list.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -112,6 +112,10 @@
#else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
+ list_node()
+ : m_data()
+ {}
+
template<class ...Args>
list_node(Args &&...args)
: m_data(boost::interprocess::forward<Args>(args)...)
Modified: branches/release/boost/interprocess/containers/container/slist.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/slist.hpp (original)
+++ branches/release/boost/interprocess/containers/container/slist.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -112,6 +112,10 @@
#else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
+ slist_node()
+ : m_data()
+ {}
+
template<class ...Args>
slist_node(Args &&...args)
: m_data(boost::interprocess::forward<Args>(args)...)
Modified: branches/release/boost/interprocess/containers/container/stable_vector.hpp
==============================================================================
--- branches/release/boost/interprocess/containers/container/stable_vector.hpp (original)
+++ branches/release/boost/interprocess/containers/container/stable_vector.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -227,6 +227,10 @@
#else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
+ node_type()
+ : value()
+ {}
+
template<class ...Args>
node_type(Args &&...args)
: value(boost::interprocess::forward<Args>(args)...)
@@ -677,16 +681,12 @@
}
//Now fill pool if data is not enough
if((n - size) > this->internal_data.pool_size){
- this->add_to_pool((n - size) - this->internal_data.pool_size, alloc_version());
+ this->add_to_pool((n - size) - this->internal_data.pool_size);
}
}
}
- template<class AllocatorVersion>
- void clear_pool(AllocatorVersion,
- typename boost::interprocess_container::containers_detail::enable_if_c
- <boost::interprocess_container::containers_detail::is_same<AllocatorVersion, allocator_v1>
- ::value>::type * = 0)
+ void clear_pool(allocator_v1)
{
if(!impl.empty() && impl.back()){
void_ptr &p1 = *(impl.end()-2);
@@ -703,11 +703,7 @@
}
}
- template<class AllocatorVersion>
- void clear_pool(AllocatorVersion,
- typename boost::interprocess_container::containers_detail::enable_if_c
- <boost::interprocess_container::containers_detail::is_same<AllocatorVersion, allocator_v2>
- ::value>::type * = 0)
+ void clear_pool(allocator_v2)
{
if(!impl.empty() && impl.back()){
@@ -725,11 +721,12 @@
this->clear_pool(alloc_version());
}
- template<class AllocatorVersion>
- void add_to_pool(size_type n, AllocatorVersion,
- typename boost::interprocess_container::containers_detail::enable_if_c
- <boost::interprocess_container::containers_detail::is_same<AllocatorVersion, allocator_v1>
- ::value>::type * = 0)
+ void add_to_pool(size_type n)
+ {
+ this->add_to_pool(n, alloc_version());
+ }
+
+ void add_to_pool(size_type n, allocator_v1)
{
size_type remaining = n;
while(remaining--){
@@ -737,11 +734,7 @@
}
}
- template<class AllocatorVersion>
- void add_to_pool(size_type n, AllocatorVersion,
- typename boost::interprocess_container::containers_detail::enable_if_c
- <boost::interprocess_container::containers_detail::is_same<AllocatorVersion, allocator_v2>
- ::value>::type * = 0)
+ void add_to_pool(size_type n, allocator_v2)
{
void_ptr &p1 = *(impl.end()-2);
void_ptr &p2 = impl.back();
Modified: branches/release/boost/interprocess/detail/os_file_functions.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/os_file_functions.hpp (original)
+++ branches/release/boost/interprocess/detail/os_file_functions.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -24,6 +24,8 @@
# include <sys/types.h>
# include <sys/stat.h>
# include <errno.h>
+# include <cstdio>
+# include <dirent.h>
# else
# error Unknown platform
# endif
@@ -437,11 +439,62 @@
return (acquired = true);
}
-
-
inline bool release_file_lock_sharable(file_handle_t hnd)
{ return release_file_lock(hnd); }
+inline bool delete_subdirectories_recursive
+ (const std::string &refcstrRootDirectory, const char *dont_delete_this)
+{
+ DIR *d = opendir(refcstrRootDirectory.c_str());
+ if(!d) {
+ return false;
+ }
+
+ struct dir_close
+ {
+ DIR *d_;
+ dir_close(DIR *d) : d_(d) {}
+ ~dir_close() { ::closedir(d_); }
+ } dc(d); (void)dc;
+
+ struct ::dirent *de;
+ struct ::stat st;
+ std::string fn;
+
+ while((de=::readdir(d))) {
+ if( de->d_name[0] == '.' && ( de->d_name[1] == '\0'
+ || (de->d_name[1] == '.' && de->d_name[2] == '\0' )) ){
+ continue;
+ }
+ if(dont_delete_this && std::strcmp(dont_delete_this, de->d_name) == 0){
+ continue;
+ }
+ fn = refcstrRootDirectory;
+ fn += '/';
+ fn += de->d_name;
+
+ if(std::remove(fn.c_str())) {
+ if(::stat(fn.c_str(), & st)) {
+ return false;
+ }
+ if(S_ISDIR(st.st_mode)) {
+ if(!delete_subdirectories_recursive(fn, 0) ){
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+ return std::remove(refcstrRootDirectory.c_str()) ? false : true;
+}
+
+//This function erases all the subdirectories of a directory except the one pointed by "dont_delete_this"
+inline bool delete_subdirectories(const std::string &refcstrRootDirectory, const char *dont_delete_this)
+{
+ return delete_subdirectories_recursive(refcstrRootDirectory, dont_delete_this );
+}
+
#endif //#if (defined BOOST_INTERPROCESS_WINDOWS)
} //namespace detail{
Modified: branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp (original)
+++ branches/release/boost/interprocess/detail/tmp_dir_helpers.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -18,15 +18,72 @@
#include <boost/interprocess/exceptions.hpp>
#include <string>
-#if (defined BOOST_INTERPROCESS_WINDOWS)
-# include <boost/interprocess/detail/win32_api.hpp>
+#if defined(BOOST_INTERPROCESS_WINDOWS)
+ #define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME
+ #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
+ #include <boost/interprocess/detail/win32_api.hpp>
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+ #include <sys/sysctl.h>
+ #if defined(CTL_KERN) && defined (KERN_BOOTTIME)
+ #define BOOST_INTERPROCESS_HAS_BSD_KERNEL_BOOTTIME
+ #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
+ #endif
#endif
namespace boost {
namespace interprocess {
namespace detail {
-#if (defined BOOST_INTERPROCESS_WINDOWS)
+#if defined (BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME)
+inline void get_bootstamp(std::string &s, bool add = false)
+{
+ char bootstamp[winapi::BootstampLength*2+1];
+ std::size_t bootstamp_length = winapi::BootstampLength*2;
+ winapi::get_boot_time_str(bootstamp, bootstamp_length);
+ bootstamp[winapi::BootstampLength*2] = 0;
+ if(add){
+ s += bootstamp;
+ }
+ else{
+ s = bootstamp;
+ }
+}
+#elif defined(BOOST_INTERPROCESS_HAS_BSD_KERNEL_BOOTTIME)
+inline void get_bootstamp(std::string &s, bool add = false)
+{
+ // FreeBSD specific: sysctl "kern.boottime"
+ int request[2] = { CTL_KERN, KERN_BOOTTIME };
+ struct ::timeval result;
+ size_t result_len = sizeof result;
+
+ if (::sysctl (request, 2, &result, &result_len, NULL, 0) < 0)
+ return;
+
+ char bootstamp_str[256];
+
+ const char Characters [] =
+ { '0', '1', '2', '3', '4', '5', '6', '7'
+ , '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ std::size_t char_counter = 0;
+ long fields[2] = { result.tv_sec, result.tv_usec };
+ for(std::size_t field = 0; field != 2; ++field){
+ for(std::size_t i = 0; i != sizeof(long); ++i){
+ const char *ptr = (const char *)&fields[field];
+ bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4];
+ bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)];
+ }
+ }
+ bootstamp_str[char_counter] = 0;
+ if(add){
+ s += bootstamp_str;
+ }
+ else{
+ s = bootstamp_str;
+ }
+}
+#endif
+
inline void tmp_filename(const char *filename, std::string &tmp_name)
{
@@ -39,13 +96,10 @@
//Remove final null.
tmp_name += "/boost_interprocess/";
-
- char bootstamp[winapi::BootstampLength*2+1];
- std::size_t bootstamp_length = winapi::BootstampLength*2;
- winapi::get_boot_time_str(bootstamp, bootstamp_length);
- bootstamp[winapi::BootstampLength*2] = 0;
- tmp_name += bootstamp;
+ #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
+ get_bootstamp(tmp_name, true);
tmp_name += '/';
+ #endif
tmp_name += filename;
}
@@ -70,16 +124,14 @@
}
}
- //Obtain bootstamp string
- char bootstamp[winapi::BootstampLength*2+1];
- std::size_t bootstamp_length = winapi::BootstampLength*2;
- winapi::get_boot_time_str(bootstamp, bootstamp_length);
- bootstamp[winapi::BootstampLength*2] = 0;
-
+ #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
//Create a new subdirectory with the bootstamp
std::string root_tmp_name = tmp_name;
tmp_name += '/';
- tmp_name += bootstamp;
+ //Obtain bootstamp string
+ std::string bootstamp;
+ get_bootstamp(bootstamp);
+ tmp_name += bootstamp;
//If fails, check that it's because already exists
if(!create_directory(tmp_name.c_str())){
@@ -88,58 +140,15 @@
throw interprocess_exception(info);
}
}
-
//Now erase all old directories created in the previous boot sessions
- delete_subdirectories(root_tmp_name, bootstamp);
-
- //Add filename
- tmp_name += '/';
- tmp_name += filename;
-}
-
-#else //POSIX SYSTEMS
-
-inline void tmp_filename(const char *filename, std::string &tmp_name)
-{
- const char *tmp_dir = get_temporary_path();
- if(!tmp_dir){
- error_info err = system_error_code();
- throw interprocess_exception(err);
- }
- tmp_name = tmp_dir;
-
- //Remove final null.
- tmp_name += "/boost_interprocess/";
- tmp_name += filename;
-}
-
-inline void create_tmp_dir_and_get_filename(const char *filename, std::string &tmp_name)
-{
- const char *tmp_path = get_temporary_path();
- if(!tmp_path){
- error_info err = system_error_code();
- throw interprocess_exception(err);
- }
-
- tmp_name = tmp_path;
- tmp_name += "/boost_interprocess";
-
- //Create the temporary directory.
- //If fails, check that it's because already exists
- if(!create_directory(tmp_name.c_str())){
- error_info info(system_error_code());
- if(info.get_error_code() != already_exists_error){
- throw interprocess_exception(info);
- }
- }
+ delete_subdirectories(root_tmp_name, bootstamp.c_str());
+ #endif
//Add filename
tmp_name += '/';
tmp_name += filename;
}
-#endif
-
inline void add_leading_slash(const char *name, std::string &new_name)
{
if(name[0] != '/'){
@@ -148,7 +157,7 @@
new_name += name;
}
-} //namespace boost {
+} //namespace boost{
} //namespace interprocess {
} //namespace detail {
Modified: branches/release/boost/interprocess/detail/workaround.hpp
==============================================================================
--- branches/release/boost/interprocess/detail/workaround.hpp (original)
+++ branches/release/boost/interprocess/detail/workaround.hpp 2009-04-16 06:01:02 EDT (Thu, 16 Apr 2009)
@@ -46,8 +46,8 @@
# if defined(__CYGWIN__)
#define BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK
# endif
- #elif defined(__APPLE__)
- # define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
+ //#elif defined(__APPLE__)
+ //# define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
#endif
#if ((defined _V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
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