aboutsummaryrefslogtreecommitdiff
path: root/libbutl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-06-22 11:16:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-06-22 11:16:21 +0200
commitc3bb3da52c81abcde83cb72e90b1b61f0627f580 (patch)
tree178104e4a54e6adf54bb6643000474d83dca2d44 /libbutl
parentd58bb311ba5b981132f7b666a8ec0ecfeec6fd75 (diff)
Half Windows sleep times, use exponential backoff in fdselect()
Diffstat (limited to 'libbutl')
-rw-r--r--libbutl/fdstream.cxx12
-rw-r--r--libbutl/filesystem.cxx10
2 files changed, 12 insertions, 10 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx
index 5a0c479..e29bb50 100644
--- a/libbutl/fdstream.cxx
+++ b/libbutl/fdstream.cxx
@@ -1164,12 +1164,12 @@ namespace butl
// open it results in EINVAL POSIX error, ERROR_USER_MAPPED_FILE system
// error. So we retry those as well.
//
- for (size_t i (0); i < 21; ++i)
+ for (size_t i (0); i < 41; ++i)
{
- // Sleep 100 milliseconds before the open retry.
+ // Sleep 50 milliseconds before the open retry.
//
if (i != 0)
- Sleep (100);
+ Sleep (50);
fd = pass_perm
? _sopen (f, of, _SH_DENYNO, pf)
@@ -1989,7 +1989,7 @@ namespace butl
//
size_t r (0);
- while (true)
+ for (size_t i (0);; ++i)
{
for (fdselect_state& s: read)
{
@@ -2062,7 +2062,9 @@ namespace butl
if (r != 0)
break;
- DWORD t (50);
+ // Use exponential backoff but not too aggressive and with 25ms max.
+ //
+ DWORD t (i >= 100 ? 25 : 1 + (i / 4));
if (timeout)
{
diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx
index 07d0590..28a0de8 100644
--- a/libbutl/filesystem.cxx
+++ b/libbutl/filesystem.cxx
@@ -1142,12 +1142,12 @@ namespace butl
// failure (see mventry() for details). If that's the case, we will keep
// trying to move the file for two seconds.
//
- for (size_t i (0); i < 21; ++i)
+ for (size_t i (0); i < 41; ++i)
{
- // Sleep 100 milliseconds before the removal retry.
+ // Sleep 50 milliseconds before the removal retry.
//
if (i != 0)
- Sleep (100);
+ Sleep (50);
ur = _unlink (f);
@@ -1792,12 +1792,12 @@ namespace butl
// fdopen().
//
DWORD ec;
- for (size_t i (0); i < 21; ++i)
+ for (size_t i (0); i < 41; ++i)
{
// Sleep 100 milliseconds before the move retry.
//
if (i != 0)
- Sleep (100);
+ Sleep (50);
if (MoveFileExA (f, t, mfl))
return;