Skip to content

Commit 6934ee8

Browse files
committed
Don't require platform.callback-nontrivial
Don't use an `Event` with `Callback` - it's non-trivial, so needs the "full" form of `Callback`. `Callback` is being switched to not support non-trivial functors by default to save ROM. Use a `reference_wrapper` to a `UserAllocatedEvent` instead, which works fine with the trivial-only `Callback`. A `reference_wrapper` is small enough to fit in a `Callback`, and is trivially-copyable, so works to decouple the event lifetime from the callback. Having decoupled it, the event has program lifetime, so may as well be `UserAllocatedEvent` for simplicity. (`UserAllocatedEvent` could be trivial, but is too big to be placed in a `Callback` directly in any case).
1 parent a647cf9 commit 6934ee8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "mbed.h"
1717
#include <stdio.h>
1818
#include <errno.h>
19+
#include <functional>
1920

2021
#include "BlockDevice.h"
2122

@@ -68,14 +69,15 @@ void erase() {
6869
}
6970
}
7071

72+
static auto erase_event = mbed_event_queue()->make_user_allocated_event(erase);
7173

7274
// Entry point for the example
7375
int main() {
7476
printf("--- Mbed OS filesystem example ---\n");
7577

7678
// Setup the erase event on button press, use the event queue
7779
// to avoid running in interrupt context
78-
irq.fall(mbed_event_queue()->event(erase));
80+
irq.fall(std::ref(erase_event));
7981

8082
// Try to mount the filesystem
8183
printf("Mounting the filesystem... ");

0 commit comments

Comments
 (0)