aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-06-23 11:36:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-06-23 11:36:26 +0200
commite4b8bb208d74af08666d80ff94ddb5fe8c1433e5 (patch)
tree79b6f98229905ddeba8842872af41dfc26197497
parentfd4ec99398e6d2e495634065141df52c25f4ae67 (diff)
Tune Windows fdselect() implementation
-rw-r--r--libbutl/fdstream.cxx10
1 files changed, 8 insertions, 2 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx
index 18f611f..8098e50 100644
--- a/libbutl/fdstream.cxx
+++ b/libbutl/fdstream.cxx
@@ -34,6 +34,7 @@
# include <wchar.h> // wcsncmp(), wcsstr()
+# include <thread> // this_thread::yield()
# include <algorithm> // count()
#endif
@@ -2064,7 +2065,9 @@ namespace butl
// Use exponential backoff but not too aggressive and with 25ms max.
//
- DWORD t (static_cast<DWORD> (i >= 100 ? 25 : 1 + (i / 4)));
+ DWORD t (
+ static_cast<DWORD> (i <= 1000 ? 0 :
+ i >= 1000 + 100 ? 25 : 1 + ((i - 1000) / 4)));
if (timeout)
{
@@ -2081,7 +2084,10 @@ namespace butl
break;
}
- Sleep (t);
+ if (t == 0)
+ this_thread::yield ();
+ else
+ Sleep (t);
}
return make_pair (r, 0);