diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index 2ed5b3ee..eb6bed44 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -249,6 +249,7 @@ if(BUILD_FAIRMQ) TransportFactory.cxx plugins/config/Config.cxx plugins/control/Control.cxx + shmem/Common.cxx shmem/Manager.cxx shmem/Monitor.cxx ) @@ -385,7 +386,7 @@ if(BUILD_FAIRMQ) fairmq_target_tidy(TARGET fairmq-splitter) endif() - add_executable(fairmq-shmmonitor shmem/Monitor.cxx shmem/Monitor.h shmem/runMonitor.cxx) + add_executable(fairmq-shmmonitor shmem/Common.cxx shmem/Monitor.cxx shmem/Monitor.h shmem/runMonitor.cxx) target_compile_features(fairmq-shmmonitor PUBLIC cxx_std_17) target_compile_definitions(fairmq-shmmonitor PUBLIC BOOST_ERROR_CODE_HEADER_ONLY) if(FAIRMQ_DEBUG_MODE) diff --git a/fairmq/shmem/Common.cxx b/fairmq/shmem/Common.cxx new file mode 100644 index 00000000..78fec8f7 --- /dev/null +++ b/fairmq/shmem/Common.cxx @@ -0,0 +1,48 @@ +/******************************************************************************** + * Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include "Common.h" + +#include + +#include + +#include +#include + +namespace fair::mq::shmem +{ + +std::string makeShmIdStr(const std::string& sessionId, const std::string& userId) +{ + std::string seed(userId + sessionId); + // generate a 8-digit hex value out of sha256 hash + std::vector hash(4); + picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end()); + + return picosha2::bytes_to_hex_string(hash.begin(), hash.end()); +} + +std::string makeShmIdStr(const std::string& sessionId) +{ + return makeShmIdStr(sessionId, std::to_string(geteuid())); +} + +uint64_t makeShmIdUint64(const std::string& sessionId) +{ + std::string shmId = makeShmIdStr(sessionId); + uint64_t id = 0; + std::stringstream ss; + ss << std::hex << shmId; + ss >> id; + + return id; +} + + +} // namespace fair::mq::shmem diff --git a/fairmq/shmem/Common.h b/fairmq/shmem/Common.h index b90a93e2..63f1ae52 100644 --- a/fairmq/shmem/Common.h +++ b/fairmq/shmem/Common.h @@ -8,10 +8,7 @@ #ifndef FAIR_MQ_SHMEM_COMMON_H_ #define FAIR_MQ_SHMEM_COMMON_H_ -#include - #include -#include #include #include // std::equal_to @@ -26,7 +23,6 @@ #include #include -#include #include namespace fair::mq::shmem @@ -212,31 +208,9 @@ struct RegionBlock // find id for unique shmem name: // a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)). -inline std::string makeShmIdStr(const std::string& sessionId, const std::string& userId) -{ - std::string seed(userId + sessionId); - // generate a 8-digit hex value out of sha256 hash - std::vector hash(4); - picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end()); - - return picosha2::bytes_to_hex_string(hash.begin(), hash.end()); -} - -inline std::string makeShmIdStr(const std::string& sessionId) -{ - return makeShmIdStr(sessionId, std::to_string(geteuid())); -} - -inline uint64_t makeShmIdUint64(const std::string& sessionId) -{ - std::string shmId = makeShmIdStr(sessionId); - uint64_t id = 0; - std::stringstream ss; - ss << std::hex << shmId; - ss >> id; - - return id; -} +std::string makeShmIdStr(const std::string& sessionId, const std::string& userId); +std::string makeShmIdStr(const std::string& sessionId); +uint64_t makeShmIdUint64(const std::string& sessionId); struct SegmentSize : public boost::static_visitor {