diff options
-rw-r--r-- | liboverlay/overlay.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp index 33cebdf..0ff72dc 100644 --- a/liboverlay/overlay.cpp +++ b/liboverlay/overlay.cpp @@ -94,6 +94,7 @@ typedef struct uint32_t dataReady; /* Only updated by the data side */ pthread_mutex_t lock; + pthread_mutexattr_t attr; uint32_t streamEn; uint32_t streamingReset; @@ -287,16 +288,29 @@ static int create_shared_data(overlay_shared_t **shared) p->marker = SHARED_DATA_MARKER; p->size = size; p->refCnt = 1; - - if (pthread_mutex_init(&p->lock, NULL) != 0) { - LOGE("Failed to Open Overlay Lock!\n"); - munmap(p, size); - close(fd); - return -1; + if (pthread_mutexattr_init(&p->attr) != 0) { + LOGE("Failed to initialize overlay mutex attr"); + goto MutexAttrErr; + } + if (pthread_mutexattr_setpshared(&p->attr, PTHREAD_PROCESS_SHARED) != 0) { + LOGE("Failed to set the overlay mutex attr to be shared across-processes"); + goto MutexAttrSetErr; + } + if (pthread_mutex_init(&p->lock, &p->attr) != 0) { + LOGE("Failed to initialize overlay mutex\n"); + goto MutexErr; } *shared = p; return fd; + +MutexErr: +MutexAttrSetErr: + pthread_mutexattr_destroy(&p->attr); +MutexAttrErr: + munmap(p, size); + close(fd); + return -1; } static void destroy_shared_data(int shared_fd, overlay_shared_t *shared, @@ -309,9 +323,12 @@ static void destroy_shared_data(int shared_fd, overlay_shared_t *shared, /* side will deadlock trying to use an already released mutex */ if (android_atomic_dec(&shared->refCnt) == 1) { if (pthread_mutex_destroy(&shared->lock)) { - LOGE("Failed to Close Overlay Semaphore!\n"); + LOGE("Failed to uninitialize overlay mutex!\n"); } + if (pthread_mutexattr_destroy(&shared->attr)) { + LOGE("Failed to uninitialize the overlay mutex attr!\n"); + } shared->marker = 0; } |