mirror of
https://github.com/isar/libmdbx.git
synced 2025-11-21 03:48:55 +08:00
mdbx-windows: use timeouts instead of retries for file locking.
This commit is contained in:
@@ -9,32 +9,15 @@ static std::unordered_map<unsigned, HANDLE> events;
|
||||
static HANDLE hBarrierSemaphore, hBarrierEvent;
|
||||
static HANDLE hProgressActiveEvent, hProgressPassiveEvent;
|
||||
|
||||
static int waitstatus2errcode(DWORD result) {
|
||||
switch (result) {
|
||||
case WAIT_OBJECT_0:
|
||||
return MDBX_SUCCESS;
|
||||
case WAIT_FAILED:
|
||||
return GetLastError();
|
||||
case WAIT_ABANDONED:
|
||||
return ERROR_ABANDONED_WAIT_0;
|
||||
case WAIT_IO_COMPLETION:
|
||||
return ERROR_USER_APC;
|
||||
case WAIT_TIMEOUT:
|
||||
return ERROR_TIMEOUT;
|
||||
default:
|
||||
return ERROR_UNHANDLED_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_wait4barrier(void) {
|
||||
DWORD rc = WaitForSingleObject(hBarrierSemaphore, 0);
|
||||
switch (rc) {
|
||||
default:
|
||||
failure_perror("WaitForSingleObject(BarrierSemaphore)", waitstatus2errcode(rc));
|
||||
failure_perror("WaitForSingleObject(BarrierSemaphore)", osal_waitstatus2errcode(rc));
|
||||
case WAIT_OBJECT_0:
|
||||
rc = WaitForSingleObject(hBarrierEvent, INFINITE);
|
||||
if (rc != WAIT_OBJECT_0)
|
||||
failure_perror("WaitForSingleObject(BarrierEvent)", waitstatus2errcode(rc));
|
||||
failure_perror("WaitForSingleObject(BarrierEvent)", osal_waitstatus2errcode(rc));
|
||||
break;
|
||||
case WAIT_TIMEOUT:
|
||||
if (!SetEvent(hBarrierEvent))
|
||||
@@ -95,7 +78,7 @@ void osal_broadcast(unsigned id) {
|
||||
int osal_waitfor(unsigned id) {
|
||||
log_trace("osal_waitfor: event %u", id);
|
||||
DWORD rc = WaitForSingleObject(events.at(id), INFINITE);
|
||||
return waitstatus2errcode(rc);
|
||||
return osal_waitstatus2errcode(rc);
|
||||
}
|
||||
|
||||
int osal_delay(unsigned seconds) {
|
||||
@@ -397,7 +380,7 @@ int osal_actor_poll(mdbx_pid_t &pid, unsigned timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return waitstatus2errcode(rc);
|
||||
return osal_waitstatus2errcode(rc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +401,7 @@ void osal_udelay(size_t us) {
|
||||
if (us > threshold_us && us > 1000) {
|
||||
DWORD rc = SleepEx(unsigned(us / 1000), TRUE);
|
||||
if (rc)
|
||||
failure_perror("SleepEx()", waitstatus2errcode(rc));
|
||||
failure_perror("SleepEx()", osal_waitstatus2errcode(rc));
|
||||
us = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user