From b82a563d5aeb65e3734539315bc3ce34a95c5503 Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Fri, 6 Jan 2017 23:17:41 -0800 Subject: [PATCH] Fixed Issue #322 (Memory spike at opening service) * Shared memory mapped files now opened in "shared_mem" folder adjacent PSMoveService.exe * This fixes occasional weird issues with trying to open temp folders in c:\ProgramData\boost_interprocess --- src/psmoveprotocol/SharedTrackerState.h | 4 ++++ src/psmoveservice/Server/PSMoveService.cpp | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/psmoveprotocol/SharedTrackerState.h b/src/psmoveprotocol/SharedTrackerState.h index 4d2a7dc3..4303a5ef 100644 --- a/src/psmoveprotocol/SharedTrackerState.h +++ b/src/psmoveprotocol/SharedTrackerState.h @@ -1,6 +1,10 @@ #ifndef SHARED_TRACKER_STATE_H #define SHARED_TRACKER_STATE_H +#ifdef WIN32 +#define BOOST_INTERPROCESS_SHARED_DIR_PATH "shared_mem" +#endif // WIN32 + #include class SharedVideoFrameHeader diff --git a/src/psmoveservice/Server/PSMoveService.cpp b/src/psmoveservice/Server/PSMoveService.cpp index d24cf57c..cc38906b 100644 --- a/src/psmoveservice/Server/PSMoveService.cpp +++ b/src/psmoveservice/Server/PSMoveService.cpp @@ -5,7 +5,9 @@ #include "ServerNetworkManager.h" #include "ServerRequestHandler.h" #include "DeviceManager.h" +#include "ProtocolVersion.h" #include "ServerLog.h" +#include "SharedTrackerState.h" #include "TrackerManager.h" #include @@ -137,6 +139,20 @@ class PSMoveServiceImpl bool startup() { bool success= true; + + /** Make sure the shared memory directory exists (if non-default path is defined) */ + #if defined(BOOST_INTERPROCESS_SHARED_DIR_PATH) + boost::filesystem::path shared_mem_dir(BOOST_INTERPROCESS_SHARED_DIR_PATH); + boost::system::error_code ec; + if (!boost::filesystem::create_directory(shared_mem_dir, ec)) + { + if(ec.value() != boost::interprocess::already_exists_error && ec.value() != boost::interprocess::no_error) + { + SERVER_LOG_FATAL("PSMoveService") << "Failed to create the shared memory directory: " << ec.message(); + success= false; + } + } + #endif // BOOST_INTERPROCESS_SHARED_DIR_PATH /** Start listening for client connections */ if (success) @@ -503,7 +519,7 @@ int PSMoveService::exec(int argc, char *argv[]) log_init(this->getProgramSettings()->log_level, "PSMoveService.log"); // Start the service app - SERVER_LOG_INFO("main") << "Starting PSMoveService"; + SERVER_LOG_INFO("main") << "Starting PSMoveService v" << PSM_DETAILED_VERSION_STRING; try { PSMoveServiceImpl app;