genlock: Update version to match release on CodeAurora Forum
Change-Id: Ia45afc73723a9abc1cd55da8a8d0013c171b9855
Signed-off-by: Naseer Ahmed <naseer@codeaurora.org>
diff --git a/libgenlock/genlock.cpp b/libgenlock/genlock.cpp
index bfec641..150ae13 100644
--- a/libgenlock/genlock.cpp
+++ b/libgenlock/genlock.cpp
@@ -54,7 +54,8 @@
} else if (lockType & GENLOCK_READ_LOCK) {
kLockType = GENLOCK_RDLOCK;
} else {
- ALOGE("%s: invalid lockType (lockType = %d)", __FUNCTION__, lockType);
+ ALOGE("%s: invalid lockType (lockType = %d)",
+ __FUNCTION__, lockType);
return -1;
}
return kLockType;
@@ -62,35 +63,50 @@
/* Internal function to perform the actual lock/unlock operations */
genlock_status_t perform_lock_unlock_operation(native_handle_t *buffer_handle,
- int lockType, int timeout)
+ int lockType, int timeout,
+ int flags)
{
if (private_handle_t::validate(buffer_handle)) {
ALOGE("%s: handle is invalid", __FUNCTION__);
return GENLOCK_FAILURE;
}
- private_handle_t *hnd = reinterpret_cast<private_handle_t*>(buffer_handle);
+ private_handle_t *hnd = reinterpret_cast<private_handle_t*>
+ (buffer_handle);
if ((hnd->flags & private_handle_t::PRIV_FLAGS_UNSYNCHRONIZED) == 0) {
if (hnd->genlockPrivFd < 0) {
- ALOGE("%s: the lock has not been created, or has not been attached",
- __FUNCTION__);
+ ALOGE("%s: the lock has not been created,"
+ "or has not been attached", __FUNCTION__);
return GENLOCK_FAILURE;
}
genlock_lock lock;
lock.op = lockType;
- lock.flags = 0;
+ lock.flags = flags;
lock.timeout = timeout;
lock.fd = hnd->genlockHandle;
- if (ioctl(hnd->genlockPrivFd, GENLOCK_IOC_LOCK, &lock)) {
- ALOGE("%s: GENLOCK_IOC_LOCK failed (lockType0x%x, err=%s fd=%d)", __FUNCTION__,
+#ifdef GENLOCK_IOC_DREADLOCK
+ if (ioctl(hnd->genlockPrivFd, GENLOCK_IOC_DREADLOCK, &lock)) {
+ ALOGE("%s: GENLOCK_IOC_DREADLOCK failed (lockType0x%x,"
+ "err=%s fd=%d)", __FUNCTION__,
lockType, strerror(errno), hnd->fd);
if (ETIMEDOUT == errno)
return GENLOCK_TIMEDOUT;
return GENLOCK_FAILURE;
}
+#else
+ // depreciated
+ if (ioctl(hnd->genlockPrivFd, GENLOCK_IOC_LOCK, &lock)) {
+ ALOGE("%s: GENLOCK_IOC_LOCK failed (lockType0x%x, err=%s fd=%d)"
+ ,__FUNCTION__, lockType, strerror(errno), hnd->fd);
+ if (ETIMEDOUT == errno)
+ return GENLOCK_TIMEDOUT;
+
+ return GENLOCK_FAILURE;
+ }
+#endif
}
return GENLOCK_NO_ERROR;
}
@@ -269,7 +285,7 @@
ALOGW("%s: trying to lock a buffer with timeout = 0", __FUNCTION__);
}
// Call the private function to perform the lock operation specified.
- ret = perform_lock_unlock_operation(buffer_handle, kLockType, timeout);
+ ret = perform_lock_unlock_operation(buffer_handle, kLockType, timeout, 0);
#endif
return ret;
}
@@ -287,7 +303,7 @@
#ifdef USE_GENLOCK
// Do the unlock operation by setting the unlock flag. Timeout is always
// 0 in this case.
- ret = perform_lock_unlock_operation(buffer_handle, GENLOCK_UNLOCK, 0);
+ ret = perform_lock_unlock_operation(buffer_handle, GENLOCK_UNLOCK, 0, 0);
#endif
return ret;
}
@@ -320,10 +336,38 @@
lock.fd = hnd->genlockHandle;
lock.timeout = timeout;
if (ioctl(hnd->genlockPrivFd, GENLOCK_IOC_WAIT, &lock)) {
- ALOGE("%s: GENLOCK_IOC_WAIT failed (err=%s)", __FUNCTION__, strerror(errno));
+ ALOGE("%s: GENLOCK_IOC_WAIT failed (err=%s)", __FUNCTION__,
+ strerror(errno));
return GENLOCK_FAILURE;
}
}
#endif
return GENLOCK_NO_ERROR;
}
+
+/*
+ * Convert a write lock that we own to a read lock
+ *
+ * @param: handle of the buffer
+ * @param: timeout value for the wait.
+ * return: error status.
+ */
+genlock_status_t genlock_write_to_read(native_handle_t *buffer_handle,
+ int timeout) {
+ genlock_status_t ret = GENLOCK_NO_ERROR;
+#ifdef USE_GENLOCK
+ if (0 == timeout) {
+ ALOGW("%s: trying to lock a buffer with timeout = 0", __FUNCTION__);
+ }
+ // Call the private function to perform the lock operation specified.
+#ifdef GENLOCK_IOC_DREADLOCK
+ ret = perform_lock_unlock_operation(buffer_handle, GENLOCK_RDLOCK, timeout,
+ GENLOCK_WRITE_TO_READ);
+#else
+ // depreciated
+ ret = perform_lock_unlock_operation(buffer_handle, GENLOCK_RDLOCK,
+ timeout, 0);
+#endif
+#endif
+ return ret;
+}