helics  2.8.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
AsioContextManager Class Reference

#include <AsioContextManager.h>

+ Inheritance diagram for AsioContextManager:

Public Types

using LoopHandle = std::unique_ptr< Servicer >
 

Public Member Functions

const std::string & getName () const
 
asio::io_context & getBaseContext () const
 
LoopHandle startContextLoop ()
 
bool isRunning () const
 

Static Public Member Functions

static std::shared_ptr< AsioContextManagergetContextPointer (const std::string &contextName=std::string())
 
static std::shared_ptr< AsioContextManagergetExistingContextPointer (const std::string &contextName=std::string())
 
static asio::io_context & getContext (const std::string &contextName=std::string())
 
static asio::io_context & getExistingContext (const std::string &contextName=std::string())
 
static void closeContext (const std::string &contextName=std::string())
 
static void setContextToLeakOnDelete (const std::string &contextName=std::string())
 
static LoopHandle runContextLoop (const std::string &contextName=std::string{})
 

Friends

void contextProcessingLoop (std::shared_ptr< AsioContextManager > ptr)
 

Detailed Description

class defining a (potential) singleton Asio io_context manager for all asio usage

Member Function Documentation

◆ getBaseContext()

asio::io_context& AsioContextManager::getBaseContext ( ) const
inline

get the underlying asio::io_context reference

Referenced by startContextLoop().

◆ getContext()

asio::io_context & AsioContextManager::getContext ( const std::string &  contextName = std::string())
static

get the asio io_context associated with the context manager

References getContextPointer().

◆ getContextPointer()

std::shared_ptr< AsioContextManager > AsioContextManager::getContextPointer ( const std::string &  contextName = std::string())
static

return a pointer to a context manager

the function will search for an existing context manager for the name if it doesn't find one it will create a new one

Parameters
contextNamethe name of the context to find or create

Referenced by getContext(), helics::getLocalExternalAddressV4(), and helics::getLocalExternalAddressV6().

◆ getExistingContext()

asio::io_context & AsioContextManager::getExistingContext ( const std::string &  contextName = std::string())
static

get the asio io_context associated with the context manager but only if the context exists if it doesn't this will throw and invalid_argument exception

References getExistingContextPointer().

◆ getExistingContextPointer()

std::shared_ptr< AsioContextManager > AsioContextManager::getExistingContextPointer ( const std::string &  contextName = std::string())
static

return a pointer to a context manager

the function will search for an existing context manager for the name if it doesn't find one it will return nullptr

Parameters
contextNamethe name of the context to find

Referenced by getExistingContext().

◆ getName()

const std::string& AsioContextManager::getName ( ) const
inline

get the name of the current context manager

◆ isRunning()

bool AsioContextManager::isRunning ( ) const
inline

check if the contextLoopo is running

◆ runContextLoop()

AsioContextManager::LoopHandle AsioContextManager::runContextLoop ( const std::string &  contextName = std::string{})
static

run a single thread for the context manager to execute asynchronous contexts in

will run a single thread for the io_context, it will not stop the thread until either the context manager is closed or the haltContextLoop function is called and there is no more work

Parameters
contextNamethe name of the context

◆ setContextToLeakOnDelete()

void AsioContextManager::setContextToLeakOnDelete ( const std::string &  contextName = std::string())
static

tell the context to free the pointer and leak the memory on delete

You may ask why, well in windows systems when operating in a DLL if this context is closed after certain other operations that happen when the DLL is unlinked bad things can happen, and since in nearly all cases this happens at Shutdown leaking really doesn't matter that much and if you don't the context could terminate before some other parts of the program which cause all sorts of odd errors and issues

◆ startContextLoop()

AsioContextManager::LoopHandle AsioContextManager::startContextLoop ( )

run a single thread for the context manager to execute asynchronous contexts in

will run a single thread for the io_context, it will not stop the thread until either the context manager is closed or the haltContextLoop function is called and there is no more work

References getBaseContext().


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