|
| 1 | +// Copyright 2022 CloudWeGo Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +//go:build linux && riscv64 |
| 16 | + |
| 17 | +package netpoll |
| 18 | + |
| 19 | +import ( |
| 20 | + "syscall" |
| 21 | + "unsafe" |
| 22 | +) |
| 23 | + |
| 24 | +// EpollWait implements epoll_wait. |
| 25 | +// riscv64 only provides SYS_EPOLL_PWAIT (no SYS_EPOLL_WAIT). |
| 26 | +func EpollWait(epfd int, events []epollevent, msec int) (n int, err error) { |
| 27 | + var r0 uintptr |
| 28 | + _p0 := unsafe.Pointer(&events[0]) |
| 29 | + if msec == 0 { |
| 30 | + // When timeout is 0 (non-blocking poll), use RawSyscall6 to avoid the overhead |
| 31 | + // of scheduler coordination (entersyscall/exitsyscall) since it won't block. |
| 32 | + r0, _, err = syscall.RawSyscall6(syscall.SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), 0, 0, 0) |
| 33 | + } else { |
| 34 | + r0, _, err = syscall.Syscall6(syscall.SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) |
| 35 | + } |
| 36 | + if err == syscall.Errno(0) { |
| 37 | + err = nil |
| 38 | + } |
| 39 | + return int(r0), err |
| 40 | +} |
0 commit comments