Skip to content

Keep posix_memalign() around for older Android APIs #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
endif()

check_function_exists(_pthread_workqueue_init HAVE__PTHREAD_WORKQUEUE_INIT)
check_function_exists(aligned_alloc HAVE_ALIGNED_ALLOC)
check_function_exists(getprogname HAVE_GETPROGNAME)
check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
check_function_exists(mach_approximate_time HAVE_MACH_APPROXIMATE_TIME)
Expand Down
7 changes: 6 additions & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,13 @@ _dispatch_operation_perform(dispatch_operation_t op)
bQueried = true;
}
op->buf = _aligned_malloc(op->buf_siz, siInfo.dwPageSize);
#else
#elif defined(HAVE_ALIGNED_ALLOC)
op->buf = aligned_alloc((size_t)PAGE_SIZE, op->buf_siz);
#else
err = posix_memalign(&op->buf, (size_t)PAGE_SIZE, op->buf_siz);
if (err != 0) {
goto error;
}
#endif
_dispatch_op_debug("buffer allocated", op);
} else if (op->direction == DOP_DIR_WRITE) {
Expand Down
4 changes: 4 additions & 0 deletions tests/dispatch_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
buffer = _aligned_malloc(size, si.dwPageSize);
#else
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
#if defined(HAVE_ALIGNED_ALLOC)
buffer = aligned_alloc(pagesize, size);
#else
posix_memalign((void **)&buffer, pagesize, size);
#endif
#endif
ssize_t r = dispatch_test_fd_read(fd, buffer, size);
if (r == -1) {
Expand Down
4 changes: 4 additions & 0 deletions tests/dispatch_read2.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ dispatch_read2(dispatch_fd_t fd,
buffer = _aligned_malloc(bufsiz, pagesize);
#else
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
#if defined(HAVE_ALIGNED_ALLOC)
buffer = aligned_alloc(pagesize, bufsiz);
#else
posix_memalign((void **)&buffer, pagesize, bufsiz);
#endif
#endif
ssize_t actual = dispatch_test_fd_read(fd, buffer, bufsiz);
if (actual == -1) {
Expand Down