Shahriar Vaghar
2018-12-03 06:45:54 UTC
Hello,
In the code below, while *consumer* has grabbed the lock, once in a while,
*producer* gets the lock and writes to shared buffer!
What am I doing wrong? My flags are wrong? I need only one of the functions
have access to the shared buffer at one time.
producer and consumer are running in two separate processes.
static AHardwareBuffer* hardware_buffer;
void *producer*() {
void* shared_buffer = NULL;
int ret = AHardwareBuffer_lock(hardware_buffer,
AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, NULL, &shared_buffer);
if (ret != 0) {
ALOGE("%s: Failed to AHardwareBuffer_lock", __func__);
return;
}
// do work - write data to shared_buffer
ret = AHardwareBuffer_unlock(adev->h_buffer, NULL);
if (ret != 0) {
ALOGE("%s: Failed to AHardwareBuffer_unlock", __func__);
}
}
void *consumer*() {
void* shared_buffer = NULL;
int ret = AHardwareBuffer_lock(hardware_buffer,
AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, -1, NULL, &shared_buffer);
if (ret != 0) {
LOG("Failed to AHardwareBuffer_lock %d", ret);
return;
}
// do work - read data from shared_buffer
ret = AHardwareBuffer_unlock(hardware_buffer, NULL);
if (ret != 0) {
LOG("failed to AHardwareBuffer_unlock %d", ret);
}
}
Thanks, Shahriar
In the code below, while *consumer* has grabbed the lock, once in a while,
*producer* gets the lock and writes to shared buffer!
What am I doing wrong? My flags are wrong? I need only one of the functions
have access to the shared buffer at one time.
producer and consumer are running in two separate processes.
static AHardwareBuffer* hardware_buffer;
void *producer*() {
void* shared_buffer = NULL;
int ret = AHardwareBuffer_lock(hardware_buffer,
AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, NULL, &shared_buffer);
if (ret != 0) {
ALOGE("%s: Failed to AHardwareBuffer_lock", __func__);
return;
}
// do work - write data to shared_buffer
ret = AHardwareBuffer_unlock(adev->h_buffer, NULL);
if (ret != 0) {
ALOGE("%s: Failed to AHardwareBuffer_unlock", __func__);
}
}
void *consumer*() {
void* shared_buffer = NULL;
int ret = AHardwareBuffer_lock(hardware_buffer,
AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, -1, NULL, &shared_buffer);
if (ret != 0) {
LOG("Failed to AHardwareBuffer_lock %d", ret);
return;
}
// do work - read data from shared_buffer
ret = AHardwareBuffer_unlock(hardware_buffer, NULL);
if (ret != 0) {
LOG("failed to AHardwareBuffer_unlock %d", ret);
}
}
Thanks, Shahriar
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c50fa7b9-ce79-4507-82c2-12db28916e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c50fa7b9-ce79-4507-82c2-12db28916e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.