Unfortunately, it is very difficult to infer the parameters of
function-objects generically in C++03 without any additional type
information. The current implementation fails to do so, and the compiler
simply bails with "unable to deduce template parameter".
Rather than leaving the user with a small novel of error messages, this
patch removes the problematic callback overloads, leaving only callback
overloads for the original pointer types.
The callback class can now accept generalized function-objects:
class Thing {
public:
int value;
void operator()() {
printf("hi! %d\n", value);
}
};
Callback<void()> cb(Thing(2));
However, with the intention of avoiding implicit dynamic-memory
allocations, the Callback class is limited to a single word of storage.
Exceeding this size will eliminate the function-object type from the
overload set and fail to compile.
Effort was invested to make this situation very clear to the user. Here
is an example error message with noise removed:
[ERROR] ./main.cpp: In function 'int main()':
./mbed-os/hal/api/Ticker.h:101:10: note:
no known conversion for argument 1 from 'BigFunc' to 'mbed::Callback<void()>'
The real benefit of this change is the ability for users to hook into
the attributes of the Callback class. This mostly allows lifetime
management of the function-objects from third-party libraries (such as
the Event class from mbed-events).
Note: The convenient `callback` function may become ambiguous if
provided with a type that defines multiple incompatible `operator()`
member functions.
This allows additional attributes to be attached to the internally
generated type such as move and destructor operations with no increase
in RAM footprint.
The current overloads can't take advantage of this, but it does open
the possibility for more powerful overloads that can provide these
additional attributes.
Changes to mbed-os memory consumption:
.text .data .bss
before 57887 2292 7692
after 57842 2292 7691
Enable the low power timer for the following targets:
- NUCLEO_F411RE
- NUCLEO_F401RE
- DISCO_F429ZI
- NUCLEO_F446RE
- NUCLEO_F410RB
- DISCO_F469NI
- NUCLEO_F446ZE
- B86B_F446VE
* 'master' of https://github.com/ARMmbed/mbed-os: (63 commits)
[XDOT_L151] add IAR support
Modify mbedtls scripts to add config-no-entropy.h
Remove extra spaces
[XDOT_L151] include xDot in mbed 5 releases
[STM32F429ZI] INITIAL_SP correction
[STM32F091RC] patch for tests-mbedmicro-rtos-mbed-threads
mbedtls trng - remove MBEDTLS_ENTROPY_HARDWARE_ALT
targets - add TRNG device_has to STM32F7 targets
mbedtls - move TRNG mbed impl into platform folder
TRNG HAL - fix length doc wording for get_bytes
HAL TRNG - add dummy variable to empty structs
TRNG - protect HAL implementation if DEVICE_TRNG is not defined
TRNG - remove set seed function
HAL - RNG rename to TRNG
HAL - rng nuvoton cleanup code style
RNG - fix warnings due to obj not used for some targets
RNG - rename rng_get_numbers to rng_get_bytes
mbedtls - mbed wrapper rename to mbed_rng
HAL: Add rng set seed value function
NUMAKER_PFM_NUC472: Add RGN HAL API implementation
...
# Conflicts:
# hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/serial_api.c
[XDOT_L151] copy new target CMSIS files from NZ32_SC151 target
[XDOT_L151] remove Modtronix code, add HardFault_Handler, update clock configuration to match xDot hardware
[XDOT_L151] copy new target HAL files from NZ32_SC151 target
[XDOT_L151] update HAL to match xDot hardware
[XDOT_L151] add xdot_eeprom.* and xdot_low_power.* files
[XDOT_L151] add RTOS support for target
Conflicts:
rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c
[XDOT_L151] match NUCLEO_L152RE startup code for GCC_ARM so RTOS works
[XDOT_L151] fix GPIO write failure
[XDOT_L151] add XDOT_L151CC target to targets.json
[XDOT_L151] change xDot default stack size to 256 bytes and main stack size to 1.5kB
[XDOT_L151] update PinNames.h to match rev E hardware - no change to external pinout
[XDOT_L151] update style in custom xDot HAL files
Conflicts:
rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h
rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c