Skip to content

Commit c3bffdf

Browse files
author
dave
committed
capture functionality behind a define switch: TM_ENABLE_CAPTURED_LAMBDAS
1 parent 7f7e9a7 commit c3bffdf

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ In the setup method, add an function callback that gets fired once in the future
3838
}, TIME_SECONDS);
3939
```
4040

41-
From 1.2 onwards: On ESP8266, ESP32, all mbed boards, and most 32 bit Arduino boards you can also capture values. An example of this usage follows:
41+
From 1.2 onwards: On ESP8266, ESP32, all mbed boards, and most 32 bit Arduino boards you can also *enable* argument capture in lambda expressions. By default, the feature is off because it is quite a heavy feature that many may never use.
42+
43+
To enable set add the following flag to your compile options, and it will be enabled if the board supports it: `-DTM_ENABLE_CAPTURED_LAMBDAS`
44+
45+
An example of this usage follows:
4246

4347
```
4448
int capturedValue = 42;

src/TaskPlatformDeps.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TimerTask;
1111

1212
#if defined(__MBED__) || defined(ARDUINO_ARDUINO_NANO33BLE)
1313

14-
#if !defined(TM_DONT_USE_CAPTURE)
14+
#if defined(TM_ENABLE_CAPTURED_LAMBDAS)
1515
#define TM_ALLOW_CAPTURED_LAMBDA
1616
#endif
1717

@@ -89,7 +89,7 @@ namespace tm_internal {
8989
#include "Arduino.h"
9090
typedef uint8_t pintype_t;
9191
# define IOA_USE_ARDUINO
92-
#if !defined(TM_DONT_USE_CAPTURE)
92+
#if defined(TM_ENABLE_CAPTURED_LAMBDAS)
9393
# define TM_ALLOW_CAPTURED_LAMBDA
9494
#endif
9595

@@ -273,7 +273,7 @@ inline void atomicWritePtr(TimerTaskAtomicPtr* pPtr, TimerTask* newValue) {
273273

274274
// for all mbed and ESP boards we already enable lambda captures, SAMD is a known extra case that works.
275275
// we can only enable on larger boards with enough memory to take the extra size of the structures.
276-
#if !defined(TM_DONT_USE_CAPTURE) && defined(ARDUINO_ARCH_SAMD)
276+
#if defined(TM_ENABLE_CAPTURED_LAMBDAS) && defined(ARDUINO_ARCH_SAMD)
277277
# define TM_ALLOW_CAPTURED_LAMBDA
278278
#endif
279279

@@ -357,7 +357,7 @@ namespace tm_internal {
357357
// Here we have one last go at determining if we should enable capture lambdas by checking if the functional include
358358
// is available, we only do so if we are on GCC > 5
359359
//
360-
# if !defined(TM_ALLOW_CAPTURED_LAMBDA) && !defined(TM_DONT_USE_CAPTURE) && __GNUC__ >= 5
360+
# if !defined(TM_ALLOW_CAPTURED_LAMBDA) && defined(TM_ENABLE_CAPTURED_LAMBDAS) && __GNUC__ >= 5
361361
#if __has_include(<functional>)
362362
# define TM_ALLOW_CAPTURED_LAMBDA
363363
#endif // _has_include

0 commit comments

Comments
 (0)