REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::detail::dfa_lease Class Reference

This thread's DFA set for one regex, for the lifetime of the lease: a scan through it takes no lock, so threads sharing a regex do not queue on its DFAs. More...

#include <onepass.hpp>

Collaboration diagram for real::detail::dfa_lease:
[legend]

Classes

struct  cache
 The set a thread keeps between leases, and the slot it returns to. More...
 

Public Member Functions

 dfa_lease (regex_immutables *immut)
 Leases a DFA set for immut, cleared if it was built for an earlier program.
 
 dfa_lease (const dfa_lease &)=delete
 
dfa_lease & operator= (const dfa_lease &)=delete
 
 dfa_lease (dfa_lease &&)=delete
 
dfa_lease & operator= (dfa_lease &&)=delete
 
 ~dfa_lease ()
 Ends the lease: the cached set stays with this thread, a nested one goes back to its pool.
 
shared_dfa_set & operator* () const noexcept
 The leased set.
 
shared_dfa_set * operator-> () const noexcept
 The leased set's members.
 

Static Public Member Functions

static void drop_thread_set (const shared_dfa_slot &slot) noexcept
 Frees this thread's cached set if it came from slot and no lease holds it: the slot's regex is gone, so no lease will ask for it again.
 

Static Private Member Functions

static cache & thread_cache ()
 This thread's cache.
 
static std::shared_ptr< shared_dfa_slot > slot_for (regex_immutables *immut)
 The slot for immut, created on first use (a shared reference: it may be retired).
 
static std::unique_ptr< shared_dfa_set > take (shared_dfa_slot &slot)
 A free set from slot's pool, or a new one.
 
static void give (shared_dfa_slot &slot, std::unique_ptr< shared_dfa_set > set) noexcept
 Returns set to slot's pool, or frees it when the pool cannot take it.
 

Private Attributes

shared_dfa_slot * slot_ {nullptr}
 The slot the set belongs to.
 
shared_dfa_set * set_ {nullptr}
 The leased set.
 
bool cached_ {false}
 The set is this thread's cached one.
 
std::shared_ptr< shared_dfa_slot > nested_slot_
 The slot of a nested lease.
 
std::unique_ptr< shared_dfa_set > nested_set_
 The set of a nested lease.
 

Detailed Description

This thread's DFA set for one regex, for the lifetime of the lease: a scan through it takes no lock, so threads sharing a regex do not queue on its DFAs.

Each thread keeps the set it last used, with its slot, and gives it back to that slot's pool when it moves to another regex or exits; a repeat lease is an owner check and a generation check. A nested lease (a scan started inside another scan) takes a separate set from the pool and returns it on destruction, so the outer scan's set is never handed away under it.

Constructor & Destructor Documentation

◆ dfa_lease()

real::detail::dfa_lease::dfa_lease ( regex_immutables *  immut)
inlineexplicit

Leases a DFA set for immut, cleared if it was built for an earlier program.

Parameters
[in]immutThe regex whose DFAs are wanted.

Member Function Documentation

◆ drop_thread_set()

static void real::detail::dfa_lease::drop_thread_set ( const shared_dfa_slot &  slot)
inlinestaticnoexcept

Frees this thread's cached set if it came from slot and no lease holds it: the slot's regex is gone, so no lease will ask for it again.

Parameters
[in]slotThe retired slot.

◆ give()

static void real::detail::dfa_lease::give ( shared_dfa_slot &  slot,
std::unique_ptr< shared_dfa_set >  set 
)
inlinestaticprivatenoexcept

Returns set to slot's pool, or frees it when the pool cannot take it.

Called from destructors, so it cannot throw: a lock that fails or a pool that cannot grow leaves set to be freed here instead of pooled, which costs the next lease a rebuild and nothing else.

Parameters
[in,out]slotThe slot the set belongs to.
[in]setThe set given back.

◆ operator*()

shared_dfa_set & real::detail::dfa_lease::operator* ( ) const
inlinenoexcept

The leased set.

Returns
The set.

◆ operator->()

shared_dfa_set * real::detail::dfa_lease::operator-> ( ) const
inlinenoexcept

The leased set's members.

Returns
The set.

◆ slot_for()

static std::shared_ptr< shared_dfa_slot > real::detail::dfa_lease::slot_for ( regex_immutables *  immut)
inlinestaticprivate

The slot for immut, created on first use (a shared reference: it may be retired).

Parameters
[in]immutThe regex whose slot is wanted.
Returns
The slot.

◆ take()

static std::unique_ptr< shared_dfa_set > real::detail::dfa_lease::take ( shared_dfa_slot &  slot)
inlinestaticprivate

A free set from slot's pool, or a new one.

Parameters
[in,out]slotThe slot whose pool is drawn from.
Returns
The set.

◆ thread_cache()

static cache & real::detail::dfa_lease::thread_cache ( )
inlinestaticprivate

This thread's cache.

Returns
The cache.

The documentation for this class was generated from the following file: