Merge remote-tracking branch 'upstream-public/pr/1328' into development
diff --git a/ChangeLog b/ChangeLog
index c87c146..8447365 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -108,7 +108,7 @@
* Fix incorrect unit in benchmark output. #850
* Fix crash when calling mbedtls_ssl_cache_free() twice. Found by
MilenkoMitrovic, #1104
- * Fix mbedtls_timing_alarm(0) on Unix.
+ * Fix mbedtls_timing_alarm(0) on Unix and MinGW.
* Fix use of uninitialized memory in mbedtls_timing_get_timer when reset=1.
* Fix possible memory leaks in mbedtls_gcm_self_test().
* Added missing return code checks in mbedtls_aes_self_test().
diff --git a/library/timing.c b/library/timing.c
index 6df137d..35d6d89 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -278,6 +278,14 @@
{
DWORD ThreadId;
+ if( seconds == 0 )
+ {
+ /* No need to create a thread for this simple case.
+ * Also, this shorcut is more reliable at least on MinGW32 */
+ mbedtls_timing_alarmed = 1;
+ return;
+ }
+
mbedtls_timing_alarmed = 0;
alarmMs = seconds * 1000;
CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) );