35#include <flow/log/log.hpp>
183 private boost::noncopyable
239 const std::atomic<bool>* skip_fast_path_verbose_logging_ptr,
269 const std::atomic<bool>* skip_fast_path_verbose_logging_ptr,
385 template<
typename Container>
485 const std::atomic<bool>* skip_fast_path_verbose_logging_ptr);
544 "Size of 1 slot in the use-count-storing custom pool-allocator must equal the size of the value "
545 "we in fact store in each such slot.");
546 static_assert(Atomic_use_ct::is_always_lock_free,
547 "Atomic_use_ct must be lock-free: a non-lock-free atomic is implemented via per-process lock state "
548 "which cannot work across processes; and lock-freedom implies address-freedom in practice; "
549 "address-freedom makes our cross-process (SHM) use-count ops work. See also its doc header.");
589 static_assert(
decltype(
m_n_unused)::is_always_lock_free,
"Another atomic counter in SHM.");
630 "Another atomic counter in SHM.");
698 template<
typename Logging_task>
755template<
typename Container>
761 container->reserve(N);
765 for (
auto& hint : hints)
767 use_ct_idx = hint.exchange(0, std::memory_order_relaxed);
771 container->push_back(--use_ct_idx);
796 const auto logger_ptr = get_logger();
797 if (logger_ptr && logger_ptr->should_log(flow::log::Sev::S_TRACE, get_log_component()))
799 for (
const auto use_ct_idx : *container)
801 FLOW_LOG_TRACE_WITHOUT_CHECKING
802 (
"Lend-tracker pool [" << *
this <<
"]: Emitted/reset unused-object-not-yet-deleted hint: "
803 "use-count is/was 0 at idx [" << use_ct_idx <<
"], "
811 FLOW_LOG_TRACE_WITHOUT_CHECKING
812 (
"Lend-tracker pool [" << *
this <<
"]: Emitted/reset [" << container->size() <<
"] "
813 "unused-object-not-yet-deleted hints.");
820template<
typename Logging_task>
823 m_log_ctx->log_while_locked(logging_task);
This internal-use class represents, essentially, a handle to the use-count database (which the class ...
use_ct_idx_t use_ct_ptr_to_idx(const Atomic_use_ct *use_ct_ptr) const
The reverse of use_ct_idx_to_ptr(), this converts a process-local vaddr pointing at a use-count slot ...
void emit_unused_ct_idx_hints(Container *container)
Collects the indices of use-count slots that have been flagged (by use_count_dec()) as having reached...
friend std::ostream & operator<<(std::ostream &, const Lend_tracker_pool &)
Prints string representation of the given Lend_tracker_pool to the given ostream.
Lend_tracker_pool(const flow::log::Log_context_mt *log_ctx, const std::atomic< bool > *skip_fast_path_verbose_logging_ptr, const Shared_name &pool_name, util::Create_only mode_tag, Obj_db_aux_pool_stats *stats, const util::Permissions &perms={})
Constructs the admin-mode (creating) handle: creates the SHM-pool named pool_name and initializes its...
void update_log_context(const flow::log::Log_context_mt *log_ctx, const std::atomic< bool > *skip_fast_path_verbose_logging_ptr)
Updates the logging context initially provided via ctor.
const flow::log::Log_context_mt * m_log_ctx
See update_log_context().
const Shared_name m_pool_name
SHM pool name as set immutably at construction.
unsigned int use_count_inc(use_ct_idx_t use_ct_idx)
Atomically increments the use-count at the given slot.
std::optional< Pool > m_pool
Un-nullified permanently in ctor, this is the handle to the high-perf use-count-tracking SHM-pool per...
static constexpr size_t S_N_UNUSED_IDX_HINTS
The max number of unused-slot hints emit_unused_ct_idx_hints() can emit.
const std::atomic< bool > * m_skip_fast_path_verbose_logging_ptr
See update_log_context().
std::atomic< uint32_t > Atomic_use_ct
The type of value stored in each use-count slot in m_pool.
signed int n_unused() const
Returns the current count of use-count slots that are unused-referencing (use-count has reached zero ...
bool dead() const
Returns false (indicating liveness of the SHM-pool we handle) throughout; until the admin-mode (m_is_...
Obj_db_aux_pool_stats * m_stats
Stats to update in admin-mode; null => skips stat-keeping.
bool skip_fast_path_verbose_logging() const
Reads m_skip_fast_path_verbose_logging_ptr pointee's current value.
void log_while_locked(Logging_task &&logging_task) const
Forwards to m_log_ctx->log_while_locked().
bool use_count_return_if_unused(use_ct_idx_t *use_ct_idx_ptr)
Checks whether the use-count at slot *use_ct_idx_ptr has reached zero; if so, returns the slot to the...
unsigned int use_count_dec_admin(use_ct_idx_t *use_ct_idx_ptr)
Atomically decrements the use-count at the given slot; for use in admin mode (m_is_creator is true: t...
void use_count_return_bc_unused(use_ct_idx_t *use_ct_idx, bool was_not_counted_as_unused)
Helper that, given the pre-condition that use-count slot *use_ct_idx has been decremented to 0 but is...
Metadata * m_metadata
Pointer to the Metadata in m_pool; also used as the base for use_ct_idx indices produced or consumed ...
unsigned int use_count_dec(use_ct_idx_t use_ct_idx)
Atomically decrements the use-count at the given slot; for use in client mode (m_is_creator is false)...
use_ct_idx_t use_count_new()
Allocates a new use-count slot and initializes its value to 1 (one extant handle: the just-constructe...
~Lend_tracker_pool()
Destroys this handle.
void * pool_allocate(size_t sz)
Forwards to m_pool->allocate(sz) while recording – accurately but performantly – into *m_stats as nee...
const bool m_is_creator
true if admin-mode (create-mode ctor was used); false if client-mode (open-mode ctor was used).
unsigned int use_count(use_ct_idx_t use_ct_idx) const
Returns the current use-count value at the given slot.
Atomic_use_ct * use_ct_idx_to_ptr(use_ct_idx_t use_ct_idx) const
The reverse of use_ct_ptr_to_idx().
static constexpr size_t S_ALLOC_SZ
This important constant defines the mandatory size of each allocation – that is argument to allocate(...
Similar to bipc's basic_managed_shared_memory, except that if a ctor created the SHM-pool in the file...
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
Segregated private stuff for ipc::shm::arena_lend.
uint32_t use_ct_idx_t
Index into a given Lend_tracker_pool's bulk storage of arena-construct()ed (outer a/k/a first-class) ...
shm::bipc_ext::Sparse_managed_shm< Use_count_registry, ::ipc::bipc::null_index > Lend_tracker_shm
The managed-SHM-pool type underlying each Lend_tracker_pool: Use_count_registry as the memory-algorit...
bipc::permissions Permissions
Short-hand for Unix (POSIX) permissions class.
bipc::open_only_t Open_only
Tag type indicating an ideally-atomic open-if-exists-else-fail operation.
bipc::create_only_t Create_only
Tag type indicating a create-unless-exists-else-fail operation.
Stats about the RAM use of the arena-lending SHM-provider's auxiliary (non-user-data) SHM-pools which...