From e37f4b2ccbca9ba0e2df34215b6f869c60353564 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 25 Sep 2017 19:18:13 +0200 Subject: [PATCH] port: make ep_port_wait() thread-safe --- src/port.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/port.c b/src/port.c index e9b188e..a0f997a 100644 --- a/src/port.c +++ b/src/port.c @@ -143,6 +143,8 @@ static int _ep_port_poll(ep_port_t* port_info, if (_ep_port_update_events(port_info) < 0) return -1; + LeaveCriticalSection(&port_info->lock); + BOOL r = GetQueuedCompletionStatusEx(port_info->iocp, iocp_events, maxevents, @@ -150,6 +152,8 @@ static int _ep_port_poll(ep_port_t* port_info, timeout, FALSE); + EnterCriticalSection(&port_info->lock); + if (!r) return_error(-1); @@ -187,6 +191,8 @@ int ep_port_wait(ep_port_t* port_info, gqcs_timeout = INFINITE; } + EnterCriticalSection(&port_info->lock); + /* Dequeue completion packets until either at least one interesting event * has been discovered, or the timeout is reached. */ @@ -211,6 +217,8 @@ int ep_port_wait(ep_port_t* port_info, gqcs_timeout = (DWORD)(due - now); } while (gqcs_timeout > 0); + LeaveCriticalSection(&port_info->lock); + if (result >= 0) return result; else if (GetLastError() == WAIT_TIMEOUT)