* If BOOST_USE_WINDOWS_H is defined, <windows.h> and other windows SDK files are included,

otherwise the library declares needed functions and structures to reduce the impact of including
those heavy headers.

*  Added `get_size` to windows_shared_memory.
This commit is contained in:
Ion Gaztañaga
2014-05-28 15:30:04 +02:00
parent 02a7e7ecf2
commit de405e89a3
8 changed files with 1203 additions and 849 deletions

View File

@@ -6650,6 +6650,12 @@ when using the library and that path will be used to place shared memory files.
[endsect]
[section:boost:use_windows_h BOOST_USE_WINDOWS_H support]
If `BOOST_USE_WINDOWS_H` is defined, <windows.h> and other windows SDK files are included,
otherwise the library declares needed functions and structures to reduce the impact of including
those heavy headers.
[endsect]
[section:notes_linux Notes for Linux users]
@@ -6745,6 +6751,7 @@ thank them:
* [@https://svn.boost.org/trac/boost/ticket/9835 Trac #9835 (['"Boost Interprocess fails to compile with Android NDK GCC 4.8, -Werror=unused-variable"])].
* [@https://svn.boost.org/trac/boost/ticket/9911 Trac #9911 (['"get_tmp_base_dir(...) failure"])].
* [@https://svn.boost.org/trac/boost/ticket/9946 Trac #9946 (['"ret_ptr uninitialized in init_atomic_func, fini_atomic_func"])].
* [@https://svn.boost.org/trac/boost/ticket/10021 Trac #10021 (['"Interprocess and BOOST_USE_WINDOWS_H"])].
* [@https://github.com/boostorg/interprocess/pull/2 GitHub #2] (['"Provide support for the Cray C++ compiler. The Cray compiler defines __GNUC__"]]).
* [@https://github.com/boostorg/interprocess/pull/3 GitHub #3] (['"Fix/mingw interprocess_exception throw in file_wrapper::priv_open_or_create"]]).
@@ -6761,6 +6768,12 @@ thank them:
* Added `BOOST_INTERPROCESS_SHARED_DIR_PATH` option to define the shared directory used to place shared memory objects
when implemented as memory mapped files.
* Added support for `BOOST_USE_WINDOWS_H`. When this macro is defined Interprocess does not declare
used Windows API function and types, includes all needed windows SDK headers and uses types and
functions declared by the Windows SDK.
* Added `get_size` to [classref ::boost:interprocess:windows_shared_memory].
[endsect]
[section:release_notes_boost_1_55_00 Boost 1.55 Release]

View File

@@ -270,7 +270,7 @@ inline bool delete_subdirectories_recursive
void * hFile; // Handle to directory
std::string strFilePath; // Filepath
std::string strPattern; // Pattern
winapi::win32_find_data_t FileInformation; // File information
winapi::win32_find_data FileInformation; // File information
//Find all files and directories
strPattern = refcstrRootDirectory + "\\*.*";
@@ -338,7 +338,7 @@ template<class Function>
inline bool for_each_file_in_dir(const char *dir, Function f)
{
void * hFile; // Handle to directory
winapi::win32_find_data_t FileInformation; // File information
winapi::win32_find_data FileInformation; // File information
//Get base directory
std::string str(dir);

File diff suppressed because it is too large Load Diff

View File

@@ -60,13 +60,13 @@ class windows_shared_memory
//!Represents an empty windows_shared_memory.
windows_shared_memory();
//!Creates a new native shared memory with name "name" and mode "mode",
//!Creates a new native shared memory with name "name" and at least size "size",
//!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, const permissions& perm = permissions())
{ this->priv_open_or_create(ipcdetail::DoCreate, name, mode, size, perm); }
//!Tries to create a shared memory object with name "name" and mode "mode", with the
//!Tries to create a shared memory object with name "name" and at least size "size", 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, const permissions& perm = permissions())
@@ -112,6 +112,10 @@ class windows_shared_memory
//!Returns the mapping handle. Never throws
mapping_handle_t get_mapping_handle() const;
//!Returns the size of the windows shared memory. It will be a 4K rounded
//!size of the "size" passed in the constructor.
offset_t get_size() const;
/// @cond
private:
@@ -152,6 +156,12 @@ inline mapping_handle_t windows_shared_memory::get_mapping_handle() const
inline mode_t windows_shared_memory::get_mode() const
{ return m_mode; }
inline offset_t windows_shared_memory::get_size() const
{
offset_t size; //This shall never fail
return (m_handle && winapi::get_file_mapping_size(m_handle, size)) ? size : 0;
}
inline bool windows_shared_memory::priv_open_or_create
(ipcdetail::create_enum_t type, const char *filename, mode_t mode, std::size_t size, const permissions& perm)
{

View File

@@ -479,6 +479,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "named_condition_any_test",
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "boost_use_windows_h", "boost_use_windows_h.vcproj", "{518CE8C3-6512-FA75-46EF-B917A3A116D1}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@@ -967,6 +971,10 @@ Global
{58CC2563-6092-48FE-FAF7-BA046A792658}.Debug.Build.0 = Debug|Win32
{58CC2563-6092-48FE-FAF7-BA046A792658}.Release.ActiveCfg = Release|Win32
{58CC2563-6092-48FE-FAF7-BA046A792658}.Release.Build.0 = Release|Win32
{518CE8C3-6512-FA75-46EF-B917A3A116D1}.Debug.ActiveCfg = Debug|Win32
{518CE8C3-6512-FA75-46EF-B917A3A116D1}.Debug.Build.0 = Debug|Win32
{518CE8C3-6512-FA75-46EF-B917A3A116D1}.Release.ActiveCfg = Release|Win32
{518CE8C3-6512-FA75-46EF-B917A3A116D1}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View File

@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="boost_use_windows_h"
ProjectGUID="{518CE8C3-6512-FA75-46EF-B917A3A116D1}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../Bin/Win32/Debug"
IntermediateDirectory="Debug/boost_use_windows_h"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB;"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/boost_use_windows_h.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/boost_use_windows_h.pdb"
SubSystem="1"
TargetMachine="1"
FixedBaseAddress="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../Bin/Win32/Release"
IntermediateDirectory="Release/boost_use_windows_h"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="3"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB;"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/boost_use_windows_h.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4F8F372-C425-7A56-652E-A6A023A237EF}">
<File
RelativePath="..\..\test\boost_use_windows_h.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{5C3EBE53-7D9B-C441-258B-62B5F182FBE5}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,38 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014. 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.
//
//////////////////////////////////////////////////////////////////////////////
#define _WIN32_WINNT 0x0501
#define BOOST_USE_WINDOWS_H
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#ifdef BOOST_INTERPROCESS_WINDOWS
#include <boost/interprocess/windows_shared_memory.hpp>
using namespace boost::interprocess;
int main ()
{
windows_shared_memory dummy;
static_cast<void>(dummy);
return 0;
}
#else
int main()
{
return 0;
}
#endif
#include <boost/interprocess/detail/config_end.hpp>

View File

@@ -32,7 +32,8 @@ int main ()
//Create a file mapping
windows_shared_memory mapping
(create_only, names[i_name], read_write, FileSize);
if(mapping.get_size() < FileSize)
return 1;
{
//Create two mapped regions, one half of the file each