diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index f891ca7d5..d3b909f2f 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -1378,19 +1378,6 @@ BOOL CommCloseHandle(HANDLE handle) if (!CommIsHandled(handle)) return FALSE; - if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING) - { - ULONG WaitMask = 0; - DWORD BytesReturned = 0; - - /* ensures to gracefully stop the WAIT_ON_MASK's loop */ - if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask, sizeof(ULONG), NULL, - 0, &BytesReturned, NULL)) - { - CommLog_Print(WLOG_WARN, "failure to WAIT_ON_MASK's loop!"); - } - } - DeleteCriticalSection(&pComm->ReadLock); DeleteCriticalSection(&pComm->WriteLock); DeleteCriticalSection(&pComm->EventsLock); diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c index 8f4108001..e1125a0e3 100644 --- a/winpr/libwinpr/comm/comm_serial_sys.c +++ b/winpr/libwinpr/comm/comm_serial_sys.c @@ -1075,6 +1075,10 @@ static BOOL set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask) /* waiting the end of the pending wait_on_mask() */ while (is_wait_set(pComm)) Sleep(10); /* 10ms */ + + EnterCriticalSection(&pComm->EventsLock); + pComm->PendingEvents &= ~SERIAL_EV_WINPR_STOP; + LeaveCriticalSection(&pComm->EventsLock); } /* NB: ensure to leave the critical section before to return */ @@ -1473,8 +1477,6 @@ static BOOL wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask) if (pComm->PendingEvents & SERIAL_EV_WINPR_STOP) { - pComm->PendingEvents &= ~SERIAL_EV_WINPR_STOP; - /* pOutputMask must remain empty but should * not have been modified. *