|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73100 - sandbox/mmap/boost/mmap
From: dsaritz_at_[hidden]
Date: 2011-07-14 09:11:48
Author: psiha
Date: 2011-07-14 09:11:45 EDT (Thu, 14 Jul 2011)
New Revision: 73100
URL: http://svn.boost.org/trac/boost/changeset/73100
Log:
Fixed Clang compiler errors.
Added temporary workarounds for OS X-POSIX specifics.
Minor other changes.
Text files modified:
sandbox/mmap/boost/mmap/memory_mapping.cpp | 37 ++++++----
sandbox/mmap/boost/mmap/memory_mapping.hpp | 139 +++++++++++++++++++++------------------
2 files changed, 98 insertions(+), 78 deletions(-)
Modified: sandbox/mmap/boost/mmap/memory_mapping.cpp
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.cpp (original)
+++ sandbox/mmap/boost/mmap/memory_mapping.cpp 2011-07-14 09:11:45 EDT (Thu, 14 Jul 2011)
@@ -33,6 +33,14 @@
#endif // _WIN32
#include <errno.h>
#include <fcntl.h>
+
+#ifndef _WIN32
+ #ifdef __APPLE__
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) osx
+ #else
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) posix
+ #endif
+#endif
//------------------------------------------------------------------------------
namespace boost
{
@@ -123,6 +131,7 @@
mode_t const current_mask( ::umask( 0 ) );
int const file_handle ( ::open( file_name, flags.oflag, flags.pmode ) );
+ //...zzz...investigate posix_fadvise, posix_madvise, fcntl for the system hints...
BOOST_VERIFY( ::umask( current_mask ) == 0 );
#endif // _WIN32
@@ -131,7 +140,7 @@
}
-bool set_file_size( guard::native_handle_t const file_handle, unsigned int const desired_size )
+bool set_file_size( guard::native_handle_t const file_handle, std::size_t const desired_size )
{
#ifdef _WIN32
// It is 'OK' to send null/invalid handles to Windows functions (they will
@@ -175,11 +184,11 @@
unsigned int const file_flags::share_mode::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_WRITE , 0 );
unsigned int const file_flags::share_mode::remove = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_DELETE, 0 );
-unsigned int const file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_RANDOM_ACCESS , O_RANDOM );
-unsigned int const file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_SEQUENTIAL_SCAN , O_SEQUENTIAL );
-unsigned int const file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, O_DIRECT );
-unsigned int const file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_DELETE_ON_CLOSE , O_TEMPORARY );
-unsigned int const file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_TEMPORARY , O_SHORT_LIVED );
+unsigned int const file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_RANDOM_ACCESS , /*O_RANDOM*/0 );//...zzz...msvc specific flags...fix this...
+unsigned int const file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_SEQUENTIAL_SCAN , /*O_SEQUENTIAL*/0 );
+unsigned int const file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, /*O_DIRECT*/0 );
+unsigned int const file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_DELETE_ON_CLOSE , /*O_TEMPORARY*/0 );
+unsigned int const file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_TEMPORARY , /*O_SHORT_LIVED*/0 );
unsigned int const file_flags::on_construction_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_READONLY, S_IRUSR );
unsigned int const file_flags::on_construction_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IWUSR );
@@ -208,7 +217,7 @@
: on_construction_rights
) // flags_and_attributes
#else // POSIX
- ( ( handle_access_flags == O_RDONLY | O_WRONLY ) ? O_RDWR : handle_access_flags )
+ ( ( handle_access_flags == ( O_RDONLY | O_WRONLY ) ) ? O_RDWR : handle_access_flags )
|
open_flags
|
@@ -244,10 +253,10 @@
unsigned int const mapping_flags::share_mode::hidden = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_COPY, MAP_PRIVATE );
unsigned int const mapping_flags::system_hint::strict_target_address = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_FIXED );
-unsigned int const mapping_flags::system_hint::lock_to_ram = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , MAP_LOCKED );
+unsigned int const mapping_flags::system_hint::lock_to_ram = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_LOCKED, 0 ) );
unsigned int const mapping_flags::system_hint::reserve_page_file_space = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_RESERVE, /*khm#1*/MAP_NORESERVE );
-unsigned int const mapping_flags::system_hint::precommit = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , MAP_POPULATE );
-unsigned int const mapping_flags::system_hint::uninitialized = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_UNINITIALIZED );
+unsigned int const mapping_flags::system_hint::precommit = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_POPULATE, 0 ) );
+unsigned int const mapping_flags::system_hint::uninitialized = BOOST_AUX_IO_WIN32_OR_POSIX( 0, BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_UNINITIALIZED, 0 ) );
mapping_flags mapping_flags::create
@@ -275,7 +284,7 @@
flags.map_view_flags = handle_access_flags;
#else
- flags.protection = handle_access_rights;
+ flags.protection = handle_access_flags;
flags.flags = share_mode | system_hints;
if ( ( system_hints & system_hint::reserve_page_file_space ) ) /*khm#1*/
flags.flags &= ~MAP_NORESERVE;
@@ -332,7 +341,7 @@
#else // POSIX
- iterator_t const view_start( static_cast<iterator_t>( ::mmap( 0, desired_size, flags.protection, flags.flags, file_handle, 0 ) ) );
+ iterator_t const view_start( static_cast<iterator_t>( ::mmap( 0, desired_size, flags.protection, flags.flags, object_handle, 0 ) ) );
return mapped_view<unsigned char>
(
view_start,
@@ -348,9 +357,9 @@
void detail::mapped_view_base<unsigned char const>::unmap( detail::mapped_view_base<unsigned char const> const & mapped_range )
{
#ifdef _WIN32
- BOOST_VERIFY( ::UnmapViewOfFile( mapped_range.begin() ) || mapped_range.empty() );
+ BOOST_VERIFY( ::UnmapViewOfFile( mapped_range.begin() ) || mapped_range.empty() );
#else
- BOOST_VERIFY( ( ::munmap( mapped_range.begin(), mapped_range.size() ) == 0 ) || mapped_range.empty() );
+ BOOST_VERIFY( ( ::munmap ( const_cast<unsigned char *>( mapped_range.begin() ), mapped_range.size() ) == 0 ) || mapped_range.empty() );
#endif // _WIN32
}
Modified: sandbox/mmap/boost/mmap/memory_mapping.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.hpp (original)
+++ sandbox/mmap/boost/mmap/memory_mapping.hpp 2011-07-14 09:11:45 EDT (Thu, 14 Jul 2011)
@@ -187,12 +187,18 @@
};
#endif // _WIN32
-class posix_handle : noncopyable
+class posix_handle
+#ifdef BOOST_MSVC
+ : noncopyable
+#endif // BOOST_MSVC
{
public:
typedef int handle_t;
explicit posix_handle( handle_t );
+ #ifndef BOOST_MSVC
+ posix_handle( posix_handle const & );
+ #endif // BOOST_MSVC
#ifdef _WIN32
explicit posix_handle( windows_handle::handle_t );
@@ -258,11 +264,11 @@
#ifdef BOOST_MSVC
const &
#endif
- make_typed_range( mapped_view_base<unsigned char const> const & );
+ make_typed_range( mapped_view_base<unsigned char> const & );
private: // Hide mutable members
- iterator_range & advance_begin( difference_type );
- iterator_range & advance_end ( difference_type );
+ void advance_begin();
+ void advance_end ();
void pop_front();
void pop_back ();
@@ -277,48 +283,6 @@
template <>
void mapped_view_base<unsigned char const>::unmap( mapped_view_base<unsigned char const> const & );
-
- template <typename Element>
- mapped_view<unsigned char const>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapped_view_base<Element>::make_basic_view( mapped_view_base<Element> const & range )
- {
- return
- #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view<unsigned char const> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view<unsigned char const>
- (
- static_cast<unsigned char const *>( static_cast<void const *>( range.begin() ) ),
- static_cast<unsigned char const *>( static_cast<void const *>( range.end () ) )
- );
- #endif // compiler
- }
-
-
- template <typename Element>
- mapped_view<Element>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapped_view_base<Element>::make_typed_range( mapped_view_base<unsigned char const> const & range )
- {
- BOOST_ASSERT( range.begin() % sizeof( Element ) == 0 );
- BOOST_ASSERT( range.end () % sizeof( Element ) == 0 );
- BOOST_ASSERT( range.size () % sizeof( Element ) == 0 );
- return
- #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view<Element> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view<unsigned char const>
- (
- static_cast<Element *>( static_cast<void *>( range.begin() ) ),
- static_cast<Element *>( static_cast<void *>( range.end () ) )
- );
- #endif // compiler
- }
} // namespace detail
template <typename Element>
@@ -329,8 +293,8 @@
{
return basic_memory_range_t
(
- static_cast<unsigned char *>( static_cast<void *>( begin() ) ),
- static_cast<unsigned char *>( static_cast<void *>( end () ) )
+ static_cast<unsigned char *>( static_cast<void *>( this->begin() ) ),
+ static_cast<unsigned char *>( static_cast<void *>( this->end () ) )
);
}
@@ -344,8 +308,10 @@
);
private:
- mapped_view( iterator_range<Element *> const & mapped_range ) : mapped_view_base( mapped_range ) {}
- mapped_view( Element * const p_begin, Element * const p_end ) : mapped_view_base( p_begin, p_end ) {}
+ template <typename Element> friend class detail::mapped_view_base;
+
+ mapped_view( iterator_range<Element *> const & mapped_range ) : detail::mapped_view_base<Element>( mapped_range ) {}
+ mapped_view( Element * const p_begin, Element * const p_end ) : detail::mapped_view_base<Element>( p_begin, p_end ) {}
};
template <typename Element>
@@ -356,8 +322,8 @@
{
return basic_memory_range_t
(
- static_cast<unsigned char const *>( static_cast<void const *>( begin() ) ),
- static_cast<unsigned char const *>( static_cast<void const *>( end () ) )
+ static_cast<unsigned char const *>( static_cast<void const *>( this->begin() ) ),
+ static_cast<unsigned char const *>( static_cast<void const *>( this->end () ) )
);
}
@@ -371,10 +337,65 @@
);
private:
- mapped_view( iterator_range<Element const *> const & mapped_range ) : mapped_view_base( mapped_range ) {}
- mapped_view( Element const * const p_begin, Element const * const p_end ) : mapped_view_base( p_begin, p_end ) {}
+ template <typename Element> friend class detail::mapped_view_base;
+
+ mapped_view( iterator_range<Element const *> const & mapped_range ) : detail::mapped_view_base<Element const>( mapped_range ) {}
+ mapped_view( Element const * const p_begin, Element const * const p_end ) : detail::mapped_view_base<Element const>( p_begin, p_end ) {}
+ mapped_view( mapped_view<Element> const & mutable_view ) : detail::mapped_view_base<Element const>( mutable_view ) {}
};
+
+namespace detail
+{
+ // Implementation note:
+ // These have to be defined after mapped_view for eager compilers (e.g.
+ // GCC and Clang).
+ // (14.07.2011.) (Domagoj Saric)
+
+ template <typename Element>
+ mapped_view<unsigned char const>
+ #ifdef BOOST_MSVC
+ const &
+ #endif
+ mapped_view_base<Element>::make_basic_view( mapped_view_base<Element> const & range )
+ {
+ return
+ #ifdef BOOST_MSVC
+ reinterpret_cast<mapped_view<unsigned char const> const &>( range );
+ #else // compiler might care about strict aliasing rules
+ mapped_view<unsigned char const>
+ (
+ static_cast<unsigned char const *>( static_cast<void const *>( range.begin() ) ),
+ static_cast<unsigned char const *>( static_cast<void const *>( range.end () ) )
+ );
+ #endif // compiler
+ }
+
+
+ template <typename Element>
+ mapped_view<Element>
+ #ifdef BOOST_MSVC
+ const &
+ #endif
+ mapped_view_base<Element>::make_typed_range( mapped_view_base<unsigned char> const & range )
+ {
+ BOOST_ASSERT( reinterpret_cast<std::size_t>( range.begin() ) % sizeof( Element ) == 0 );
+ BOOST_ASSERT( reinterpret_cast<std::size_t>( range.end () ) % sizeof( Element ) == 0 );
+ BOOST_ASSERT( range.size () % sizeof( Element ) == 0 );
+ return
+ #ifdef BOOST_MSVC
+ reinterpret_cast<mapped_view<Element> const &>( range );
+ #else // compiler might care about strict aliasing rules
+ mapped_view<unsigned char const>
+ (
+ static_cast<Element *>( static_cast<void *>( range.begin() ) ),
+ static_cast<Element *>( static_cast<void *>( range.end () ) )
+ );
+ #endif // compiler
+ }
+} // namespace detail
+
+
template <typename Handle>
struct is_mappable : mpl::false_ {};
@@ -389,16 +410,6 @@
#endif // _WIN32
-template <typename Element>
-mapped_view<Element> mapped_view<Element>::map
-(
- guard::native_handle_t,
- mapping_flags const &,
- std::size_t desired_size,
- std::size_t offset
-);
-
-
template <>
mapped_view<unsigned char> mapped_view<unsigned char>::map
(
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