mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2025-07-03 14:38:18 +00:00
android: ashmem implementation of mirrored memory
This commit is contained in:
parent
ddbe4a8bf2
commit
dd74dd773d
22
src/os.c
22
src/os.c
|
@ -78,6 +78,12 @@
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/ashmem.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct SoundIoOsThread {
|
struct SoundIoOsThread {
|
||||||
#if defined(SOUNDIO_OS_WINDOWS)
|
#if defined(SOUNDIO_OS_WINDOWS)
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
|
@ -670,11 +676,24 @@ int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
fd = open("/dev/ashmem", O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
return SoundIoErrorSystemResources;
|
||||||
|
|
||||||
|
int ret = ioctl(fd, ASHMEM_SET_SIZE, actual_capacity);
|
||||||
|
if (ret < 0) {
|
||||||
|
close(fd);
|
||||||
|
return SoundIoErrorSystemResources;
|
||||||
|
}
|
||||||
|
#else
|
||||||
char shm_path[] = "/dev/shm/soundio-XXXXXX";
|
char shm_path[] = "/dev/shm/soundio-XXXXXX";
|
||||||
char tmp_path[] = "/tmp/soundio-XXXXXX";
|
char tmp_path[] = "/tmp/soundio-XXXXXX";
|
||||||
char *chosen_path;
|
char *chosen_path;
|
||||||
|
|
||||||
int fd = mkstemp(shm_path);
|
fd = mkstemp(shm_path);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fd = mkstemp(tmp_path);
|
fd = mkstemp(tmp_path);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -695,6 +714,7 @@ int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t
|
||||||
close(fd);
|
close(fd);
|
||||||
return SoundIoErrorSystemResources;
|
return SoundIoErrorSystemResources;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char *address = (char*)mmap(NULL, actual_capacity * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
char *address = (char*)mmap(NULL, actual_capacity * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
||||||
if (address == MAP_FAILED) {
|
if (address == MAP_FAILED) {
|
||||||
|
|
Loading…
Reference in a new issue