|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52415 - in trunk/boost/interprocess: containers/container containers/container/detail detail
From: igaztanaga_at_[hidden]
Date: 2009-04-16 03:01:53
Author: igaztanaga
Date: 2009-04-16 03:01:51 EDT (Thu, 16 Apr 2009)
New Revision: 52415
URL: http://svn.boost.org/trac/boost/changeset/52415
Log:
Fixed C++0x and MacOS X bugs
Text files modified:
trunk/boost/interprocess/containers/container/detail/tree.hpp | 4 +
trunk/boost/interprocess/containers/container/list.hpp | 4 +
trunk/boost/interprocess/containers/container/slist.hpp | 4 +
trunk/boost/interprocess/containers/container/stable_vector.hpp | 4 +
trunk/boost/interprocess/detail/os_file_functions.hpp | 57 ++++++++++++++++
trunk/boost/interprocess/detail/tmp_dir_helpers.hpp | 133 +++++++++++++++++++++------------------
6 files changed, 142 insertions(+), 64 deletions(-)
Modified: trunk/boost/interprocess/containers/container/detail/tree.hpp
==============================================================================
--- trunk/boost/interprocess/containers/container/detail/tree.hpp (original)
+++ trunk/boost/interprocess/containers/container/detail/tree.hpp 2009-04-16 03:01:51 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: trunk/boost/interprocess/containers/container/list.hpp
==============================================================================
--- trunk/boost/interprocess/containers/container/list.hpp (original)
+++ trunk/boost/interprocess/containers/container/list.hpp 2009-04-16 03:01:51 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: trunk/boost/interprocess/containers/container/slist.hpp
==============================================================================
--- trunk/boost/interprocess/containers/container/slist.hpp (original)
+++ trunk/boost/interprocess/containers/container/slist.hpp 2009-04-16 03:01:51 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: trunk/boost/interprocess/containers/container/stable_vector.hpp
==============================================================================
--- trunk/boost/interprocess/containers/container/stable_vector.hpp (original)
+++ trunk/boost/interprocess/containers/container/stable_vector.hpp 2009-04-16 03:01:51 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)...)
Modified: trunk/boost/interprocess/detail/os_file_functions.hpp
==============================================================================
--- trunk/boost/interprocess/detail/os_file_functions.hpp (original)
+++ trunk/boost/interprocess/detail/os_file_functions.hpp 2009-04-16 03:01:51 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: trunk/boost/interprocess/detail/tmp_dir_helpers.hpp
==============================================================================
--- trunk/boost/interprocess/detail/tmp_dir_helpers.hpp (original)
+++ trunk/boost/interprocess/detail/tmp_dir_helpers.hpp 2009-04-16 03:01:51 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 {
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