summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-04-01 10:44:17 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2017-04-01 10:47:30 +0100
commitcc8d9a29e7cb24a43a10ec86a789efcf12394974 (patch)
tree81578e5447e8c1c13b79e5b886db67b1fba40df0 /src/win32
parentdcaa90991f0d14ba62c3749b47f6768bf7cdcfa6 (diff)
downloadlibgit2-cc8d9a29e7cb24a43a10ec86a789efcf12394974.tar.gz
win32: introduce `do_with_retries` macro
Provide a macro that will allow us to run a function with posix-like return values multiple times in a retry loop, with an optional cleanup function called between invocations.
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/posix_w32.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 14f30ebe5..1dd6bffd7 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -157,6 +157,27 @@ GIT_INLINE(void) set_errno(void)
}
}
+GIT_INLINE(bool) last_error_retryable(void)
+{
+ int os_error = GetLastError();
+
+ return (os_error == ERROR_SHARING_VIOLATION ||
+ os_error == ERROR_ACCESS_DENIED);
+}
+
+#define do_with_retries(fn, cleanup) \
+ do { \
+ int __tries, __ret; \
+ for (__tries = 0; __tries < 10; __tries++) { \
+ if (__tries && (__ret = (cleanup)) != 0) \
+ return __ret; \
+ if ((__ret = (fn)) != GIT_RETRY) \
+ return __ret; \
+ Sleep(5); \
+ } \
+ return -1; \
+ } while (0) \
+
/**
* Truncate or extend file.
*