diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index 8362132d..d4072d3b 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -6626,7 +6626,7 @@ want [*Boost.Interprocess] to initialize the COM library with another model, def [section:notes_windows_shm_folder Shared memory emulation folder] -Shared memory (`shared_memory_object`) is implemented in windows using memory mapped files, placed in a +Shared memory (`shared_memory_object`) is implemented in Windows using memory mapped files, placed in a shared directory in the shared documents folder (`SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common AppData`). This directory name is the last bootup time obtained via COM calls (if `BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME`) defined or searching the system log for a startup event (the default implementation), so that each bootup shared memory is created in a new @@ -6643,8 +6643,19 @@ If using the default implementation, (`BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTU found, this might be due to some buggy software that floods or erases the event log. In any error case (shared documents folder is not defined or bootup time could not be obtained, the library throws an error. You still -can use [*Boost.Interprocess] definining your own directory as the shared directory. Just define `BOOST_INTERPROCESS_SHARED_DIR_PATH` -when using the library and that path will be used to place shared memory files. +can use [*Boost.Interprocess] definining your own directory as the shared directory. When your shared directory is a compile-time constant, +define `BOOST_INTERPROCESS_SHARED_DIR_PATH` when using the library and that path will be used to place shared memory files. When you have +to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the function + +[c++] + + namespace boost { + namespace interprocess { + namespace ipcdetail { + void get_shared_dir(std::string &shared_dir); + } + } + } [endsect] @@ -6662,11 +6673,22 @@ those heavy headers. [section:notes_linux_shm_folder Shared memory emulation folder] -On systems without POSIX shared memory support shared memory objects are implemented as memory mapped files, using a directory -placed in "/tmp" that can include (if `BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME` is defined) the last bootup time (if the Os supports it). -As in Windows, in any error case obtaining this directory the library throws an error . You still can use -[*Boost.Interprocess] definining your own directory as the shared directory. Just define `BOOST_INTERPROCESS_SHARED_DIR_PATH` -when using the library and that path will be used to place shared memory files. +On systems without POSIX shared memory support, shared memory objects are implemented as memory mapped files, using a directory +placed in "/tmp" that can include (if `BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME` is defined) the last bootup time (if the OS supports it). +As in Windows, in any error case obtaining this directory the library throws an error . When your shared directory is a compile-time constant, +define `BOOST_INTERPROCESS_SHARED_DIR_PATH` when using the library and that path will be used to place shared memory files. When you have +to determine the shared directory at runtime, define `BOOST_INTERPROCESS_SHARED_DIR_FUNC` and implement the function + +[c++] + + namespace boost { + namespace interprocess { + namespace ipcdetail { + void get_shared_dir(std::string &shared_dir); + } + } + } + [endsect] diff --git a/include/boost/interprocess/detail/shared_dir_helpers.hpp b/include/boost/interprocess/detail/shared_dir_helpers.hpp old mode 100644 new mode 100755 index a0ac766f..bfce9fe0 --- a/include/boost/interprocess/detail/shared_dir_helpers.hpp +++ b/include/boost/interprocess/detail/shared_dir_helpers.hpp @@ -106,9 +106,10 @@ inline void get_shared_dir_root(std::string &dir_path) { #if defined (BOOST_INTERPROCESS_WINDOWS) winapi::get_shared_documents_folder(dir_path); - #else + #else dir_path = "/tmp"; #endif + //We always need this path, so throw on error if(dir_path.empty()){ error_info err = system_error_code(); @@ -118,11 +119,22 @@ inline void get_shared_dir_root(std::string &dir_path) dir_path += "/boost_interprocess"; } +#ifdef BOOST_INTERPROCESS_SHARED_DIR_FUNC +namespace boost { + namespace interprocess { + namespace ipcdetail { + // When BOOST_INTERPROCESS_SHARED_DIR_FUNC is defined, users have to implement + // get_shared_dir + void get_shared_dir(std::string &shared_dir); + } + } +} +#else inline void get_shared_dir(std::string &shared_dir) { #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; - #else + #else get_shared_dir_root(shared_dir); #if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) shared_dir += "/"; @@ -130,6 +142,7 @@ inline void get_shared_dir(std::string &shared_dir) #endif #endif } +#endif inline void shared_filepath(const char *filename, std::string &filepath) { @@ -140,8 +153,8 @@ inline void shared_filepath(const char *filename, std::string &filepath) inline void create_shared_dir_and_clean_old(std::string &shared_dir) { - #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) - shared_dir = BOOST_INTERPROCESS_SHARED_DIR_PATH; + #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) || defined(BOOST_INTERPROCESS_SHARED_DIR_FUNC) + get_shared_dir(shared_dir); #else //First get the temp directory std::string root_shared_dir;