newlib: revert back from spinlocks to using newlib locks for time.h

Spinlocks from spinlock.h do not disable the scheduler and thus cannot safely
be directly used as a locking mechanism. A task holding the lock can get
pre-empted, and at that point the new running task will also be allowed to
take the spinlock and access whatever it was protecting.

Another issue is that the task holding a spinlock could migrate to a different
core which in turn would cause the application to fail asserts. The current
implementation assumes the core that takes the lock is also the core that
releases it.

Closes https://github.com/espressif/esp-idf/issues/5762
This commit is contained in:
Marius Vikhammer
2020-08-24 11:33:57 +08:00
parent 8a9dc46b14
commit 6fb996b1ac
3 changed files with 19 additions and 25 deletions

View File

@@ -15,9 +15,10 @@
#include "esp_system.h"
#include "esp_attr.h"
#include "soc/spinlock.h"
#include "soc/rtc.h"
#include "freertos/FreeRTOS.h"
#include "sdkconfig.h"
#if CONFIG_IDF_TARGET_ESP32
@@ -33,10 +34,7 @@
int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
{
int64_t t = 0;
static spinlock_t s_time_lock = SPINLOCK_INITIALIZER;
spinlock_acquire(&s_time_lock, SPINLOCK_WAIT_FOREVER);
t = (esp_rtc_get_time_us() - g_startup_time);
spinlock_release(&s_time_lock);
t = (esp_rtc_get_time_us() - g_startup_time);
return t;
}