24#include <boost/move/make_unique.hpp> 
   29template<
typename Mode_tag>
 
   33  flow::log::Log_context(logger_ptr, 
Log_component::S_TRANSPORT),
 
   34  m_pool_name(pool_name_arg)
 
   36  using boost::io::ios_all_saver;
 
   37  using boost::movelib::make_unique;
 
   39  assert(pool_sz >= 
sizeof(
void*));
 
   40  static_assert(std::is_same_v<Mode_tag, util::Create_only> || std::is_same_v<Mode_tag, util::Open_or_create>,
 
   41                "Can only delegate to this ctor with Mode_tag = Create_only or Open_or_create.");
 
   42  constexpr char const * MODE_STR = std::is_same_v<Mode_tag, util::Create_only>
 
   43                                      ? 
"create-only" : 
"open-or-create";
 
   45  if (get_logger()->should_log(flow::log::Sev::S_INFO, get_log_component()))
 
   47    ios_all_saver saver(*(get_logger()->this_thread_ostream())); 
 
   48    FLOW_LOG_INFO_WITHOUT_CHECKING
 
   49      (
"SHM-classic pool [" << *
this << 
"]: Constructing heap handle to heap/pool at name [" << 
m_pool_name << 
"] in " 
   50       "[" << MODE_STR << 
"] mode; pool size [" << flow::util::ceil_div(pool_sz, 
size_t(1024 * 1024)) << 
"Mi]; " 
   51       "perms = [" << std::setfill(
'0') << std::setw(4) << std::oct << perms.get_permissions() << 
"].");
 
   81  flow::log::Log_context(logger_ptr, 
Log_component::S_TRANSPORT),
 
   82  m_pool_name(pool_name_arg)
 
   84  using boost::movelib::make_unique;
 
   86  FLOW_LOG_INFO(
"SHM-classic pool [" << *
this << 
"]: Constructing heap handle to heap/pool at name " 
   87                "[" << 
m_pool_name << 
"] in open-only mode; paged read-only? = [" << read_only << 
"].");
 
   90                                        "Pool_arena(OPEN_ONLY): Pool()", [&]()
 
   99  FLOW_LOG_INFO(
"SHM-classic pool [" << *
this << 
"]: Closing handle.");
 
  104  assert((n != 0) && 
"Please do not allocate(0).");
 
  112  if (get_logger()->should_log(flow::log::Sev::S_DATA, get_log_component()))
 
  114    const auto total = 
m_pool->get_size();
 
  115    const auto prev_free = 
m_pool->get_free_memory();
 
  116    const auto ret = 
m_pool->allocate(n); 
 
  117    const auto now_free  = 
m_pool->get_free_memory();
 
  118    assert(total == 
m_pool->get_size());
 
  120    FLOW_LOG_DATA_WITHOUT_CHECKING(
"SHM-classic pool [" << *
this << 
"]: SHM-alloc-ed user buffer sized [" << n << 
"]; " 
  121                                   "bipc alloc-algo reports free space changed " 
  122                                   "[" << prev_free << 
"] (used [" << (total - prev_free) << 
"]) => " 
  123                                   "[" << now_free << 
"] (used [" << (total - now_free) << 
"]); " 
  124                                   "raw delta [" << (prev_free - now_free) << 
"].");
 
  129  return m_pool->allocate(n); 
 
  134  assert(buf_not_null && 
"Please do not deallocate(nullptr).");
 
  142  if (get_logger()->should_log(flow::log::Sev::S_DATA, get_log_component()))
 
  144    const auto total = m_pool->get_size();
 
  145    const auto prev_free = m_pool->get_free_memory();
 
  146    m_pool->deallocate(buf_not_null); 
 
  147    const auto now_free  = m_pool->get_free_memory();
 
  148    assert(total == m_pool->get_size());
 
  150    FLOW_LOG_DATA_WITHOUT_CHECKING(
"SHM-classic pool [" << *
this << 
"]: SHM-dealloc-ed user buffer (size unknown) " 
  151                                   "bipc alloc-algo reports free space changed " 
  152                                   "[" << prev_free << 
"] (used [" << (total - prev_free) << 
"]) => " 
  153                                   "[" << now_free << 
"] (used [" << (total - now_free) << 
"]); " 
  154                                   "raw delta [" << (now_free - prev_free) << 
"].");
 
  158    m_pool->deallocate(buf_not_null);
 
  173  return os << 
'@' << &val << 
" => sh_name[" << val.
m_pool_name << 
']';
 
A SHM-classic interface around a single SHM pool with allocation-algorithm services by boost....
Pool_arena(flow::log::Logger *logger_ptr, const Shared_name &pool_name, util::Create_only mode_tag, size_t pool_sz, const util::Permissions &perms=util::Permissions(), Error_code *err_code=0)
Construct Pool_arena accessor object to non-existing named SHM pool, creating it first.
bool deallocate(void *buf_not_null) noexcept
Undoes effects of local allocate() that returned buf_not_null; or another-process's allocate() that r...
boost::movelib::unique_ptr< Pool > m_pool
Attached SHM pool. If ctor fails in non-throwing fashion then this remains null. Immutable after ctor...
const Shared_name m_pool_name
SHM pool name as set immutably at construction.
void * allocate(size_t n)
Allocates buffer of specified size, in bytes, in the accessed pool; returns locally-derefernceable ad...
~Pool_arena()
Destroys Pool_arena accessor object.
static void remove_persistent(flow::log::Logger *logger_ptr, const Shared_name &name, Error_code *err_code=0)
Removes the named SHM pool object.
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
const char * native_str() const
Returns (sans copying) pointer to NUL-terminated wrapped name string, suitable to pass into sys calls...
@ S_SHM_BIPC_MISC_LIBRARY_ERROR
Low-level boost.ipc.shm: boost.interprocess emitted miscellaneous library exception sans a system cod...
ipc::shm sub-module with the SHM-classic SHM-provider. See ipc::shm doc header for introduction.
std::ostream & operator<<(std::ostream &os, const Pool_arena &val)
Prints string representation of the given Pool_arena to the given ostream.
bipc::permissions Permissions
Short-hand for Unix (POSIX) permissions class.
void remove_persistent_shm_pool(flow::log::Logger *logger_ptr, const Shared_name &pool_name, Error_code *err_code)
Equivalent to shm::classic::Pool_arena::remove_persistent().
bipc::open_only_t Open_only
Tag type indicating an ideally-atomic open-if-exists-else-fail operation.
const Open_or_create OPEN_OR_CREATE
Tag value indicating an open-if-exists-else-create operation.
const Open_only OPEN_ONLY
Tag value indicating an atomic open-if-exists-else-fail operation.
bipc::open_or_create_t Open_or_create
Tag type indicating an atomic open-if-exists-else-create operation.
bipc::create_only_t Create_only
Tag type indicating a create-unless-exists-else-fail operation.
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...
const Create_only CREATE_ONLY
Tag value indicating an atomic create-unless-exists-else-fail operation.
Log_component
The flow::log::Component payload enumeration containing various log components used by Flow-IPC inter...
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.