Files
spark/src/lib/md/ShmSegmentName.cpp
T
John Colvin 103725887f build: Resolve app data dir and shared mem prefix at runtime
We really can't define them at compile time anymore as we build multiple
exes that depend on libspark in the same dir (e.g., spark api server,
pubsub, ds-publisher, webapp, etc.). That means one libspark.so (or dll)
must serve all exes. We should compile a consistent libspark to mitigate
the risk of running an exe with the wrong version (of libspark). For
example, running pubsub with a libspark configured for spark api server,
leftover from an earlier build.
2024-09-18 14:02:38 +00:00

30 lines
994 B
C++

#include "ShmSegmentName.h"
#include "lib/utils/bts_assert.h"
#include "lib/os/os.h"
namespace bts::md {
bool ShmSegmentName::prefix_initialized_ = false;
std::string ShmSegmentName::prefix_ = {};
std::mutex ShmSegmentName::prefix_mx_ = {};
std::string ShmSegmentName::prefix() {
// Optimistically check if prefix has been initialized without using a lock
if (!prefix_initialized_) {
// It hasn't been initialized. Use a lock to initialize it
std::lock_guard<std::mutex> lock{prefix_mx_};
// Verify it hasn't been initialized again (since the initial check was done without a lock).
if (!prefix_initialized_) {
if (!os::try_expand_env(SHARED_MEMORY_PREFIX, prefix_)) {
prefix_ = os::process_path().filename().string();
}
}
bts_assert(!prefix_.empty());
prefix_initialized_ = true;
}
return prefix_ + "_" +
config::get<md::PublisherNamespace>().shared_memory_namespace();
}
} // namespace bts::md