[c402739f] | 1 | #!python3 |
---|
| 2 | # |
---|
| 3 | # Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo |
---|
| 4 | # |
---|
| 5 | # The contents of this file are covered under the licence agreement in the |
---|
| 6 | # file "LICENCE" distributed with Cforall. |
---|
| 7 | # |
---|
| 8 | # call.cfa.in -- Python script to generate io/call.cfa |
---|
| 9 | # |
---|
| 10 | # Author : Thierry Delisle |
---|
| 11 | # Created On : Fri Sep 11 12:41:16 2020 |
---|
| 12 | # Last Modified By : |
---|
| 13 | # Last Modified On : |
---|
| 14 | # Update Count : |
---|
| 15 | # |
---|
| 16 | |
---|
| 17 | Header = """// |
---|
| 18 | // Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo |
---|
| 19 | // |
---|
| 20 | // The contents of this file are covered under the licence agreement in the |
---|
| 21 | // file "LICENCE" distributed with Cforall. |
---|
| 22 | // |
---|
| 23 | // call.cfa -- Api for cforall |
---|
| 24 | // |
---|
| 25 | // Author : Generated from call.cfa.in |
---|
| 26 | // Created On : {} |
---|
| 27 | // |
---|
| 28 | |
---|
| 29 | """ |
---|
| 30 | |
---|
| 31 | Prelude = """#define __cforall_thread__ |
---|
| 32 | |
---|
| 33 | #include "bits/defs.hfa" |
---|
| 34 | #include "kernel.hfa" |
---|
[0e52f14] | 35 | #include "io/types.hfa" |
---|
[c402739f] | 36 | |
---|
| 37 | //============================================================================================= |
---|
| 38 | // I/O uring backend |
---|
| 39 | //============================================================================================= |
---|
| 40 | |
---|
| 41 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
| 42 | #include <assert.h> |
---|
| 43 | #include <stdint.h> |
---|
| 44 | #include <errno.h> |
---|
| 45 | #include <linux/io_uring.h> |
---|
| 46 | |
---|
| 47 | #include "kernel/fwd.hfa" |
---|
| 48 | |
---|
[290553a] | 49 | static const __u8 REGULAR_FLAGS = 0 |
---|
| 50 | #if defined(CFA_HAVE_IOSQE_FIXED_FILE) |
---|
| 51 | | IOSQE_FIXED_FILE |
---|
| 52 | #endif |
---|
| 53 | #if defined(CFA_HAVE_IOSQE_IO_DRAIN) |
---|
| 54 | | IOSQE_IO_DRAIN |
---|
| 55 | #endif |
---|
| 56 | #if defined(CFA_HAVE_IOSQE_ASYNC) |
---|
| 57 | | IOSQE_ASYNC |
---|
| 58 | #endif |
---|
| 59 | ; |
---|
[c402739f] | 60 | |
---|
[290553a] | 61 | static const __u32 LINK_FLAGS = 0 |
---|
| 62 | #if defined(CFA_HAVE_IOSQE_IO_LINK) |
---|
| 63 | | IOSQE_IO_LINK |
---|
| 64 | #endif |
---|
| 65 | #if defined(CFA_HAVE_IOSQE_IO_HARDLINK) |
---|
| 66 | | IOSQE_IO_HARDLINK |
---|
| 67 | #endif |
---|
| 68 | ; |
---|
[c402739f] | 69 | |
---|
[290553a] | 70 | static const __u32 SPLICE_FLAGS = 0 |
---|
| 71 | #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED) |
---|
| 72 | | SPLICE_F_FD_IN_FIXED |
---|
| 73 | #endif |
---|
| 74 | ; |
---|
[c402739f] | 75 | |
---|
| 76 | extern [* struct io_uring_sqe, __u32] __submit_alloc( struct __io_data & ring, __u64 data ); |
---|
| 77 | extern void __submit( struct io_context * ctx, __u32 idx ) __attribute__((nonnull (1))); |
---|
| 78 | |
---|
| 79 | static inline io_context * __get_io_context( void ) { |
---|
| 80 | cluster * cltr = active_cluster(); |
---|
| 81 | |
---|
| 82 | /* paranoid */ verifyf( cltr, "No active cluster for io operation\\n"); |
---|
| 83 | assertf( cltr->io.cnt > 0, "Cluster %p has no default io contexts and no context was specified\\n", cltr ); |
---|
| 84 | |
---|
| 85 | /* paranoid */ verifyf( cltr->io.ctxs, "default io contexts for cluster %p are missing\\n", cltr); |
---|
[fe9468e2] | 86 | return &cltr->io.ctxs[ thread_rand() % cltr->io.cnt ]; |
---|
[c402739f] | 87 | } |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | //============================================================================================= |
---|
| 91 | // I/O Forwards |
---|
| 92 | //============================================================================================= |
---|
| 93 | #include <time.hfa> |
---|
| 94 | |
---|
| 95 | // Some forward declarations |
---|
| 96 | #include <errno.h> |
---|
| 97 | #include <unistd.h> |
---|
| 98 | |
---|
| 99 | extern "C" { |
---|
| 100 | #include <sys/types.h> |
---|
| 101 | #include <sys/socket.h> |
---|
| 102 | #include <sys/syscall.h> |
---|
| 103 | |
---|
[ace2e92] | 104 | #if defined(CFA_HAVE_PREADV2) |
---|
[c402739f] | 105 | struct iovec; |
---|
| 106 | extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
---|
| 107 | #endif |
---|
[ace2e92] | 108 | #if defined(CFA_HAVE_PWRITEV2) |
---|
[c402739f] | 109 | struct iovec; |
---|
| 110 | extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
---|
| 111 | #endif |
---|
| 112 | |
---|
| 113 | extern int fsync(int fd); |
---|
| 114 | |
---|
| 115 | #if __OFF_T_MATCHES_OFF64_T |
---|
| 116 | typedef __off64_t off_t; |
---|
| 117 | #else |
---|
| 118 | typedef __off_t off_t; |
---|
| 119 | #endif |
---|
| 120 | typedef __off64_t off64_t; |
---|
| 121 | extern int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags); |
---|
| 122 | |
---|
| 123 | struct msghdr; |
---|
| 124 | struct sockaddr; |
---|
| 125 | extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); |
---|
| 126 | extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); |
---|
| 127 | extern ssize_t send(int sockfd, const void *buf, size_t len, int flags); |
---|
| 128 | extern ssize_t recv(int sockfd, void *buf, size_t len, int flags); |
---|
| 129 | extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); |
---|
| 130 | extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
---|
| 131 | |
---|
| 132 | extern int fallocate(int fd, int mode, off_t offset, off_t len); |
---|
| 133 | extern int posix_fadvise(int fd, off_t offset, off_t len, int advice); |
---|
| 134 | extern int madvise(void *addr, size_t length, int advice); |
---|
| 135 | |
---|
| 136 | extern int openat(int dirfd, const char *pathname, int flags, mode_t mode); |
---|
| 137 | extern int close(int fd); |
---|
| 138 | |
---|
| 139 | extern ssize_t read (int fd, void *buf, size_t count); |
---|
| 140 | |
---|
| 141 | struct epoll_event; |
---|
| 142 | extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); |
---|
| 143 | |
---|
| 144 | extern ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags); |
---|
| 145 | extern ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | //============================================================================================= |
---|
| 149 | // I/O Interface |
---|
| 150 | //============================================================================================= |
---|
| 151 | """ |
---|
| 152 | |
---|
| 153 | print(Header.format("A Date")) |
---|
| 154 | print(Prelude) |
---|
| 155 | |
---|
| 156 | import re |
---|
| 157 | import sys |
---|
| 158 | class Call: |
---|
| 159 | def __init__(self, op, signature, body, define=None): |
---|
| 160 | sig = re.search("(.*) (.*)\((.*)\)", signature) |
---|
| 161 | if not sig: |
---|
| 162 | print("OP '{}' has invalid signature {}".format(op, signature), file=sys.stderr) |
---|
| 163 | sys.exit(1) |
---|
| 164 | |
---|
| 165 | self.op = op |
---|
| 166 | self.ret = sig.group(1) |
---|
| 167 | self.name = sig.group(2) |
---|
| 168 | self.params = sig.group(3) |
---|
| 169 | self.define = define |
---|
| 170 | self.body = "" |
---|
| 171 | |
---|
| 172 | accepted_keys = [ 'ioprio', 'fd', 'off', 'addr2','addr', 'splice_off_in','len', |
---|
| 173 | 'rw_flags', 'fsync_flags', 'poll_events', 'poll32_events', |
---|
| 174 | 'sync_range_flags', 'msg_flags', 'timeout_flags', 'accept_flags', |
---|
| 175 | 'cancel_flags', 'open_flags', 'statx_flags', 'fadvise_advice', |
---|
| 176 | 'splice_flags', 'buf_index' ,'buf_group' 'personality', |
---|
| 177 | 'splice_fd_in' ] |
---|
| 178 | |
---|
| 179 | for k, v in body.items(): |
---|
| 180 | if not k in accepted_keys: |
---|
| 181 | print("OP '{}' has invalid body kew {}".format(op, k), file=sys.stderr) |
---|
| 182 | sys.exit(1) |
---|
| 183 | |
---|
| 184 | self.body += "\n sqe->{key} = {value};".format(key=k, value=v) |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | def args(self): |
---|
| 188 | param_a = self.params.split(',') |
---|
| 189 | args_a = [p.replace('*', ' ').split()[-1] for p in param_a] |
---|
| 190 | for a in args_a: |
---|
| 191 | if '*' in a: |
---|
| 192 | print("OP '{}' has invalid * in argument {}".format(self.op, a), file=sys.stderr) |
---|
| 193 | sys.exit(1) |
---|
| 194 | |
---|
| 195 | return ', '.join(args_a) |
---|
| 196 | |
---|
| 197 | AsyncTemplate = """inline void async_{name}(io_future_t & future, {params}, int submit_flags, io_cancellation * cancellation, io_context * context) {{ |
---|
| 198 | #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 199 | ssize_t res = {name}({args}); |
---|
| 200 | if (res >= 0) {{ |
---|
| 201 | fulfil(future, res); |
---|
| 202 | }} |
---|
| 203 | else {{ |
---|
| 204 | fulfil(future, -errno); |
---|
| 205 | }} |
---|
| 206 | #else |
---|
| 207 | // we don't support LINK yet |
---|
| 208 | if( 0 != (submit_flags & LINK_FLAGS) ) {{ |
---|
| 209 | errno = ENOTSUP; return -1; |
---|
| 210 | }} |
---|
| 211 | |
---|
| 212 | if( !context ) {{ |
---|
| 213 | context = __get_io_context(); |
---|
| 214 | }} |
---|
| 215 | if(cancellation) {{ |
---|
| 216 | cancellation->target = (__u64)(uintptr_t)&future; |
---|
| 217 | }} |
---|
| 218 | |
---|
| 219 | __u8 sflags = REGULAR_FLAGS & submit_flags; |
---|
| 220 | struct __io_data & ring = *context->thrd.ring; |
---|
| 221 | |
---|
| 222 | __u32 idx; |
---|
| 223 | struct io_uring_sqe * sqe; |
---|
| 224 | [sqe, idx] = __submit_alloc( ring, (__u64)(uintptr_t)&future ); |
---|
| 225 | |
---|
| 226 | sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0; |
---|
| 227 | sqe->opcode = IORING_OP_{op}; |
---|
| 228 | sqe->flags = sflags;{body} |
---|
| 229 | |
---|
| 230 | verify( sqe->user_data == (__u64)(uintptr_t)&future ); |
---|
| 231 | __submit( context, idx ); |
---|
| 232 | #endif |
---|
| 233 | }}""" |
---|
| 234 | |
---|
| 235 | SyncTemplate = """{ret} cfa_{name}({params}, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {{ |
---|
| 236 | if( timeout >= 0 ) {{ |
---|
| 237 | errno = ENOTSUP; |
---|
| 238 | return -1; |
---|
| 239 | }} |
---|
| 240 | io_future_t future; |
---|
| 241 | |
---|
| 242 | async_{name}( future, {args}, submit_flags, cancellation, context ); |
---|
| 243 | |
---|
| 244 | wait( future ); |
---|
| 245 | if( future.result < 0 ) {{ |
---|
| 246 | errno = -future.result; |
---|
| 247 | return -1; |
---|
| 248 | }} |
---|
| 249 | return future.result; |
---|
| 250 | }}""" |
---|
| 251 | |
---|
| 252 | calls = [ |
---|
| 253 | # CFA_HAVE_IORING_OP_READV |
---|
| 254 | Call('READV', 'ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags)', { |
---|
| 255 | 'fd' : 'fd', |
---|
| 256 | 'off' : 'offset', |
---|
| 257 | 'addr': '(__u64)iov', |
---|
| 258 | 'len' : 'iovcnt', |
---|
| 259 | }, define = 'CFA_HAVE_PREADV2'), |
---|
| 260 | # CFA_HAVE_IORING_OP_WRITEV |
---|
| 261 | Call('WRITEV', 'ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags)', { |
---|
| 262 | 'fd' : 'fd', |
---|
| 263 | 'off' : 'offset', |
---|
| 264 | 'addr': '(__u64)iov', |
---|
| 265 | 'len' : 'iovcnt' |
---|
| 266 | }, define = 'CFA_HAVE_PWRITEV2'), |
---|
| 267 | # CFA_HAVE_IORING_OP_FSYNC |
---|
| 268 | Call('FSYNC', 'int fsync(int fd)', { |
---|
| 269 | 'fd': 'fd' |
---|
| 270 | }), |
---|
| 271 | # CFA_HAVE_IORING_OP_EPOLL_CTL |
---|
| 272 | Call('EPOLL_CTL', 'int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)', { |
---|
| 273 | 'fd': 'epfd', |
---|
| 274 | 'addr': 'fd', |
---|
| 275 | 'len': 'op', |
---|
| 276 | 'off': '(__u64)event' |
---|
| 277 | }), |
---|
| 278 | # CFA_HAVE_IORING_OP_SYNC_FILE_RANGE |
---|
| 279 | Call('SYNC_FILE_RANGE', 'int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)', { |
---|
| 280 | 'fd': 'fd', |
---|
| 281 | 'off': 'offset', |
---|
| 282 | 'len': 'nbytes', |
---|
| 283 | 'sync_range_flags': 'flags' |
---|
| 284 | }), |
---|
| 285 | # CFA_HAVE_IORING_OP_SENDMSG |
---|
| 286 | Call('SENDMSG', 'ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)', { |
---|
| 287 | 'fd': 'sockfd', |
---|
| 288 | 'addr': '(__u64)(struct msghdr *)msg', |
---|
| 289 | 'len': '1', |
---|
| 290 | 'msg_flags': 'flags' |
---|
| 291 | }), |
---|
| 292 | # CFA_HAVE_IORING_OP_RECVMSG |
---|
| 293 | Call('RECVMSG', 'ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)', { |
---|
| 294 | 'fd': 'sockfd', |
---|
| 295 | 'addr': '(__u64)(struct msghdr *)msg', |
---|
| 296 | 'len': '1', |
---|
| 297 | 'msg_flags': 'flags' |
---|
| 298 | }), |
---|
| 299 | # CFA_HAVE_IORING_OP_SEND |
---|
| 300 | Call('SEND', 'ssize_t send(int sockfd, const void *buf, size_t len, int flags)', { |
---|
| 301 | 'fd': 'sockfd', |
---|
[4ab3cf9b] | 302 | 'addr': '(__u64)buf', |
---|
[c402739f] | 303 | 'len': 'len', |
---|
| 304 | 'msg_flags': 'flags' |
---|
| 305 | }), |
---|
| 306 | # CFA_HAVE_IORING_OP_RECV |
---|
| 307 | Call('RECV', 'ssize_t recv(int sockfd, void *buf, size_t len, int flags)', { |
---|
| 308 | 'fd': 'sockfd', |
---|
[4ab3cf9b] | 309 | 'addr': '(__u64)buf', |
---|
[c402739f] | 310 | 'len': 'len', |
---|
| 311 | 'msg_flags': 'flags' |
---|
| 312 | }), |
---|
| 313 | # CFA_HAVE_IORING_OP_ACCEPT |
---|
| 314 | Call('ACCEPT4', 'int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)', { |
---|
| 315 | 'fd': 'sockfd', |
---|
| 316 | 'addr': 'addr', |
---|
| 317 | 'addr2': 'addrlen', |
---|
| 318 | 'accept_flags': 'flags' |
---|
| 319 | }), |
---|
| 320 | # CFA_HAVE_IORING_OP_CONNECT |
---|
| 321 | Call('CONNECT', 'int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)', { |
---|
| 322 | 'fd': 'sockfd', |
---|
[4ab3cf9b] | 323 | 'addr': '(__u64)addr', |
---|
[c402739f] | 324 | 'off': 'addrlen' |
---|
| 325 | }), |
---|
| 326 | # CFA_HAVE_IORING_OP_FALLOCATE |
---|
| 327 | Call('FALLOCATE', 'int fallocate(int fd, int mode, off_t offset, off_t len)', { |
---|
| 328 | 'fd': 'fd', |
---|
| 329 | 'addr': '(__u64)len', |
---|
| 330 | 'len': 'mode', |
---|
| 331 | 'off': 'offset' |
---|
| 332 | }), |
---|
| 333 | # CFA_HAVE_IORING_OP_FADVISE |
---|
| 334 | Call('FADVISE', 'int posix_fadvise(int fd, off_t offset, off_t len, int advice)', { |
---|
| 335 | 'fd': 'fd', |
---|
[4ab3cf9b] | 336 | 'off': 'offset', |
---|
[c402739f] | 337 | 'len': 'len', |
---|
| 338 | 'fadvise_advice': 'advice' |
---|
| 339 | }), |
---|
| 340 | # CFA_HAVE_IORING_OP_MADVISE |
---|
| 341 | Call('MADVISE', 'int madvise(void *addr, size_t length, int advice)', { |
---|
[eccb14d] | 342 | 'addr': '(__u64)addr', |
---|
[c402739f] | 343 | 'len': 'length', |
---|
| 344 | 'fadvise_advice': 'advice' |
---|
| 345 | }), |
---|
| 346 | # CFA_HAVE_IORING_OP_OPENAT |
---|
| 347 | Call('OPENAT', 'int openat(int dirfd, const char *pathname, int flags, mode_t mode)', { |
---|
| 348 | 'fd': 'dirfd', |
---|
| 349 | 'addr': '(__u64)pathname', |
---|
| 350 | 'len': 'mode', |
---|
| 351 | 'open_flags': 'flags;' |
---|
| 352 | }), |
---|
| 353 | # CFA_HAVE_IORING_OP_OPENAT2 |
---|
| 354 | Call('OPENAT2', 'int openat2(int dirfd, const char *pathname, struct open_how * how, size_t size)', { |
---|
| 355 | 'fd': 'dirfd', |
---|
| 356 | 'addr': 'pathname', |
---|
| 357 | 'len': 'sizeof(*how)', |
---|
| 358 | 'off': '(__u64)how', |
---|
| 359 | }, define = 'CFA_HAVE_OPENAT2'), |
---|
| 360 | # CFA_HAVE_IORING_OP_CLOSE |
---|
| 361 | Call('CLOSE', 'int close(int fd)', { |
---|
| 362 | 'fd': 'fd' |
---|
| 363 | }), |
---|
| 364 | # CFA_HAVE_IORING_OP_STATX |
---|
| 365 | Call('STATX', 'int statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf)', { |
---|
| 366 | 'fd': 'dirfd', |
---|
| 367 | 'off': '(__u64)statxbuf', |
---|
| 368 | 'addr': 'pathname', |
---|
| 369 | 'len': 'mask', |
---|
| 370 | 'statx_flags': 'flags' |
---|
| 371 | }, define = 'CFA_HAVE_STATX'), |
---|
| 372 | # CFA_HAVE_IORING_OP_READ |
---|
| 373 | Call('READ', 'ssize_t read(int fd, void * buf, size_t count)', { |
---|
| 374 | 'fd': 'fd', |
---|
[4ab3cf9b] | 375 | 'addr': '(__u64)buf', |
---|
[c402739f] | 376 | 'len': 'count' |
---|
| 377 | }), |
---|
| 378 | # CFA_HAVE_IORING_OP_WRITE |
---|
| 379 | Call('WRITE', 'ssize_t write(int fd, void * buf, size_t count)', { |
---|
| 380 | 'fd': 'fd', |
---|
[4ab3cf9b] | 381 | 'addr': '(__u64)buf', |
---|
[c402739f] | 382 | 'len': 'count' |
---|
| 383 | }), |
---|
| 384 | # CFA_HAVE_IORING_OP_SPLICE |
---|
| 385 | Call('SPLICE', 'ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags)', { |
---|
| 386 | 'splice_fd_in': 'fd_in', |
---|
[4ab3cf9b] | 387 | 'splice_off_in': 'off_in ? (__u64)*off_in : (__u64)-1', |
---|
[c402739f] | 388 | 'fd': 'fd_out', |
---|
[4ab3cf9b] | 389 | 'off': 'off_out ? (__u64)*off_out : (__u64)-1', |
---|
[c402739f] | 390 | 'len': 'len', |
---|
| 391 | 'splice_flags': 'flags' |
---|
| 392 | }), |
---|
| 393 | # CFA_HAVE_IORING_OP_TEE |
---|
| 394 | Call('TEE', 'ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags)', { |
---|
| 395 | 'splice_fd_in': 'fd_in', |
---|
| 396 | 'fd': 'fd_out', |
---|
| 397 | 'len': 'len', |
---|
| 398 | 'splice_flags': 'flags' |
---|
| 399 | }) |
---|
| 400 | ] |
---|
| 401 | |
---|
| 402 | print("//----------") |
---|
| 403 | print("// synchronous calls") |
---|
| 404 | for c in calls: |
---|
| 405 | if c.define: |
---|
| 406 | print("""#if defined({define}) |
---|
| 407 | {ret} cfa_{name}({params}, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context); |
---|
| 408 | #endif""".format(define=c.define,ret=c.ret, name=c.name, params=c.params)) |
---|
| 409 | else: |
---|
| 410 | print("{ret} cfa_{name}({params}, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context);" |
---|
| 411 | .format(ret=c.ret, name=c.name, params=c.params)) |
---|
| 412 | |
---|
| 413 | print("\n//----------") |
---|
| 414 | print("// asynchronous calls") |
---|
| 415 | for c in calls: |
---|
| 416 | if c.define: |
---|
| 417 | print("""#if defined({define}) |
---|
| 418 | void async_{name}(io_future_t & future, {params}, int submit_flags, io_cancellation * cancellation, io_context * context); |
---|
| 419 | #endif""".format(define=c.define,name=c.name, params=c.params)) |
---|
| 420 | else: |
---|
| 421 | print("void async_{name}(io_future_t & future, {params}, int submit_flags, io_cancellation * cancellation, io_context * context);" |
---|
| 422 | .format(name=c.name, params=c.params)) |
---|
| 423 | print("\n") |
---|
| 424 | |
---|
| 425 | for c in calls: |
---|
| 426 | print("//-----------------------------------------------------------------------------") |
---|
| 427 | print("// {}".format(c.name)) |
---|
| 428 | Async = AsyncTemplate.format( |
---|
| 429 | name = c.name, |
---|
| 430 | ret = c.ret, |
---|
| 431 | params = c.params, |
---|
| 432 | args = c.args(), |
---|
| 433 | op = c.op, |
---|
| 434 | body = c.body |
---|
| 435 | |
---|
| 436 | ) |
---|
| 437 | Sync = SyncTemplate.format( |
---|
| 438 | name = c.name, |
---|
| 439 | ret = c.ret, |
---|
| 440 | params = c.params, |
---|
| 441 | args = c.args() |
---|
| 442 | ) |
---|
| 443 | |
---|
| 444 | if c.define: |
---|
| 445 | print("""#if defined({}) |
---|
| 446 | //---------- |
---|
| 447 | // asynchronous call |
---|
| 448 | {} |
---|
| 449 | |
---|
| 450 | //---------- |
---|
| 451 | // synchronous call |
---|
| 452 | {} |
---|
| 453 | #endif |
---|
| 454 | """.format(c.define, "\n\t".join( Async.splitlines() ), "\n\t".join( Sync.splitlines() ))) |
---|
| 455 | else : |
---|
| 456 | print("""//---------- |
---|
| 457 | // asynchronous call |
---|
| 458 | {} |
---|
| 459 | |
---|
| 460 | //---------- |
---|
| 461 | // synchronous call |
---|
| 462 | {} |
---|
| 463 | """.format(Async, Sync)) |
---|
| 464 | |
---|
| 465 | print(""" |
---|
| 466 | //----------------------------------------------------------------------------- |
---|
| 467 | // Check if a function is has asynchronous |
---|
| 468 | bool has_user_level_blocking( fptr_t func ) { |
---|
| 469 | #if defined(CFA_HAVE_LINUX_IO_URING_H)""") |
---|
| 470 | |
---|
| 471 | for c in calls: |
---|
| 472 | if c.define: |
---|
| 473 | print(""" #if defined({define}) |
---|
| 474 | if( /*func == (fptr_t)preadv2 || */ |
---|
| 475 | func == (fptr_t)cfa_{name} || |
---|
| 476 | func == (fptr_t)async_{name} ) {{ |
---|
| 477 | #if defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 478 | return true; |
---|
| 479 | #else |
---|
| 480 | return false; |
---|
| 481 | #endif |
---|
| 482 | }} |
---|
| 483 | #endif""".format(define=c.define, name=c.name, op=c.op)) |
---|
| 484 | else: |
---|
| 485 | print(""" if( /*func == (fptr_t)preadv2 || */ |
---|
| 486 | func == (fptr_t)cfa_{name} || |
---|
| 487 | func == (fptr_t)async_{name} ) {{ |
---|
| 488 | #if defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 489 | return true; |
---|
| 490 | #else |
---|
| 491 | return false; |
---|
| 492 | #endif |
---|
| 493 | }}""".format(name=c.name, op=c.op)) |
---|
| 494 | |
---|
| 495 | print(""" #endif |
---|
| 496 | |
---|
| 497 | return false; |
---|
| 498 | }""") |
---|