-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathIORing+Util.swift
More file actions
79 lines (71 loc) · 2.26 KB
/
Copy pathIORing+Util.swift
File metadata and controls
79 lines (71 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
This source file is part of the Swift System open source project
Copyright (c) 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
*/
#if compiler(>=6.2) && $Lifetimes
#if os(Linux)
internal import CSystem
#if canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif
/// Throwing wrapper around the `io_uring_enter2` shim.
///
/// On success returns the syscall's non-negative result (the number of SQEs
/// consumed by the kernel). On failure, reads `errno` and throws the matching
/// `Errno`. `EINTR` is retried automatically.
@usableFromInline
internal func _ioUringEnter2(
ringDescriptor: Int32,
toSubmit: UInt32,
minComplete: UInt32,
flags: UInt32,
args: UnsafeMutablePointer<swift_io_uring_getevents_arg>?,
argsSize: Int
) throws(Errno) -> Int32 {
let result = valueOrErrno(retryOnInterrupt: true) {
io_uring_enter2(
ringDescriptor, toSubmit, minComplete, flags, args, argsSize
)
}
return try result.get()
}
/// Throwing wrapper around the `io_uring_enter` shim.
///
/// On success returns the syscall's non-negative result (the number of SQEs
/// consumed by the kernel). On failure, reads `errno` and throws the matching
/// `Errno`. `EINTR` is retried automatically.
@usableFromInline
internal func _ioUringEnter(
ringDescriptor: Int32,
toSubmit: UInt32,
minComplete: UInt32,
flags: UInt32,
sig: UnsafeMutablePointer<sigset_t>?
) throws(Errno) -> Int32 {
let result = valueOrErrno(retryOnInterrupt: true) {
io_uring_enter(ringDescriptor, toSubmit, minComplete, flags, sig)
}
return try result.get()
}
/// Throwing wrapper around the `io_uring_register` shim.
///
/// On success returns the syscall's non-negative result. On failure, reads
/// `errno` and throws the matching `Errno`. `EINTR` is retried automatically.
@usableFromInline
internal func _ioUringRegister(
ringDescriptor: Int32,
opcode: UInt32,
arg: UnsafeMutableRawPointer?,
nrArgs: UInt32
) throws(Errno) -> Int32 {
let result = valueOrErrno(retryOnInterrupt: true) {
io_uring_register(ringDescriptor, opcode, arg, nrArgs)
}
return try result.get()
}
#endif // os(Linux)
#endif // compiler(>=6.2) && $Lifetimes