21#ifndef __MULTIDELEGATE_H
22#define __MULTIDELEGATE_H
25#if defined(ESP8266) || defined(ESP32) || !defined(ARDUINO)
32#include <interrupts.h>
33using esp8266::InterruptLock;
51 template<
typename Delegate,
typename R,
bool ISQUEUE =
false,
typename... P>
54 static R execute(
Delegate& del, P... args)
60 template<
typename Delegate,
bool ISQUEUE,
typename... P>
61 struct CallP<
Delegate, void, ISQUEUE, P...>
63 static bool execute(
Delegate& del, P... args)
70 template<
typename Delegate,
typename R,
bool ISQUEUE = false>
79 template<
typename Delegate,
bool ISQUEUE>
96 template<
typename Delegate,
typename R,
bool ISQUEUE =
false,
size_t QUEUE_CAPACITY = 32,
typename... P>
202#if defined(ESP8266) || defined(ESP32)
203 result =
new (std::nothrow)
Node_t;
224 class iterator :
public std::iterator<std::forward_iterator_tag, Delegate>
236 operator bool()
const
301#if defined(ESP8266) || defined(ESP32)
302 new (std::nothrow)
Node_t;
310 item->
mNext =
nullptr;
365 operator bool()
const
378#if defined(ARDUINO) && !defined(ESP32)
379 if (fence.
load())
return {};
382 if (fence.exchange(
true))
return {};
388 result = CallP<Delegate, R, ISQUEUE, P...>::execute(*it, args...);
389 if (result && ISQUEUE)
393#if defined(ESP8266) || defined(ESP32)
395 optimistic_yield(10000);
404 template<
typename Delegate,
typename R =
void,
bool ISQUEUE = false,
size_t QUEUE_CAPACITY = 32>
412 auto it = this->
begin();
418#if defined(ARDUINO) && !defined(ESP32)
419 if (fence.
load())
return {};
422 if (fence.exchange(
true))
return {};
428 result = Call<Delegate, R, ISQUEUE>::execute(*it);
429 if (result && ISQUEUE)
430 it = this->
erase(it);
433#if defined(ESP8266) || defined(ESP32)
435 optimistic_yield(10000);
446 template<
typename Delegate,
typename R,
bool ISQUEUE,
size_t QUEUE_CAPACITY,
typename... P>
453 template<
typename Delegate,
typename R,
bool ISQUEUE,
size_t QUEUE_CAPACITY>
460 template<
typename Delegate,
bool ISQUEUE,
size_t QUEUE_CAPACITY,
typename... P>
468 auto it = this->begin();
474#if defined(ARDUINO) && !defined(ESP32)
475 if (fence.
load())
return;
478 if (fence.exchange(
true))
return;
483 CallP<Delegate, void, ISQUEUE, P...>::execute(*it, args...);
485 it = this->erase(it);
488#if defined(ESP8266) || defined(ESP32)
490 optimistic_yield(10000);
498 template<
typename Delegate,
bool ISQUEUE,
size_t QUEUE_CAPACITY>
506 auto it = this->begin();
512#if defined(ARDUINO) && !defined(ESP32)
513 if (fence.
load())
return;
516 if (fence.exchange(
true))
return;
521 Call<Delegate, void, ISQUEUE>::execute(*it);
523 it = this->erase(it);
526#if defined(ESP8266) || defined(ESP32)
528 optimistic_yield(10000);
560template<
typename Delegate,
bool ISQUEUE = false,
size_t QUEUE_CAPACITY = 32>
Definition Delegate.h:2049
Definition MultiDelegate.h:35
InterruptLock()
Definition MultiDelegate.h:37
~InterruptLock()
Definition MultiDelegate.h:40
Definition MultiDelegate.h:562
Definition Delegate.h:1657
void operator()()
Definition MultiDelegate.h:504
void operator()(P... args)
Definition MultiDelegate.h:466
Definition MultiDelegate.h:444
Definition MultiDelegate.h:406
R operator()()
Definition MultiDelegate.h:410
Definition MultiDelegate.h:225
iterator(MultiDelegatePImpl &md)
Definition MultiDelegate.h:231
Delegate & operator*() const
Definition MultiDelegate.h:248
Node_t * prev
Definition MultiDelegate.h:228
Node_t * current
Definition MultiDelegate.h:227
iterator(const iterator &)=default
Delegate * operator->() const
Definition MultiDelegate.h:252
iterator & operator++()
Definition MultiDelegate.h:256
iterator & operator=(const iterator &)=default
const Node_t * stop
Definition MultiDelegate.h:229
bool operator!=(const iterator &rhs) const
Definition MultiDelegate.h:244
iterator & operator++(int)
Definition MultiDelegate.h:267
bool operator==(const iterator &rhs) const
Definition MultiDelegate.h:240
iterator & operator=(iterator &&)=default
Definition MultiDelegate.h:98
Node_t * unused
Definition MultiDelegate.h:184
iterator end() const
Definition MultiDelegate.h:279
MultiDelegatePImpl & operator+=(Delegate &&del)
Definition MultiDelegate.h:165
MultiDelegatePImpl & operator+=(const Delegate &del)
Definition MultiDelegate.h:159
iterator begin()
Definition MultiDelegate.h:275
MultiDelegatePImpl(Delegate &&del)
Definition MultiDelegate.h:126
const Delegate *IRAM_ATTR add(Delegate &&del)
Definition MultiDelegate.h:289
Node_t *IRAM_ATTR get_node_unsafe()
Definition MultiDelegate.h:190
MultiDelegatePImpl(const Delegate &del)
Definition MultiDelegate.h:121
Node_t * last
Definition MultiDelegate.h:183
MultiDelegatePImpl(MultiDelegatePImpl &&md)
Definition MultiDelegate.h:109
size_t nodeCount
Definition MultiDelegate.h:185
~MultiDelegatePImpl()
Definition MultiDelegate.h:101
void recycle_node_unsafe(Node_t *node)
Definition MultiDelegate.h:213
MultiDelegatePImpl & operator=(std::nullptr_t)
Definition MultiDelegate.h:144
MultiDelegatePImpl & operator=(const MultiDelegatePImpl &)=delete
bool erase(const Delegate *const del)
Definition MultiDelegate.h:350
MultiDelegatePImpl(const MultiDelegatePImpl &)=delete
MultiDelegatePImpl()=default
Node_t * first
Definition MultiDelegate.h:182
MultiDelegatePImpl & operator=(MultiDelegatePImpl &&md)
Definition MultiDelegate.h:131
iterator erase(iterator it)
Definition MultiDelegate.h:321
std::mutex mutex_unused
Definition MultiDelegate.h:221
R operator()(P... args)
Definition MultiDelegate.h:370
const Delegate *IRAM_ATTR add(const Delegate &del)
Definition MultiDelegate.h:284
T load(std::memory_order=std::memory_order_seq_cst) const volatile noexcept
Definition ghostl.h:47
void store(T desired, std::memory_order=std::memory_order_seq_cst) volatile noexcept
Definition ghostl.h:46
T && move(T &t) noexcept
Definition ghostl.h:50
decltype(nullptr) nullptr_t
Definition ghostl.h:80
T && forward(typename identity< T >::type &t) noexcept
Definition ghostl.h:88
Definition MultiDelegate.h:173
Node_t * mNext
Definition MultiDelegate.h:178
Delegate mDelegate
Definition MultiDelegate.h:179
~Node_t()
Definition MultiDelegate.h:174