mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-27 04:55:53 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user