Skip to content

Commit

Permalink
UserAllocatedEvent implementation
Browse files Browse the repository at this point in the history
UserAllocatedEvent provides mechanism for event posting and dispatching without
utilization of queue internal memory. UserAllocatedEvent embeds all underlying
event data and doesn't require any memory allocation while posting and dispatching.
All of these makes it cannot fail due to memory exhaustion while posting.
  • Loading branch information
maciejbocianski committed Aug 27, 2019
1 parent 3af1024 commit 61f5a87
Show file tree
Hide file tree
Showing 3 changed files with 431 additions and 6 deletions.
16 changes: 10 additions & 6 deletions events/EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace events {
// Predeclared classes
template <typename F>
class Event;
template <typename F, typename A>
class UserAllocatedEvent;

/**
* \defgroup events_EventQueue EventQueue class
Expand Down Expand Up @@ -1071,6 +1073,8 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
#if !defined(DOXYGEN_ONLY)
template <typename F>
friend class Event;
template <typename F, typename A>
friend class UserAllocatedEvent;
struct equeue _equeue;
mbed::Callback<void(int)> _update;

Expand All @@ -1095,7 +1099,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
struct context<F> {
F f;

context(F f)
constexpr context(F f)
: f(f) {}

template <typename... ArgTs>
Expand All @@ -1110,7 +1114,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
F f;
C0 c0;

context(F f, C0 c0)
constexpr context(F f, C0 c0)
: f(f), c0(c0) {}

template <typename... ArgTs>
Expand All @@ -1126,7 +1130,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
C0 c0;
C1 c1;

context(F f, C0 c0, C1 c1)
constexpr context(F f, C0 c0, C1 c1)
: f(f), c0(c0), c1(c1) {}

template <typename... ArgTs>
Expand All @@ -1143,7 +1147,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
C1 c1;
C2 c2;

context(F f, C0 c0, C1 c1, C2 c2)
constexpr context(F f, C0 c0, C1 c1, C2 c2)
: f(f), c0(c0), c1(c1), c2(c2) {}

template <typename... ArgTs>
Expand All @@ -1161,7 +1165,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
C2 c2;
C3 c3;

context(F f, C0 c0, C1 c1, C2 c2, C3 c3)
constexpr context(F f, C0 c0, C1 c1, C2 c2, C3 c3)
: f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}

template <typename... ArgTs>
Expand All @@ -1180,7 +1184,7 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
C3 c3;
C4 c4;

context(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
constexpr context(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
: f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}

template <typename... ArgTs>
Expand Down
Loading

0 comments on commit 61f5a87

Please sign in to comment.