mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-16 00:43:00 +03:00
use a scheduled function for settimeofday_cb (#6600)
* use a scheduled function for settimeofday_cb * per review * use a generic and clear name for trivial functional variable type name used for callbacks
This commit is contained in:
@ -17,7 +17,6 @@ extern bool timeshift64_is_set;
|
||||
void esp_yield();
|
||||
void esp_schedule();
|
||||
void tune_timeshift64 (uint64_t now_us);
|
||||
void settimeofday_cb (void (*cb)(void));
|
||||
void disable_extra4k_at_link_time (void) __attribute__((noinline));
|
||||
|
||||
uint32_t sqrt32 (uint32_t n);
|
||||
@ -25,6 +24,14 @@ uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#include <functional>
|
||||
|
||||
using TrivialCB = std::function<void()>;
|
||||
|
||||
void settimeofday_cb (TrivialCB&& cb);
|
||||
void settimeofday_cb (const TrivialCB& cb);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __COREDECLS_H
|
||||
|
@ -42,16 +42,22 @@
|
||||
#include <osapi.h>
|
||||
#include <os_type.h>
|
||||
#include "coredecls.h"
|
||||
#include "Schedule.h"
|
||||
|
||||
extern "C" {
|
||||
static TrivialCB _settimeofday_cb;
|
||||
|
||||
static void (*_settimeofday_cb)(void) = NULL;
|
||||
void settimeofday_cb (TrivialCB&& cb)
|
||||
{
|
||||
_settimeofday_cb = std::move(cb);
|
||||
}
|
||||
|
||||
void settimeofday_cb (void (*cb)(void))
|
||||
void settimeofday_cb (const TrivialCB& cb)
|
||||
{
|
||||
_settimeofday_cb = cb;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
|
||||
#include <pgmspace.h>
|
||||
@ -478,7 +484,7 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
|
||||
sntp_set_system_time(tv->tv_sec);
|
||||
|
||||
if (_settimeofday_cb)
|
||||
_settimeofday_cb();
|
||||
schedule_function(_settimeofday_cb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user