Skip to content

Commit 8ad0318

Browse files
committed
fix reading time after date race
1 parent a3036e0 commit 8ad0318

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/STM32RTC.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,11 @@ time_t STM32RTC::getEpoch(uint32_t *subSeconds)
11091109
syncDate();
11101110
syncTime();
11111111

1112+
/* fix race condition where date may have changed between reading date and time */
1113+
if (_seconds == 0 && _minutes == 0 && _hours == 0) {
1114+
syncDate();
1115+
}
1116+
11121117
tm.tm_isdst = -1;
11131118
/*
11141119
* mktime ignores the values supplied by the caller in the

0 commit comments

Comments
 (0)