ref: 71bc52d10365eca8a7ba1a930674e64c3e08e39c
parent: e9c340367418435d31e31e2d51b6186b7bfa8e37
author: Martin Storsjö <[email protected]>
date: Sun Mar 2 17:08:15 EST 2014
Change the unix version of WELS_EVENT to sem_t* Typedeffing WELS_EVENT as sem_t* makes the typedef behave similarly to the windows version (typedeffed as HANDLE), unifying the code that allocates and uses these event objects (getting rid of most of the need for separate codepaths and ifdefs).
--- a/codec/common/WelsThreadLib.cpp
+++ b/codec/common/WelsThreadLib.cpp
@@ -255,14 +255,14 @@
// unnamed semaphores aren't supported on OS X
WELS_THREAD_ERROR_CODE WelsEventInit (WELS_EVENT* event) {
- return sem_init (event, 0, 0);
+ return sem_init (*event, 0, 0);
}
WELS_THREAD_ERROR_CODE WelsEventDestroy (WELS_EVENT* event) {
- return sem_destroy (event); // match with sem_init
+ return sem_destroy (*event); // match with sem_init
}
-WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT** p_event, const char* event_name) {
+WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT* p_event, const char* event_name) {
if (p_event == NULL || event_name == NULL)
return WELS_THREAD_ERROR_GENERAL;
*p_event = sem_open (event_name, O_CREAT, (S_IRUSR | S_IWUSR)/*0600*/, 0);
@@ -275,7 +275,7 @@
}
}
WELS_THREAD_ERROR_CODE WelsEventClose (WELS_EVENT* event, const char* event_name) {
- WELS_THREAD_ERROR_CODE err = sem_close (event); // match with sem_open
+ WELS_THREAD_ERROR_CODE err = sem_close (*event); // match with sem_open
if (event_name)
sem_unlink (event_name);
return err;
@@ -286,7 +286,7 @@
// int32_t val = 0;
// sem_getvalue(event, &val);
// fprintf( stderr, "before signal it, val= %d..\n",val );
- err = sem_post (event);
+ err = sem_post (*event);
// sem_getvalue(event, &val);
// fprintf( stderr, "after signal it, val= %d..\n",val );
return err;
@@ -293,18 +293,18 @@
}
WELS_THREAD_ERROR_CODE WelsEventWait (WELS_EVENT* event) {
- return sem_wait (event); // blocking until signaled
+ return sem_wait (*event); // blocking until signaled
}
WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t dwMilliseconds) {
if (dwMilliseconds != (uint32_t) - 1) {
- return sem_wait (event);
+ return sem_wait (*event);
} else {
#if defined(__APPLE__)
int32_t err = 0;
int32_t wait_count = 0;
do {
- err = sem_trywait (event);
+ err = sem_trywait (*event);
if (WELS_THREAD_ERROR_OK == err)
break;// WELS_THREAD_ERROR_OK;
else if (wait_count > 0)
@@ -323,13 +323,13 @@
ts.tv_sec = tv.tv_sec + ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
- return sem_timedwait (event, &ts);
+ return sem_timedwait (*event, &ts);
#endif//__APPLE__
}
}
WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitSingleBlocking (uint32_t nCount,
- WELS_EVENT** event_list,
+ WELS_EVENT* event_list,
uint32_t dwMilliseconds) {
// bWaitAll = FALSE && blocking
uint32_t nIdx = 0;
@@ -401,7 +401,7 @@
return WELS_THREAD_ERROR_WAIT_FAILED;
}
-WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitAllBlocking (uint32_t nCount, WELS_EVENT** event_list) {
+WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitAllBlocking (uint32_t nCount, WELS_EVENT* event_list) {
// bWaitAll = TRUE && blocking
uint32_t nIdx = 0;
// const uint32_t kuiAccessTime = (uint32_t)-1;// 1 ms once
--- a/codec/common/WelsThreadLib.h
+++ b/codec/common/WelsThreadLib.h
@@ -79,7 +79,7 @@
typedef void* (*LPWELS_THREAD_ROUTINE) (void*);
typedef pthread_mutex_t WELS_MUTEX;
-typedef sem_t WELS_EVENT;
+typedef sem_t* WELS_EVENT;
#define WELS_THREAD_ROUTINE_TYPE void *
#define WELS_THREAD_ROUTINE_RETURN(rc) return (void*)(intptr_t)rc;
@@ -106,7 +106,7 @@
WELS_THREAD_ERROR_CODE WelsMutexDestroy (WELS_MUTEX* mutex);
#ifndef _WIN32
-WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT** p_event, const char* event_name);
+WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT* p_event, const char* event_name);
WELS_THREAD_ERROR_CODE WelsEventClose (WELS_EVENT* event, const char* event_name);
#endif//!_WIN32
WELS_THREAD_ERROR_CODE WelsEventInit (WELS_EVENT* event);
@@ -114,15 +114,9 @@
WELS_THREAD_ERROR_CODE WelsEventSignal (WELS_EVENT* event);
WELS_THREAD_ERROR_CODE WelsEventWait (WELS_EVENT* event);
WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t dwMilliseconds);
-#ifdef _WIN32
WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitSingleBlocking (uint32_t nCount, WELS_EVENT* event_list,
uint32_t dwMilliseconds);
WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitAllBlocking (uint32_t nCount, WELS_EVENT* event_list);
-#else
-WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitSingleBlocking (uint32_t nCount, WELS_EVENT** event_list,
- uint32_t dwMilliseconds);
-WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitAllBlocking (uint32_t nCount, WELS_EVENT** event_list);
-#endif//_WIN32
WELS_THREAD_ERROR_CODE WelsThreadCreate (WELS_THREAD_HANDLE* thread, LPWELS_THREAD_ROUTINE routine,
void* arg, WELS_THREAD_ATTR attr);
--- a/codec/encoder/core/inc/mt_defs.h
+++ b/codec/encoder/core/inc/mt_defs.h
@@ -100,12 +100,12 @@
WELS_EVENT* pUpdateMbListEvent; // signal to update mb list neighbor for various slices
WELS_EVENT* pFinUpdateMbListEvent; // signal to indicate finish updating mb list
#else
-WELS_EVENT* pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded state, [iThreadIdx]
-WELS_EVENT* pReadySliceCodingEvent[MAX_THREADS_NUM]; // events for slice coding ready, [iThreadIdx]
+WELS_EVENT pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded state, [iThreadIdx]
+WELS_EVENT pReadySliceCodingEvent[MAX_THREADS_NUM]; // events for slice coding ready, [iThreadIdx]
WELS_THREAD_HANDLE* pUpdateMbListThrdHandles; // thread handles for update mb list thread, [iThreadIdx]
-WELS_EVENT* pUpdateMbListEvent[MAX_THREADS_NUM]; // signal to update mb list neighbor for various slices
-WELS_EVENT* pFinUpdateMbListEvent[MAX_THREADS_NUM]; // signal to indicate finish updating mb list
+WELS_EVENT pUpdateMbListEvent[MAX_THREADS_NUM]; // signal to update mb list neighbor for various slices
+WELS_EVENT pFinUpdateMbListEvent[MAX_THREADS_NUM]; // signal to indicate finish updating mb list
#endif//_WIN32
WELS_MUTEX mutexSliceNumUpdate; // for dynamic slicing mode MT
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -83,13 +83,8 @@
int32_t CreateSliceThreads (sWelsEncCtx* pCtx);
-#ifdef _WIN32
int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLayerBsInfo,
const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
-#else
-int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** ppEventsList, SLayerBSInfo* pLayerBsInfo,
- const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
-#endif//_WIN32
int32_t DynamicDetectCpuCores();
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3308,7 +3308,7 @@
if (iIndexOfSliceToBeCoded >= iSliceCount)
break;
pCtx->pSliceThreading->pThreadPEncCtx[iThreadIdx].iSliceIndex = iIndexOfSliceToBeCoded;
- WelsEventSignal (pCtx->pSliceThreading->pReadySliceCodingEvent[iThreadIdx]);
+ WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iThreadIdx]);
++ iIndexOfSliceToBeCoded;
++ iThreadIdx;
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -278,11 +278,7 @@
const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum;
int32_t iThreadIdx = 0;
do {
-#ifdef _WIN32
WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]);
-#else
- WelsEventSignal (pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]);
-#endif//_WIN32
++ iThreadIdx;
} while (iThreadIdx < kiThreadNum);
@@ -506,13 +502,13 @@
char ename[SEM_NAME_MAX] = {0};
// length of semaphore name should be system constrained at least on mac 10.7
WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
- WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename);
+ WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename);
WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
- WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename);
+ WelsEventClose (&pSmt->pReadySliceCodingEvent[iIdx], ename);
WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
- WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename);
+ WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename);
WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
- WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename);
+ WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename);
#endif//_WIN32
++ iIdx;
@@ -780,12 +776,12 @@
WelsLog (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n",
iEventIdx);
#endif
- iWaitRet = WelsEventWait (pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]);
+ iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]);
if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) {
pCurDq = pEncPEncCtx->pCurDqLayer;
UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx);
WelsEventSignal (
- pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice
+ &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice
} else {
WelsLog (pEncPEncCtx, WELS_LOG_WARNING,
"[MT] UpdateMbListThreadProc(), waiting pUpdateMbListEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx,
@@ -848,7 +844,7 @@
"[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n",
iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx);
#endif
- iWaitRet = WelsEventWait (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]);
+ iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]);
#endif//WIN32
if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited
SLayerBSInfo* pLbi = pPrivateData->pLayerBs;
@@ -958,12 +954,8 @@
pSliceBs->bSliceCodedFlag = true;
#endif//MT_DEBUG_BS_WR
-#ifdef _WIN32
WelsEventSignal (
&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice
-#else
- WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice
-#endif//WIN32
} else { // for SM_DYN_SLICE parallelization
SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx;
const int32_t kiPartitionId = iThreadIdx;
@@ -1068,11 +1060,7 @@
if (uiThrdRet) // any exception??
break;
-#ifdef _WIN32
WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice
-#else
- WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice
-#endif//WIN32
}
}
#ifdef _WIN32
@@ -1152,13 +1140,8 @@
return 0;
}
-#ifdef _WIN32
int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLbi,
const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode)
-#else
-int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** pEventsList, SLayerBSInfo* pLbi,
- const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode)
-#endif//WIN32
{
int32_t iEndMbIdx = 0;
int32_t iIdx = 0;
@@ -1186,12 +1169,8 @@
while (iIdx < kiEventCnt) {
pPriData[iIdx].pLayerBs = pLbi;
pPriData[iIdx].iSliceIndex = iIdx;
-#ifdef _WIN32
if (pEventsList[iIdx])
WelsEventSignal (&pEventsList[iIdx]);
-#else
- WelsEventSignal (pEventsList[iIdx]);
-#endif//WIN32
++ iIdx;
}