Merge "cutils: add ashmem_init"
am: 55ba959c13
Change-Id: Iaa91f5dd9752ea59d8e055c0ddb43a6ccc8852f0
This commit is contained in:
commit
3d213c39e8
3 changed files with 17 additions and 1 deletions
|
|
@ -73,6 +73,8 @@ static pthread_mutex_t __ashmem_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#ifndef __ANDROID_VNDK__
|
#ifndef __ANDROID_VNDK__
|
||||||
using openFdType = int (*)();
|
using openFdType = int (*)();
|
||||||
|
|
||||||
|
static openFdType openFd;
|
||||||
|
|
||||||
openFdType initOpenAshmemFd() {
|
openFdType initOpenAshmemFd() {
|
||||||
openFdType openFd = nullptr;
|
openFdType openFd = nullptr;
|
||||||
void* handle = dlopen("libashmemd_client.so", RTLD_NOW);
|
void* handle = dlopen("libashmemd_client.so", RTLD_NOW);
|
||||||
|
|
@ -221,7 +223,10 @@ static int __ashmem_open_locked()
|
||||||
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
#ifndef __ANDROID_VNDK__
|
#ifndef __ANDROID_VNDK__
|
||||||
static auto openFd = initOpenAshmemFd();
|
if (!openFd) {
|
||||||
|
openFd = initOpenAshmemFd();
|
||||||
|
}
|
||||||
|
|
||||||
if (openFd) {
|
if (openFd) {
|
||||||
fd = openFd();
|
fd = openFd();
|
||||||
}
|
}
|
||||||
|
|
@ -480,3 +485,11 @@ int ashmem_get_size_region(int fd)
|
||||||
|
|
||||||
return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)));
|
return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ashmem_init() {
|
||||||
|
#ifndef __ANDROID_VNDK__
|
||||||
|
pthread_mutex_lock(&__ashmem_lock);
|
||||||
|
openFd = initOpenAshmemFd();
|
||||||
|
pthread_mutex_unlock(&__ashmem_lock);
|
||||||
|
#endif //__ANDROID_VNDK__
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,3 +82,5 @@ int ashmem_get_size_region(int fd)
|
||||||
|
|
||||||
return buf.st_size;
|
return buf.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ashmem_init() {}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ int ashmem_set_prot_region(int fd, int prot);
|
||||||
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
||||||
int ashmem_unpin_region(int fd, size_t offset, size_t len);
|
int ashmem_unpin_region(int fd, size_t offset, size_t len);
|
||||||
int ashmem_get_size_region(int fd);
|
int ashmem_get_size_region(int fd);
|
||||||
|
void ashmem_init();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue