Class ControllerManager::RTControllerListWrapper

Nested Relationships

This class is a nested type of Class ControllerManager.

Class Documentation

class RTControllerListWrapper

The RTControllerListWrapper class wraps a double-buffered list of controllers to avoid needing to lock the real-time thread when switching controllers in the non-real-time thread.

There’s always an “updated” list and an “outdated” one There’s always an “used by rt” list and an “unused by rt” list

The updated state changes on the switch_updated_list() The rt usage state changes on the update_and_get_used_by_rt_list()

Public Functions

std::vector<ControllerSpec> &update_and_get_used_by_rt_list()

update_and_get_used_by_rt_list Makes the “updated” list the “used by rt” list

Warning

Should only be called by the RT thread, no one should modify the updated list while it’s being used

Returns:

reference to the updated list

std::vector<ControllerSpec> &get_unused_list(const std::lock_guard<std::recursive_mutex> &guard)

get_unused_list Waits until the “outdated” and “unused by rt” lists match and returns a reference to it This referenced list can be modified safely until switch_updated_controller_list() is called, at this point the RT thread may start using it at any time

Parameters:

guard[in] Guard needed to make sure the caller is the only one accessing the unused by rt list

const std::vector<ControllerSpec> &get_updated_list(const std::lock_guard<std::recursive_mutex> &guard) const

get_updated_list Returns a const reference to the most updated list.

Warning

May or may not being used by the realtime thread, read-only reference for safety

Parameters:

guard[in] Guard needed to make sure the caller is the only one accessing the unused by rt list

void switch_updated_list(const std::lock_guard<std::recursive_mutex> &guard)

switch_updated_list Switches the “updated” and “outdated” lists, and waits until the RT thread is using the new “updated” list.

Parameters:

guard[in] Guard needed to make sure the caller is the only one accessing the unused by rt list

Public Members

mutable std::recursive_mutex controllers_lock_