cycle_ptr
Public Member Functions | Related Functions | List of all members
cycle_ptr::gc_operation Class Reference

GC operations for delayed collection. More...

#include <util.h>

Public Member Functions

constexpr gc_operation () noexcept=default
 Default constructor performs no collections.
 
 gc_operation (detail::intrusive_ptr< detail::generation > g) noexcept
 Constructor for internal use.
 
auto operator() () noexcept -> void
 Run the GC. More...
 

Related Functions

(Note that these are not member functions.)

using delay_gc = std::function< void(gc_operation)>
 Function for delayed GC invocations. More...
 
auto get_delay_gc () -> delay_gc
 Read the current delay_gc function. More...
 
auto set_delay_gc (delay_gc f) -> delay_gc
 Set the delay_gc function. More...
 

Detailed Description

GC operations for delayed collection.

This functor invokes a garbage collect for a given generation.

Multiple invocations of this functor are idempotent.

Attention
Should be invoked at least once, or there is a risk of leaking memory.

Member Function Documentation

◆ operator()()

auto cycle_ptr::gc_operation::operator() ( ) -> void
inlinenoexcept

Run the GC.

Multiple calls to this method are idempotent.

Friends And Related Function Documentation

◆ delay_gc

using delay_gc = std::function<void(gc_operation)>
related

Function for delayed GC invocations.

This function is passed a function object representing a GC invocation. It should ensure this function object will be executed at least once, at some point.

Multiple GC requests may occur, for multiple generations. However, a single generation will not issue a secondary request until the GC operation has started.

Calling get_delay_gc() or set_delay_gc() during this function will result in dead lock.

If the delay_gc function throws an exception, the code will swallow that exception and execute the GC operation immediately. If the function returns normally, it has responsibility for executing the gc_operation argument.

See also
set_delay_gc
get_delay_gc

◆ get_delay_gc()

auto get_delay_gc ( ) -> delay_gc
related

Read the current delay_gc function.

Returns the currently installed delay_gc function. Any GC requests will be submitted to the installed function.

If the returned function is empty (i.e. nullptr), GC operations are not delayed.

Returns
The currently installed delay_gc function.

◆ set_delay_gc()

auto set_delay_gc ( delay_gc  f) -> delay_gc
related

Set the delay_gc function.

This method synchronizes with all its invocations, ensuring that no calls to the old function are in progress when this function returns.

This could for example be used in combination with boost::asio, to submit GC operations:

boost::asio::io_context io_context;
[&io_contex](gc_operation op) {
boost::asio::post(io_context, std::move(op));
});
Parameters
[in]f

The function to install for delayed GC. Future GC requests will post using the installed function f.

If the function is empty (i.e. nullptr), future GC operations will be executed immediately.

Returns
The previous delay_gc function

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