Class ILLIXR::switchboard::topic
Represents a topic. More...
Public Functions
Type | Name |
---|---|
void | deserialize_and_put (std::vector< char > & buffer, network::topic_config & config) |
ptr< const event > | get () const Gets a read-only copy of the most recent event on the topic. |
topic_buffer & | get_buffer () |
const std::string & | name () |
void | put (ptr< const event > && this_event) Publishes this_event to the topic. |
void | schedule (plugin_id_t plugin_id, const std::function< void(ptr< const event > &&, std::size_t)> & callback) Schedules callback on the topic (plugin_id is for accounting) |
void | stop () Stop and remove all topic_subscription threads. |
topic (std::string name, const std::type_info & ty, std::shared_ptr< record_logger > record_logger_) |
|
const std::type_info & | ty () |
Detailed Description
Note, this class cannot have any static type-information about the contained events because I need to hold all of the topics in a homogeneous container (can't add topic<int> and topic<float> to the same std::vector<topic<WHAT_GOES_HERE>>).
Therefore, this class uses type-erasure, and regards all events as type event
. I could have used std::any
for this, but I think inheriting event
will be slightly more efficient because it avoids a heap-allocation.
However, this class can have dynamic type-information in ty, that gets set and checked at runtime.
Public Functions Documentation
function deserialize_and_put
inline void topic::deserialize_and_put (
std::vector< char > & buffer,
network::topic_config & config
)
function get
Gets a read-only copy of the most recent event on the topic.
inline ptr < const event > topic::get () const
function get_buffer
inline topic_buffer & topic::get_buffer ()
function name
inline const std::string & topic::name ()
function put
Publishes this_event
to the topic.
inline void topic::put (
ptr < const event > && this_event
)
Thread-safe * Caveat:This (circular) queue based solution may race if >= N write attempts to the N-sized queue interrupt a concurrent reader (using 'get').The reader's critical section is as follows: * Read the latest serial number * Compute the serial's modulus * Dereference and access the position in the queue/array
The critical section is extremely small, so a race is unlikely, albeit possible. The probability of a data race decreases geometrically with N.
function schedule
Schedules callback
on the topic (plugin_id
is for accounting)
inline void topic::schedule (
plugin_id_t plugin_id,
const std::function< void( ptr < const event > &&, std::size_t)> & callback
)
Thread-safe
function stop
Stop and remove all topic_subscription threads.
inline void topic::stop ()
Thread-safe
function topic
inline topic::topic (
std::string name,
const std::type_info & ty,
std::shared_ptr< record_logger > record_logger_
)
function ty
inline const std::type_info & topic::ty ()
The documentation for this class was generated from the following file /home/friedel/devel/ILLIXR/include/illixr/switchboard.hpp