--- a/khronosfws/openmax_al/src/common/xaplatform.c Thu May 27 13:20:50 2010 +0300
+++ b/khronosfws/openmax_al/src/common/xaplatform.c Wed Jun 23 18:47:10 2010 +0300
@@ -1,19 +1,19 @@
/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:
-*
-*/
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description: Platform Specific Utility Functions
+ *
+ */
#include <pthread.h>
#include <semaphore.h>
@@ -24,8 +24,6 @@
#include "xaplatform.h"
-
-
/** MACROS **/
/**********************************************************************
@@ -35,21 +33,21 @@
#undef _MUTEXERRORSUPPORT
#ifdef _MUTEXERRORSUPPORT
- typedef pthread_mutex_t XA_MTX;
+typedef pthread_mutex_t XA_MTX;
#else
- typedef struct
+typedef struct
{
- pthread_mutex_t mutex;
- pthread_t owner;
+ pthread_mutex_t mutex;
+ pthread_t owner;
} XA_MTX;
#endif
-XAresult XAImpl_CreateMutex( XAImplMutexHandle *mtx )
-{
- XA_MTX *pMtx = (XA_MTX *)malloc(sizeof(XA_MTX));
+XAresult XAImpl_CreateMutex(XAImplMutexHandle *mtx)
+ {
+ XA_MTX *pMtx = (XA_MTX *) malloc(sizeof(XA_MTX));
assert(mtx);
- if( pMtx )
- {
+ if (pMtx)
+ {
pthread_mutexattr_t *pAttr = NULL;
#ifdef _MUTEXERRORSUPPORT
pthread_mutexattr_t attr;
@@ -58,46 +56,44 @@
pthread_mutexattr_settype(pAttr, PTHREAD_MUTEX_ERRORCHECK);
if(pthread_mutex_init(pMtx, pAttr))
#else
- if(pthread_mutex_init(&(pMtx->mutex), pAttr))
+ if (pthread_mutex_init(&(pMtx->mutex), pAttr))
#endif
- {
+ {
free(pMtx);
*mtx = NULL;
return XA_RESULT_INTERNAL_ERROR;
- }
- *mtx = (XAImplMutexHandle)pMtx;
+ }
+ *mtx = (XAImplMutexHandle) pMtx;
return XA_RESULT_SUCCESS;
- }
+ }
else
- {
+ {
return XA_RESULT_MEMORY_FAILURE;
+ }
}
-}
-
-XAresult XAImpl_LockMutex( XAImplMutexHandle mtx )
-{
- XA_MTX *pMtx = (XA_MTX*)mtx;
+XAresult XAImpl_LockMutex(XAImplMutexHandle mtx)
+ {
+ XA_MTX *pMtx = (XA_MTX*) mtx;
assert(pMtx);
#ifdef _MUTEXERRORSUPPORT
if(pthread_mutex_lock(pMtx))
- {
+ {
return XA_RESULT_PRECONDITIONS_VIOLATED;
- }
+ }
#else
- if( pthread_self() == pMtx->owner ||
- pthread_mutex_unlock(&(pMtx->mutex)) )
- {
+ if (pthread_self() == pMtx->owner || pthread_mutex_unlock(&(pMtx->mutex)))
+ {
return XA_RESULT_PRECONDITIONS_VIOLATED;
- }
+ }
pMtx->owner = pthread_self();
#endif
return XA_RESULT_SUCCESS;
-}
+ }
-XAresult XAImpl_TryLockMutex( XAImplMutexHandle mtx )
-{
- XA_MTX *pMtx = (XA_MTX*)mtx;
+XAresult XAImpl_TryLockMutex(XAImplMutexHandle mtx)
+ {
+ XA_MTX *pMtx = (XA_MTX*) mtx;
XAint32 mutexRet;
XAresult ret = XA_RESULT_SUCCESS;
assert(pMtx);
@@ -105,179 +101,176 @@
#ifdef _MUTEXERRORSUPPORT
mutexRet = pthread_ mutex_trylock(pMtx);
switch (mutexRet)
- {
- case EBUSY:
+ {
+ case EBUSY:
/* if mutex is already locked, return permission denied */
- ret = XA_RESULT_PERMISSION_DENIED;
+ ret = XA_RESULT_PERMISSION_DENIED;
break;
- case 0:
- ret = XA_RESULT_SUCCESS;
+ case 0:
+ ret = XA_RESULT_SUCCESS;
break;
- default:
+ default:
ret = XA_RESULT_PRECONDITIONS_VIOLATED;
break;
- }
+ }
#else
- if( pthread_self() == pMtx->owner )
- {
+ if (pthread_self() == pMtx->owner)
+ {
return XA_RESULT_PRECONDITIONS_VIOLATED;
- }
+ }
mutexRet = pthread_mutex_trylock(&(pMtx->mutex));
switch (mutexRet)
- {
- case EBUSY:
- /* if mutex is already locked, return permission denied */
- ret = XA_RESULT_PERMISSION_DENIED;
- break;
- case 0:
- pMtx->owner = pthread_self();
- ret = XA_RESULT_SUCCESS;
- break;
- default:
- ret = XA_RESULT_PRECONDITIONS_VIOLATED;
- break;
- }
+ {
+ case EBUSY:
+ /* if mutex is already locked, return permission denied */
+ ret = XA_RESULT_PERMISSION_DENIED;
+ break;
+ case 0:
+ pMtx->owner = pthread_self();
+ ret = XA_RESULT_SUCCESS;
+ break;
+ default:
+ ret = XA_RESULT_PRECONDITIONS_VIOLATED;
+ break;
+ }
#endif
return ret;
-}
-
+ }
-XAresult XAImpl_UnlockMutex( XAImplMutexHandle mtx )
-{
- XA_MTX *pMtx = (XA_MTX*)mtx;
+XAresult XAImpl_UnlockMutex(XAImplMutexHandle mtx)
+ {
+ XA_MTX *pMtx = (XA_MTX*) mtx;
assert(pMtx);
#ifdef _MUTEXERRORSUPPORT
if(pthread_mutex_lock(pMtx))
- {
+ {
return XA_RESULT_PRECONDITIONS_VIOLATED;
- }
+ }
#else
- if( pthread_self() != pMtx->owner ||
- pthread_mutex_unlock(&(pMtx->mutex)) )
- {
+ if (pthread_self() != pMtx->owner || pthread_mutex_unlock(&(pMtx->mutex)))
+ {
return XA_RESULT_PRECONDITIONS_VIOLATED;
- }
+ }
// Changing the below value to 0 since owner is an unsigned int.
// pMtx->owner = -1;
pMtx->owner = 0;
#endif
return XA_RESULT_SUCCESS;
-}
+ }
-void XAImpl_DeleteMutex( XAImplMutexHandle mtx )
-{
- XA_MTX *pMtx = (XA_MTX*)mtx;
- if( pMtx )
+void XAImpl_DeleteMutex(XAImplMutexHandle mtx)
{
+ XA_MTX *pMtx = (XA_MTX*) mtx;
+ if (pMtx)
+ {
#ifdef _MUTEXERRORSUPPORT
pthread_mutex_destroy(pMtx);
#else
pthread_mutex_destroy(&(pMtx->mutex));
#endif
free(pMtx);
+ }
}
-}
/**********************************************************************
* semaphores
**********************************************************************/
-
-XAresult XAImpl_CreateSemaphore( XAImplSemHandle *sem )
-{
- sem_t *pSem = (sem_t*)malloc(sizeof(sem_t));
+XAresult XAImpl_CreateSemaphore(XAImplSemHandle *sem)
+ {
+ sem_t *pSem = (sem_t*) malloc(sizeof(sem_t));
assert(sem);
- if( pSem )
- {
- if(sem_init(pSem,0,0))
+ if (pSem)
{
+ if (sem_init(pSem, 0, 0))
+ {
free(pSem);
*sem = NULL;
return XA_RESULT_INTERNAL_ERROR;
- }
- *sem = (XAImplSemHandle)pSem;
+ }
+ *sem = (XAImplSemHandle) pSem;
return XA_RESULT_SUCCESS;
- }
+ }
else
- {
+ {
return XA_RESULT_MEMORY_FAILURE;
+ }
}
-}
-XAresult XAImpl_WaitSemaphore( XAImplSemHandle sem )
-{
- sem_t* pSem = (sem_t*)sem;
+XAresult XAImpl_WaitSemaphore(XAImplSemHandle sem)
+ {
+ sem_t* pSem = (sem_t*) sem;
assert(pSem);
sem_wait(pSem);
return XA_RESULT_SUCCESS;
-}
+ }
-XAresult XAImpl_PostSemaphore( XAImplSemHandle sem )
-{
- sem_t *pSem = (sem_t*)sem;
+XAresult XAImpl_PostSemaphore(XAImplSemHandle sem)
+ {
+ sem_t *pSem = (sem_t*) sem;
assert(pSem);
sem_post(pSem);
return XA_RESULT_SUCCESS;
-}
+ }
-void XAImpl_DeleteSemaphore( XAImplSemHandle sem )
-{
- sem_t *pSem = (sem_t*)sem;
- if( pSem )
+void XAImpl_DeleteSemaphore(XAImplSemHandle sem)
{
+ sem_t *pSem = (sem_t*) sem;
+ if (pSem)
+ {
sem_destroy(pSem);
free(pSem);
+ }
}
-}
/**********************************************************************
* THREADS
**********************************************************************/
-XAresult XAImpl_CreateThreadHandle( XAImplThreadHandle *thd )
-{
- pthread_t *pThd = (pthread_t*)malloc(sizeof(pthread_t));
+XAresult XAImpl_CreateThreadHandle(XAImplThreadHandle *thd)
+ {
+ pthread_t *pThd = (pthread_t*) malloc(sizeof(pthread_t));
assert(thd);
- if( !pThd )
- {
+ if (!pThd)
+ {
return XA_RESULT_MEMORY_FAILURE;
- }
- *thd = (XAImplThreadHandle)pThd;
+ }
+ *thd = (XAImplThreadHandle) pThd;
return XA_RESULT_SUCCESS;
-}
+ }
-XAresult XAImpl_StartThread( XAImplThreadHandle thd,
- void *thdattrib, XAImplThreadFunction thdfunc, void* thdfuncargs )
-{
- pthread_t *pThd = (pthread_t*)thd;
+XAresult XAImpl_StartThread(XAImplThreadHandle thd, void *thdattrib,
+ XAImplThreadFunction thdfunc, void* thdfuncargs)
+ {
+ pthread_t *pThd = (pthread_t*) thd;
assert(thd);
- if ( pthread_create(pThd, thdattrib, thdfunc, thdfuncargs) )
- {
+ if (pthread_create(pThd, thdattrib, thdfunc, thdfuncargs))
+ {
return XA_RESULT_INTERNAL_ERROR;
- }
+ }
return XA_RESULT_SUCCESS;
-}
+ }
-void XAImpl_CancelThread( XAImplThreadHandle thd )
-{
-// int res;
- // TL: TODO: There is no pthread_cancel API in S60, need to replace
- //res = pthread_cancel(*pThd);
-
-}
+void XAImpl_CancelThread(XAImplThreadHandle thd)
+ {
+ // int res;
+ // TL: TODO: There is no pthread_cancel API in S60, need to replace
+ //res = pthread_cancel(*pThd);
+
+ }
-void XAImpl_ExitThread( XAImplThreadHandle thd )
-{
+void XAImpl_ExitThread(XAImplThreadHandle thd)
+ {
pthread_exit(NULL);
-}
+ }
-void XAImpl_DeleteThreadHandle( XAImplThreadHandle thd )
-{
- pthread_t *pThd = (pthread_t*)thd;
- if( pThd )
+void XAImpl_DeleteThreadHandle(XAImplThreadHandle thd)
{
+ pthread_t *pThd = (pthread_t*) thd;
+ if (pThd)
+ {
free(pThd);
+ }
}
-}