• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <asyncio/AsyncIO.h>
18 #include <sys/syscall.h>
19 #include <unistd.h>
20 
io_setup(unsigned nr,aio_context_t * ctxp)21 int io_setup(unsigned nr, aio_context_t* ctxp) {
22     memset(ctxp, 0, sizeof(*ctxp));
23     return syscall(__NR_io_setup, nr, ctxp);
24 }
25 
io_destroy(aio_context_t ctx)26 int io_destroy(aio_context_t ctx) {
27     return syscall(__NR_io_destroy, ctx);
28 }
29 
io_submit(aio_context_t ctx,long nr,iocb ** iocbpp)30 int io_submit(aio_context_t ctx, long nr, iocb** iocbpp) {
31     return syscall(__NR_io_submit, ctx, nr, iocbpp);
32 }
33 
io_getevents(aio_context_t ctx,long min_nr,long max_nr,io_event * events,timespec * timeout)34 int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event* events, timespec* timeout) {
35     return syscall(__NR_io_getevents, ctx, min_nr, max_nr, events, timeout);
36 }
37 
io_cancel(aio_context_t ctx,iocb * iocbp,io_event * result)38 int io_cancel(aio_context_t ctx, iocb* iocbp, io_event* result) {
39     return syscall(__NR_io_cancel, ctx, iocbp, result);
40 }
41 
io_prep(iocb * iocb,int fd,const void * buf,uint64_t count,int64_t offset,bool read)42 void io_prep(iocb* iocb, int fd, const void* buf, uint64_t count, int64_t offset, bool read) {
43     memset(iocb, 0, sizeof(*iocb));
44     iocb->aio_fildes = fd;
45     iocb->aio_lio_opcode = read ? IOCB_CMD_PREAD : IOCB_CMD_PWRITE;
46     iocb->aio_reqprio = 0;
47     iocb->aio_buf = reinterpret_cast<uint64_t>(buf);
48     iocb->aio_nbytes = count;
49     iocb->aio_offset = offset;
50 }
51