Skip to content

Commit 4b4d4ce

Browse files
authored
Merge pull request #424 from junliurs/feat/support-riscv64-epoll
feat: add riscv64 epoll support
1 parent 13398b1 commit 4b4d4ce

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎sys_epoll_linux_other.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//go:build linux && !arm64 && !amd64
15+
//go:build linux && !arm64 && !amd64 && !riscv64
1616

1717
package netpoll
1818

‎sys_epoll_linux_riscv64.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)