Commit Graph

9 Commits (d92d75e9acc9ddec9b42775ae511a12acdc683a0)

Author SHA1 Message Date
Lingkai Dong 48cf1c9c80 rtos: Thread: Make stack allocation failure runtime catchable
When a Thread object's stack memory is not provided, its `start()`
member function dynamically allocates its stack from the heap. If
allocation fails, there is no way to catch it because
* `std::nothrow` is missing after the `new` keyword. As Mbed OS
is built with `-fno-exceptions` (C++ exceptions disabled), failed
allocation results in an unrecoverable fault.
* The attempted `nullptr` check, which doesn't work anyway due to
the first point, is an assertion instead of error returning.
Assertions should be used as a development tool to ensure code
behaves correctly. But out-of-memory is a completely valid runtime
situation.

This commit adds the missing `std::nothrow`, and makes `Thread::start()`
return `osErrorNoMemory` if allocation fails so the caller can handle
it.

Note: A case when a thread should never fail due to lack of memory
is the main thread. But the main thread's stack is a pre-allocated
array in the static memory, passed to the `Thread()` constructor
during thread creation, so it's not impacted by this change.
2021-09-08 14:17:58 +01:00
Lingkai Dong 3a24305916 rtos: Remove UNITTEST macro from rtos
Production code should not contain any test-specific checks. Rather
than checking `UNITTEST`, unit tests can directly set
`MBED_CONF_RTOS_PRESENT=1` to make RTOS available for testing.

Note: The cellular ATHandler test also has `MBED_CONF_RTOS_PRESENT=1`
added because `ATHandler.cpp` contains a check of this variable.
2021-07-06 16:50:49 +01:00
Kevin Bracey 537bee9f4c Better document MemoryPool behaviour
Make explicit that `MemoryPool` is a raw allocator, and users need to
take care of object construction and destruction.
2021-04-13 14:37:47 +03:00
pea-pod 507181d262 Change MBED_STATIC_ASSERTs version for built-in 2020-10-27 08:30:40 -05:00
Martin Kojtal a6ce2c53a0 platform: move internal headers to internal/
They belong to internal folder to follow our guideline, not in source as they were.
2020-08-20 08:58:00 +01:00
George Beckstein e77cdffbaa Include mbed_assert.h in Queue 2020-07-30 11:23:24 -04:00
Evelyne Donnaes 0dd6b195d7 Fixed doxygen comment 2020-07-20 17:40:41 +01:00
Ashok Rao 04fac35252 Incorporating reveiw comments - Moving mbed_rtos_types.h to public headers 2020-07-15 13:54:52 +01:00
Ashok Rao 3a1b0744ba Moving around a few items within \rtos 2020-07-09 15:57:29 +01:00