diff options
Diffstat (limited to 'libtiutils')
-rw-r--r--[-rwxr-xr-x] | libtiutils/Android.mk | 1 | ||||
-rw-r--r-- | libtiutils/DebugUtils.h | 16 | ||||
-rw-r--r-- | libtiutils/ErrorUtils.h | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | libtiutils/MessageQueue.cpp | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | libtiutils/MessageQueue.h | 0 | ||||
-rw-r--r-- | libtiutils/Semaphore.cpp | 464 | ||||
-rw-r--r-- | libtiutils/Semaphore.h | 2 |
7 files changed, 243 insertions, 244 deletions
diff --git a/libtiutils/Android.mk b/libtiutils/Android.mk index 4b6a2b3e..e15eba94 100755..100644 --- a/libtiutils/Android.mk +++ b/libtiutils/Android.mk @@ -19,7 +19,6 @@ LOCAL_SHARED_LIBRARIES:= \ libcutils LOCAL_C_INCLUDES += \ - frameworks/base/include/utils \ bionic/libc/include \ hardware/ti/omap4xxx/domx/omx_core/inc \ hardware/ti/omap4xxx/domx/mm_osal/inc diff --git a/libtiutils/DebugUtils.h b/libtiutils/DebugUtils.h index 54edfc76..f4212522 100644 --- a/libtiutils/DebugUtils.h +++ b/libtiutils/DebugUtils.h @@ -20,14 +20,14 @@ #define DEBUG_UTILS_H ///Defines for debug statements - Macro LOG_TAG needs to be defined in the respective files -#define DBGUTILS_LOGVA(str) LOGV("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__); -#define DBGUTILS_LOGVB(str,...) LOGV("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); -#define DBGUTILS_LOGDA(str) LOGD("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__); -#define DBGUTILS_LOGDB(str, ...) LOGD("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); -#define DBGUTILS_LOGEA(str) LOGE("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__); -#define DBGUTILS_LOGEB(str, ...) LOGE("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__, __VA_ARGS__); -#define LOG_FUNCTION_NAME LOGV("%d: %s() ENTER", __LINE__, __FUNCTION__); -#define LOG_FUNCTION_NAME_EXIT LOGV("%d: %s() EXIT", __LINE__, __FUNCTION__); +#define DBGUTILS_LOGVA(str) ALOGV("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__); +#define DBGUTILS_LOGVB(str,...) ALOGV("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); +#define DBGUTILS_LOGDA(str) ALOGD("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__); +#define DBGUTILS_LOGDB(str, ...) ALOGD("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); +#define DBGUTILS_LOGEA(str) ALOGE("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__); +#define DBGUTILS_LOGEB(str, ...) ALOGE("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__, __VA_ARGS__); +#define LOG_FUNCTION_NAME ALOGV("%d: %s() ENTER", __LINE__, __FUNCTION__); +#define LOG_FUNCTION_NAME_EXIT ALOGV("%d: %s() EXIT", __LINE__, __FUNCTION__); diff --git a/libtiutils/ErrorUtils.h b/libtiutils/ErrorUtils.h index 24dd8060..204ec972 100644 --- a/libtiutils/ErrorUtils.h +++ b/libtiutils/ErrorUtils.h @@ -18,7 +18,7 @@ #define ERROR_UTILS_H ///Header file where all the android error codes are defined -#include <Errors.h> +#include <utils/Errors.h> ///Header file where all the OMX error codes are defined #include "OMX_Core.h" diff --git a/libtiutils/MessageQueue.cpp b/libtiutils/MessageQueue.cpp index 11f54074..e3647d49 100755..100644 --- a/libtiutils/MessageQueue.cpp +++ b/libtiutils/MessageQueue.cpp @@ -20,7 +20,7 @@ #include <sys/types.h> #include <sys/poll.h> #include <unistd.h> -#include <Errors.h> +#include <utils/Errors.h> diff --git a/libtiutils/MessageQueue.h b/libtiutils/MessageQueue.h index 6d05201f..6d05201f 100755..100644 --- a/libtiutils/MessageQueue.h +++ b/libtiutils/MessageQueue.h diff --git a/libtiutils/Semaphore.cpp b/libtiutils/Semaphore.cpp index 41fa99c0..37f3a89c 100644 --- a/libtiutils/Semaphore.cpp +++ b/libtiutils/Semaphore.cpp @@ -1,232 +1,232 @@ -/*
- * Copyright (C) Texas Instruments - http://www.ti.com/
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-
-#include "Semaphore.h"
-#include "ErrorUtils.h"
-#include <utils/Log.h>
-#include <time.h>
-
-namespace android {
-
-/**
- @brief Constructor for the semaphore class
-
- @param none
- @return none
- */
-Semaphore::Semaphore()
-{
- ///Initialize the semaphore to NULL
- mSemaphore = NULL;
-}
-
-/**
- @brief Destructor of the semaphore class
-
- @param none
- @return none
-
- */
-Semaphore::~Semaphore()
-{
- Release();
-}
-
-/**
- @brief: Releases semaphore
-
- @param count >=0
- @return NO_ERROR On Success
- @return One of the android error codes based on semaphore de-initialization
- */
-
-status_t Semaphore::Release()
-{
- int status = 0;
-
- ///Destroy only if the semaphore has been created
- if(mSemaphore)
- {
- status = sem_destroy(mSemaphore);
-
- free(mSemaphore);
-
- mSemaphore = NULL;
- }
-
- ///Initialize the semaphore and return the status
- return ErrorUtils::posixToAndroidError(status);
-
-}
-
-/**
- @brief Create the semaphore with initial count value
-
- @param count >=0
- @return NO_ERROR On Success
- @return NO_MEMORY If unable to allocate memory for the semaphore
- @return BAD_VALUE If an invalid count value is passed (<0)
- @return One of the android error codes based on semaphore initialization
- */
-
-status_t Semaphore::Create(int count)
-{
- status_t ret = NO_ERROR;
-
- ///count cannot be less than zero
- if(count<0)
- {
- return BAD_VALUE;
- }
-
- ret = Release();
- if ( NO_ERROR != ret )
- {
- return ret;
- }
-
- ///allocate memory for the semaphore
- mSemaphore = (sem_t*)malloc(sizeof(sem_t)) ;
-
- ///if memory is unavailable, return error
- if(!mSemaphore)
- {
- return NO_MEMORY;
- }
-
- ///Initialize the semaphore and return the status
- return ErrorUtils::posixToAndroidError(sem_init(mSemaphore, 0x00, count));
-
-}
-
-/**
- @brief Wait operation
-
- @param none
- @return BAD_VALUE if the semaphore is not initialized
- @return NO_ERROR On success
- @return One of the android error codes based on semaphore wait operation
- */
-status_t Semaphore::Wait()
-{
- ///semaphore should have been created first
- if(!mSemaphore)
- {
- return BAD_VALUE;
- }
-
- ///Wait and return the status after signalling
- return ErrorUtils::posixToAndroidError(sem_wait(mSemaphore));
-
-
-}
-
-
-/**
- @brief Signal operation
-
- @param none
- @return BAD_VALUE if the semaphore is not initialized
- @return NO_ERROR On success
- @return One of the android error codes based on semaphore signal operation
- */
-
-status_t Semaphore::Signal()
-{
- ///semaphore should have been created first
- if(!mSemaphore)
- {
- return BAD_VALUE;
- }
-
- ///Post to the semaphore
- return ErrorUtils::posixToAndroidError(sem_post(mSemaphore));
-
-}
-
-/**
- @brief Current semaphore count
-
- @param none
- @return Current count value of the semaphore
- */
-int Semaphore::Count()
-{
- int val;
-
- ///semaphore should have been created first
- if(!mSemaphore)
- {
- return BAD_VALUE;
- }
-
- ///get the value of the semaphore
- sem_getvalue(mSemaphore, &val);
-
- return val;
-}
-
-/**
- @brief Wait operation with a timeout
-
- @param timeoutMicroSecs The timeout period in micro seconds
- @return BAD_VALUE if the semaphore is not initialized
- @return NO_ERROR On success
- @return One of the android error codes based on semaphore wait operation
- */
-
-status_t Semaphore::WaitTimeout(int timeoutMicroSecs)
-{
- status_t ret = NO_ERROR;
-
- struct timespec timeSpec;
- struct timeval currentTime;
-
- ///semaphore should have been created first
- if( NULL == mSemaphore)
- {
- ret = BAD_VALUE;
- }
-
- if ( NO_ERROR == ret )
- {
-
- ///setup the timeout values - timeout is specified in seconds and nanoseconds
- gettimeofday(¤tTime, NULL);
- timeSpec.tv_sec = currentTime.tv_sec;
- timeSpec.tv_nsec = currentTime.tv_usec * 1000;
- timeSpec.tv_sec += ( timeoutMicroSecs / 1000000 );
- timeSpec.tv_nsec += ( timeoutMicroSecs % 1000000) * 1000;
-
- ///Wait for the timeout or signal and return the result based on whichever event occurred first
- ret = sem_timedwait(mSemaphore, &timeSpec);
- }
-
- if ( NO_ERROR != ret )
- {
- Signal();
- Create(0);
- }
-
- return ret;
-}
-
-
-};
-
-
+/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include "Semaphore.h" +#include "ErrorUtils.h" +#include <utils/Log.h> +#include <time.h> + +namespace android { + +/** + @brief Constructor for the semaphore class + + @param none + @return none + */ +Semaphore::Semaphore() +{ + ///Initialize the semaphore to NULL + mSemaphore = NULL; +} + +/** + @brief Destructor of the semaphore class + + @param none + @return none + + */ +Semaphore::~Semaphore() +{ + Release(); +} + +/** + @brief: Releases semaphore + + @param count >=0 + @return NO_ERROR On Success + @return One of the android error codes based on semaphore de-initialization + */ + +status_t Semaphore::Release() +{ + int status = 0; + + ///Destroy only if the semaphore has been created + if(mSemaphore) + { + status = sem_destroy(mSemaphore); + + free(mSemaphore); + + mSemaphore = NULL; + } + + ///Initialize the semaphore and return the status + return ErrorUtils::posixToAndroidError(status); + +} + +/** + @brief Create the semaphore with initial count value + + @param count >=0 + @return NO_ERROR On Success + @return NO_MEMORY If unable to allocate memory for the semaphore + @return BAD_VALUE If an invalid count value is passed (<0) + @return One of the android error codes based on semaphore initialization + */ + +status_t Semaphore::Create(int count) +{ + status_t ret = NO_ERROR; + + ///count cannot be less than zero + if(count<0) + { + return BAD_VALUE; + } + + ret = Release(); + if ( NO_ERROR != ret ) + { + return ret; + } + + ///allocate memory for the semaphore + mSemaphore = (sem_t*)malloc(sizeof(sem_t)) ; + + ///if memory is unavailable, return error + if(!mSemaphore) + { + return NO_MEMORY; + } + + ///Initialize the semaphore and return the status + return ErrorUtils::posixToAndroidError(sem_init(mSemaphore, 0x00, count)); + +} + +/** + @brief Wait operation + + @param none + @return BAD_VALUE if the semaphore is not initialized + @return NO_ERROR On success + @return One of the android error codes based on semaphore wait operation + */ +status_t Semaphore::Wait() +{ + ///semaphore should have been created first + if(!mSemaphore) + { + return BAD_VALUE; + } + + ///Wait and return the status after signalling + return ErrorUtils::posixToAndroidError(sem_wait(mSemaphore)); + + +} + + +/** + @brief Signal operation + + @param none + @return BAD_VALUE if the semaphore is not initialized + @return NO_ERROR On success + @return One of the android error codes based on semaphore signal operation + */ + +status_t Semaphore::Signal() +{ + ///semaphore should have been created first + if(!mSemaphore) + { + return BAD_VALUE; + } + + ///Post to the semaphore + return ErrorUtils::posixToAndroidError(sem_post(mSemaphore)); + +} + +/** + @brief Current semaphore count + + @param none + @return Current count value of the semaphore + */ +int Semaphore::Count() +{ + int val; + + ///semaphore should have been created first + if(!mSemaphore) + { + return BAD_VALUE; + } + + ///get the value of the semaphore + sem_getvalue(mSemaphore, &val); + + return val; +} + +/** + @brief Wait operation with a timeout + + @param timeoutMicroSecs The timeout period in micro seconds + @return BAD_VALUE if the semaphore is not initialized + @return NO_ERROR On success + @return One of the android error codes based on semaphore wait operation + */ + +status_t Semaphore::WaitTimeout(int timeoutMicroSecs) +{ + status_t ret = NO_ERROR; + + struct timespec timeSpec; + struct timeval currentTime; + + ///semaphore should have been created first + if( NULL == mSemaphore) + { + ret = BAD_VALUE; + } + + if ( NO_ERROR == ret ) + { + + ///setup the timeout values - timeout is specified in seconds and nanoseconds + gettimeofday(¤tTime, NULL); + timeSpec.tv_sec = currentTime.tv_sec; + timeSpec.tv_nsec = currentTime.tv_usec * 1000; + timeSpec.tv_sec += ( timeoutMicroSecs / 1000000 ); + timeSpec.tv_nsec += ( timeoutMicroSecs % 1000000) * 1000; + + ///Wait for the timeout or signal and return the result based on whichever event occurred first + ret = sem_timedwait(mSemaphore, &timeSpec); + } + + if ( NO_ERROR != ret ) + { + Signal(); + Create(0); + } + + return ret; +} + + +}; + + diff --git a/libtiutils/Semaphore.h b/libtiutils/Semaphore.h index 466e709a..6990848c 100644 --- a/libtiutils/Semaphore.h +++ b/libtiutils/Semaphore.h @@ -16,7 +16,7 @@ -#include <Errors.h> +#include <utils/Errors.h> #include <semaphore.h> #include <stdio.h> #include <stdarg.h> |