Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79964 - trunk/boost/interprocess
From: igaztanaga_at_[hidden]
Date: 2012-08-11 08:44:33


Author: igaztanaga
Date: 2012-08-11 08:44:32 EDT (Sat, 11 Aug 2012)
New Revision: 79964
URL: http://svn.boost.org/trac/boost/changeset/79964

Log:
- Ticket #7218
- Remove MADV_DONTNEED from most systems as it has destructive semantics non-compatible with POSIX_MADV_DONTNEED

Text files modified:
   trunk/boost/interprocess/mapped_region.hpp | 27 +++++++++++++++++++++++++--
   1 files changed, 25 insertions(+), 2 deletions(-)

Modified: trunk/boost/interprocess/mapped_region.hpp
==============================================================================
--- trunk/boost/interprocess/mapped_region.hpp (original)
+++ trunk/boost/interprocess/mapped_region.hpp 2012-08-11 08:44:32 EDT (Sat, 11 Aug 2012)
@@ -21,6 +21,18 @@
 #include <boost/interprocess/detail/os_file_functions.hpp>
 #include <string>
 #include <boost/cstdint.hpp>
+//Some Unixes use caddr_t instead of void * in madvise
+// SunOS Tru64 HP-UX AIX
+#if defined(sun) || defined(__sun) || defined(__osf__) || defined(__osf) || defined(_hpux) || defined(hpux) || defined(_AIX)
+#define BOOST_INTERPROCESS_MADVISE_USES_CADDR_T
+#include <sys/types.h>
+#endif
+
+//A lot of UNIXes have destructive semantics for MADV_DONTNEED, so
+//we need to be careful to allow it.
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#define BOOST_INTERPROCESS_MADV_DONTNEED_HAS_NONDESTRUCTIVE_SEMANTICS
+#endif
 
 #if defined (BOOST_INTERPROCESS_WINDOWS)
 # include <boost/interprocess/detail/win32_api.hpp>
@@ -49,6 +61,13 @@
 namespace interprocess {
 
 /// @cond
+
+//Solaris declares madvise only in some configurations but defines MADV_XXX, a bit confusing.
+//Predeclare it here to avoid any compilation error
+#if (defined(sun) || defined(__sun)) && defined(MADV_NORMAL)
+extern "C" int madvise(caddr_t, size_t, int);
+#endif
+
 namespace ipcdetail{ class interprocess_tester; }
 namespace ipcdetail{ class raw_mapped_region_creator; }
 
@@ -744,7 +763,7 @@
          #if defined(POSIX_MADV_DONTNEED)
          unix_advice = POSIX_MADV_DONTNEED;
          mode = mode_padv;
- #elif defined(MADV_DONTNEED)
+ #elif defined(MADV_DONTNEED) && defined(BOOST_INTERPROCESS_MADV_DONTNEED_HAS_NONDESTRUCTIVE_SEMANTICS)
          unix_advice = MADV_DONTNEED;
          mode = mode_madv;
          #endif
@@ -759,7 +778,11 @@
       #endif
       #if defined(MADV_NORMAL)
          case mode_madv:
- return 0 == madvise(this->priv_map_address(), this->priv_map_size(), unix_advice);
+ return 0 == madvise(
+ #if defined(BOOST_INTERPROCESS_MADVISE_USES_CADDR_T)
+ (caddr_t)
+ #endif
+ this->priv_map_address(), this->priv_map_size(), unix_advice);
       #endif
       default:
       return false;


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