genlock: Update version to match release on CodeAurora Forum

Change-Id: Ia45afc73723a9abc1cd55da8a8d0013c171b9855
This commit is contained in:
Naseer Ahmed 2012-06-20 19:37:18 -07:00 committed by Gohulan Balachandran
parent 8126b77c3a
commit 996d07075c
2 changed files with 73 additions and 18 deletions

View File

@ -54,7 +54,8 @@ namespace {
} 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 @@ namespace {
/* 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 @@ genlock_status_t genlock_lock_buffer(native_handle_t *buffer_handle,
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 @@ genlock_status_t genlock_unlock_buffer(native_handle_t *buffer_handle)
#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 @@ genlock_status_t genlock_wait(native_handle_t *buffer_handle, int timeout) {
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;
}

View File

@ -79,15 +79,17 @@ extern "C" {
genlock_status_t genlock_attach_lock(native_handle_t *buffer_handle);
/*
* Lock the buffer specified by the buffer handle. The lock held by the buffer
* is specified by the lockType. This function will block if a write lock is
* requested on the buffer which has previously been locked for a read or write
* operation. A buffer can be locked by multiple clients for read. An optional
* timeout value can be specified. By default, there is no timeout.
* Lock the buffer specified by the buffer handle. The lock held by the
* buffer is specified by the lockType. This function will block if a write
* lock is requested on the buffer which has previously been locked for a
* read or write operation. A buffer can be locked by multiple clients for
* read. An optional timeout value can be specified.
* By default, there is no timeout.
*
* @param: handle of the buffer
* @param: type of lock to be acquired by the buffer.
* @param: timeout value in ms. GENLOCK_MAX_TIMEOUT is the maximum timeout value.
* @param: timeout value in ms. GENLOCK_MAX_TIMEOUT is the maximum timeout
* value.
* @return error status.
*/
genlock_status_t genlock_lock_buffer(native_handle_t *buffer_handle,
@ -111,8 +113,17 @@ extern "C" {
*/
genlock_status_t genlock_wait(native_handle_t *buffer_handle, int timeout);
/*
* 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);
#ifdef __cplusplus
}
#endif
#endif