diff options
author | Jerry Zhang <zhangjerry@google.com> | 2018-03-06 19:35:21 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-06 19:35:21 +0000 |
commit | 5180d5b4dc77eac334632902dae9bc6794ca3299 (patch) | |
tree | 8e89055c214b3322c88132771fda205b583fb3b8 | |
parent | d555e08224d2a08f4f12c16ae4109b63b9f7def9 (diff) | |
parent | c3d4e7226a74c3c4092480606ef07e0d30a2d42d (diff) | |
download | core-linaro-andriod-p-preview.tar.gz |
Merge "Make libasyncio headers usable from C"android-p-preview-1linaro-andriod-p-preview
-rw-r--r-- | adb/daemon/usb.cpp | 2 | ||||
-rw-r--r-- | libasyncio/AsyncIO.cpp | 11 | ||||
-rw-r--r-- | libasyncio/include/asyncio/AsyncIO.h | 16 |
3 files changed, 22 insertions, 7 deletions
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index 87ed3db67..20fb6a3d1 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -317,6 +317,8 @@ bool init_functionfs(struct usb_handle* h) { goto err; } + memset(&h->read_aiob.ctx, 0, sizeof(h->read_aiob.ctx)); + memset(&h->write_aiob.ctx, 0, sizeof(h->write_aiob.ctx)); if (io_setup(USB_FFS_NUM_BUFS, &h->read_aiob.ctx) || io_setup(USB_FFS_NUM_BUFS, &h->write_aiob.ctx)) { D("[ aio: got error on io_setup (%d) ]", errno); diff --git a/libasyncio/AsyncIO.cpp b/libasyncio/AsyncIO.cpp index 7430bc81e..6149f09d1 100644 --- a/libasyncio/AsyncIO.cpp +++ b/libasyncio/AsyncIO.cpp @@ -17,9 +17,10 @@ #include <asyncio/AsyncIO.h> #include <sys/syscall.h> #include <unistd.h> +#include <cstdint> +#include <cstring> int io_setup(unsigned nr, aio_context_t* ctxp) { - memset(ctxp, 0, sizeof(*ctxp)); return syscall(__NR_io_setup, nr, ctxp); } @@ -48,3 +49,11 @@ void io_prep(iocb* iocb, int fd, const void* buf, uint64_t count, int64_t offset iocb->aio_nbytes = count; iocb->aio_offset = offset; } + +void io_prep_pread(struct iocb* iocb, int fd, void* buf, size_t count, long long offset) { + io_prep(iocb, fd, buf, count, offset, true); +} + +void io_prep_pwrite(struct iocb* iocb, int fd, void* buf, size_t count, long long offset) { + io_prep(iocb, fd, buf, count, offset, false); +} diff --git a/libasyncio/include/asyncio/AsyncIO.h b/libasyncio/include/asyncio/AsyncIO.h index e3fb93a4d..9620d2a84 100644 --- a/libasyncio/include/asyncio/AsyncIO.h +++ b/libasyncio/include/asyncio/AsyncIO.h @@ -17,9 +17,9 @@ #ifndef _ASYNCIO_H #define _ASYNCIO_H -#include <cstring> -#include <cstdint> #include <linux/aio_abi.h> +#include <stdbool.h> +#include <stdint.h> #include <sys/cdefs.h> #include <sys/types.h> #include <time.h> @@ -35,10 +35,14 @@ extern "C" { int io_setup(unsigned nr, aio_context_t* ctxp); int io_destroy(aio_context_t ctx); -int io_submit(aio_context_t ctx, long nr, iocb** iocbpp); -int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event* events, timespec* timeout); -int io_cancel(aio_context_t ctx, iocb*, io_event* result); -void io_prep(iocb* iocb, int fd, const void* buf, uint64_t count, int64_t offset, bool read); +int io_submit(aio_context_t ctx, long nr, struct iocb** iocbpp); +int io_getevents(aio_context_t ctx, long min_nr, long max_nr, struct io_event* events, + struct timespec* timeout); +int io_cancel(aio_context_t ctx, struct iocb*, struct io_event* result); + +void io_prep_pread(struct iocb* iocb, int fd, void* buf, size_t count, long long offset); +void io_prep_pwrite(struct iocb* iocb, int fd, void* buf, size_t count, long long offset); +void io_prep(struct iocb* iocb, int fd, const void* buf, uint64_t count, int64_t offset, bool read); #ifdef __cplusplus }; |