1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-07 16:23:38 +03:00

using std::nothrow instead of malloc (#6251)

This commit is contained in:
david gauchard 2019-07-04 03:59:54 +02:00 committed by Develo
parent 6272e897ca
commit 3f35506684

View File

@ -45,15 +45,10 @@ static scheduled_fn_t* get_fn_unsafe ()
// if no unused items, and count not too high, allocate a new one // if no unused items, and count not too high, allocate a new one
else if (sCount < SCHEDULED_FN_MAX_COUNT) else if (sCount < SCHEDULED_FN_MAX_COUNT)
{ {
// calling malloc instead of new to avoid exception raising while in ISR result = new (std::nothrow) scheduled_fn_t;
// construct complex members in place (never raises exceptions)
result = (scheduled_fn_t*)malloc(sizeof(scheduled_fn_t));
if (result) if (result)
{
new (&result->mFunc) decltype(result->mFunc)();
++sCount; ++sCount;
} }
}
return result; return result;
} }
@ -91,7 +86,7 @@ bool schedule_recurrent_function_us (const std::function<bool(void)>& fn, uint32
esp8266::InterruptLock lockAllInterruptsInThisScope; esp8266::InterruptLock lockAllInterruptsInThisScope;
recurrent_fn_t* item = new recurrent_fn_t(repeat_us); recurrent_fn_t* item = new (std::nothrow) recurrent_fn_t(repeat_us);
if (!item) if (!item)
return false; return false;