Skip to content

Runques

kataklinger edited this page Nov 25, 2020 · 2 revisions

Runque represents queue of items ready to be served to consumers for processing. Order in which ready items are consumed can be configured by the user. Three options are available:

  1. FIFO - the first item made available gets served first
  2. LIFO - the last item made available gets served first
  3. Priority - available item with highest user-defined priority gets served first

frq::make_runque_t metafunction offers a way to configure desired runque:

template<typename Order,
         typename Mtm,
         typename Ty,
         typename Alloc,
         typename... Rest>
using make_runque_t = /* ... */;
  • Order defines in which order ready items are consumed. One of the following options are available:
    1. fifo_order
    2. lifo_order
    3. priority_order.
  • Mtm defines multithreading model. Only coro_thread_model is implemented.
  • Ty is type of items stored in runque
  • Alloc is obviously allocator used by queue itself
  • Rest can be used for passing additional parameters to desired runque type. In case of priority_order, it defines LessThen operation passed to underlying priority queue.

Ty parameter is not the same as user type on which forque operates. It is wrapping type that allows consumer to control item's lifetime. The type also provides a way to notify forque that item has been processed so it can ready next related item, if available.

Type returned by make_runque_t metafunction will satisfy runlike concept which is defined as:

template<typename Ty>
concept runlike = requires(Ty s) {
  typename Ty::value_type;
  requires runnable<typename Ty::value_type>;
  typename Ty::get_type;

  { s.get() } ->std::same_as<typename Ty::get_type>;
  { s.put(std::declval<typename Ty::value_type&&>()) };
};

where:

  • value_type - is type of items stored in the queue which needs to satisfy runnable concept,
  • get_type - is return type of get() member function that yields next available item,
  • get - is a function returning next available item and
  • put - is function adding item to the queue

runnable concept is rather simple. It only requires non-throwing move constructor:

template<typename Ty>
concept runnable =
  std::is_nothrow_move_constructible_v<Ty> && !std::is_reference_v<Ty>;

User's only responsibility is to configure desired runque type and to provide it to forque. User will not interact with runque directly.

Clone this wiki locally