31#include <flow/log/simple_ostream_logger.hpp>
32#include <boost/interprocess/permissions.hpp>
33#include <boost/interprocess/shared_memory_object.hpp>
34#include <boost/interprocess/mapped_region.hpp>
35#include <boost/interprocess/sync/scoped_lock.hpp>
54 using Sh_lock = bipc::scoped_lock<bipc::named_mutex>;
74 using flow::log::Simple_ostream_logger;
75 using flow::log::Config;
77 using flow::Flow_log_component;
78 using bipc::permissions;
79 using bipc::interprocess_exception;
81 Config std_log_config{Sev::S_WARNING};
82 std_log_config.init_component_to_union_idx_mapping<Flow_log_component>
83 (1000, Config::standard_component_payload_enum_sparse_length<Flow_log_component>(),
true);
84 std_log_config.init_component_names<Flow_log_component>(flow::S_FLOW_LOG_COMPONENT_NAME_MAP,
false,
"flow-");
85 std_log_config.init_component_to_union_idx_mapping<
Log_component>
86 (2000, Config::standard_component_payload_enum_sparse_length<Log_component>(),
true);
89 Simple_ostream_logger std_logger{&std_log_config};
90 FLOW_LOG_SET_CONTEXT(&std_logger, Log_component::S_SHM);
123 const auto SUFFIX =
Shared_name::ct(
"shm") /
"arenaLend" /
"nextPoolId";
126 little_pool_name /= SUFFIX;
127 mutex_name /= SUFFIX;
130 perms.set_unrestricted();
135 "generate_pool_id().init",
146 Sh_lock sh_lock{*s_pool_id_mutex_or_none};
151 s_pool_id_shm_obj_or_none
152 = Shm_obj{util::OPEN_ONLY, little_pool_name.native_str(), bipc::read_write};
156 catch (
const boost::interprocess::interprocess_exception& exc)
160 if (exc.get_error_code() != boost::interprocess::not_found_error)
167 = Shm_obj{util::CREATE_ONLY, little_pool_name.native_str(), bipc::read_write, perms};
207 FLOW_LOG_FATAL(
"Due to above shocking error at making a named mutex+tiny SHM pool+mapping when trying to handle "
208 "SHM pool ID creation, we abort.");
231 Sh_lock sh_lock{*s_pool_id_mutex_or_none};
234 auto& id_ref = *(
static_cast<pool_id_t*
>(s_pool_id_shm_region_or_none.get_address()));
235 id = (++id_ref) << 1 >> 1;
242 assert((((id_ref << 1 >> 1) == 1)) &&
"(X00...0 + 1) must be (X00...1). Is the above logic broken?");
static std::once_flag s_pool_id_shm_region_init_flag
Used with std::call_once() to ensure s_pool_id_shm_region_or_none is initialized no more than once.
detail::pool_id_t pool_id_t
Pool ID type alias. Please see detail::pool_id_t doc header for discussion as to the chosen bit width...
static std::optional< boost::interprocess::named_mutex > s_pool_id_mutex_or_none
Initialized no more than once (in this process) by generate_pool_id(), a handle to a named-mutex prot...
static bipc::mapped_region s_pool_id_shm_region_or_none
Initialized no more than once (in this process) by generate_pool_id(), a handle to tiny SHM region st...
static pool_id_t generate_pool_id()
Returns a heretofore-unused pool ID so as to be used to identify (in a Shm_pool_offset_ptr_data::Repo...
static bipc::shared_memory_object s_pool_id_shm_obj_or_none
The SHM-object (pool) mapped by s_pool_id_shm_region_or_none.
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
static Shared_name ct(const Source &src)
Copy-constructs from a char-sequence container such as string or util::String_view.
static const Shared_name S_RESOURCE_TYPE_ID_SHM
Relative-folder fragment (no separators) identifying the resource type for: SHM pools.
static const Shared_name S_RESOURCE_TYPE_ID_MUTEX
Relative-folder fragment (no separators) identifying the resource type for: boost....
Segregated private stuff for ipc::shm::arena_lend.
uint32_t pool_id_t
Pool ID type.
@ S_SHM_BIPC_MISC_LIBRARY_ERROR
Low-level boost.ipc.shm: boost.interprocess emitted miscellaneous library exception sans a system cod...
const Open_or_create OPEN_OR_CREATE
Tag value indicating an open-if-exists-else-create operation.
Shared_name build_conventional_non_session_based_shared_name(const Shared_name &resource_type)
Builds an absolute name according to the path convention explained in Shared_name class doc header; t...
void op_with_possible_bipc_exception(flow::log::Logger *logger_ptr, Error_code *err_code, const Error_code &misc_bipc_lib_error, String_view context, const Func &func)
Internal (to ipc) utility that invokes the given function that invokes a boost.interprocess operation...
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
const boost::unordered_multimap< Log_component, std::string > S_IPC_LOG_COMPONENT_NAME_MAP
The map generated by flow::log macro magic that maps each enumerated value in ipc::Log_component to i...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.