diff options
| author | ruki <[email protected]> | 2026-08-23 14:59:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-23 14:59:19 +0800 |
| commit | 7ddecb012e558dacc0c9aae762c43c3c863a372c (patch) | |
| tree | fa7d7a3795f4f6bf6be8dcd4f805f471e68de191 /xmake/core | |
| parent | deaabcd162bebe9312201bcaac48404fd8a1925a (diff) | |
fix wait 0wait
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/fwatcher.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/pipe.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/process.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/scheduler.lua | 25 | ||||
| -rw-r--r-- | xmake/core/base/socket.lua | 2 |
5 files changed, 30 insertions, 5 deletions
diff --git a/xmake/core/base/fwatcher.lua b/xmake/core/base/fwatcher.lua index 9fc04722e..e05baa584 100644 --- a/xmake/core/base/fwatcher.lua +++ b/xmake/core/base/fwatcher.lua @@ -93,7 +93,7 @@ end -- wait event -- --- @param timeout the timeout +-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting -- -- @return ok, event, e.g {type = fwatcher.ET_MODIFY, path = "/tmp"} -- diff --git a/xmake/core/base/pipe.lua b/xmake/core/base/pipe.lua index 137f9c779..9a896afba 100644 --- a/xmake/core/base/pipe.lua +++ b/xmake/core/base/pipe.lua @@ -235,7 +235,7 @@ end -- wait pipe events -- -- @param events the events to wait, e.g. pipe.EV_READ, pipe.EV_WRITE --- @param timeout the timeout in milliseconds, -1 for infinite +-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting -- @return the received events, or 0 on timeout -- function _instance:wait(events, timeout) diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index 35b0b15b7..0c4c509b0 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -81,9 +81,9 @@ end -- wait subprocess -- --- @param timeout the timeout +-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting -- --- @return ok, status +-- @return ok, status, e.g. -1 on error, 0 on timeout, 1 on exited -- function _subprocess:wait(timeout) diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 4ae8d74e0..f936f1d8f 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -982,6 +982,15 @@ function scheduler:poller_wait(obj, events, timeout) end end + -- no events yet? return immediately if timeout is zero + -- + -- @note we save the waiting events, so the poller caches the events when they + -- arrive and the next wait returns them immediately + if timeout == 0 then + pollerdata.poller_events_wait = events_wait + return 0 + end + -- register timeout task to timer local timer_task = nil if timeout > 0 then @@ -1053,6 +1062,14 @@ function scheduler:poller_waitproc(obj, timeout) return -1, errors end + -- has not exited yet? return immediately if timeout is zero + -- + -- @note we have inserted it into the poller, so its exit status is still saved + -- as a pending status when it exits later, and the next wait returns it immediately + if timeout == 0 then + return 0 + end + -- register timeout task to timer local timer_task = nil if timeout > 0 then @@ -1123,6 +1140,14 @@ function scheduler:poller_waitfs(obj, timeout) return -1, errors end + -- no event yet? return immediately if timeout is zero + -- + -- @note we have inserted it into the poller, so the next event is still saved + -- as a pending status when it arrives, and the next wait returns it immediately + if timeout == 0 then + return 0 + end + -- register timeout task to timer local timer_task = nil if timeout > 0 then diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua index 393edd199..fbe1fea10 100644 --- a/xmake/core/base/socket.lua +++ b/xmake/core/base/socket.lua @@ -675,7 +675,7 @@ end -- wait for socket events -- -- @param events the events to wait, e.g. socket.EV_RECV, socket.EV_SEND --- @param timeout the timeout in milliseconds, -1 for infinite +-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting -- @return the received events, or 0 on timeout -- function _instance:wait(events, timeout) |
