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).
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 6 files). Show all
Unified · Split
| @@ -278,11 +278,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 277 unmodified lines | |||
| 278 | const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum; | 278 | const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum; |
| 279 | int32_t iThreadIdx = 0; | 279 | int32_t iThreadIdx = 0; |
| 280 | do { | 280 | do { |
| 281 | #ifdef _WIN32 | ||
| 282 | WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]); | 281 | WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]); |
| 283 | #else | ||
| 284 | WelsEventSignal (pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]); | ||
| 285 | #endif//_WIN32 | ||
| 286 | ++ iThreadIdx; | 282 | ++ iThreadIdx; |
| 287 | } while (iThreadIdx < kiThreadNum); | 283 | } while (iThreadIdx < kiThreadNum); |
| 288 | 284 | ||
| @@ -506,13 +502,13 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 217 unmodified lines | |||
| 506 | char ename[SEM_NAME_MAX] = {0}; | 502 | char ename[SEM_NAME_MAX] = {0}; |
| 507 | // length of semaphore name should be system constrained at least on mac 10.7 | 503 | // length of semaphore name should be system constrained at least on mac 10.7 |
| 508 | WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); | 504 | WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); |
| 509 | WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename); | 505 | WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename); |
| 510 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); | 506 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); |
| 511 | WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename); | 507 | WelsEventClose (&pSmt->pReadySliceCodingEvent[iIdx], ename); |
| 512 | WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); | 508 | WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); |
| 513 | WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename); | 509 | WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename); |
| 514 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); | 510 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); |
| 515 | WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename); | 511 | WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename); |
| 516 | #endif//_WIN32 | 512 | #endif//_WIN32 |
| 517 | 513 | ||
| 518 | ++ iIdx; | 514 | ++ iIdx; |
| @@ -780,12 +776,12 @@ WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { · 261 unmodified lines | |||
| 780 | WelsLog (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n", | 776 | WelsLog (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n", |
| 781 | iEventIdx); | 777 | iEventIdx); |
| 782 | #endif | 778 | #endif |
| 783 | iWaitRet = WelsEventWait (pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]); | 779 | iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]); |
| 784 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { | 780 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { |
| 785 | pCurDq = pEncPEncCtx->pCurDqLayer; | 781 | pCurDq = pEncPEncCtx->pCurDqLayer; |
| 786 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); | 782 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); |
| 787 | WelsEventSignal ( | 783 | WelsEventSignal ( |
| 788 | pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice | 784 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice |
| 789 | } else { | 785 | } else { |
| 790 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, | 786 | WelsLog (pEncPEncCtx, WELS_LOG_WARNING, |
| 791 | "[MT] UpdateMbListThreadProc(), waiting pUpdateMbListEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx, | 787 | "[MT] UpdateMbListThreadProc(), waiting pUpdateMbListEvent[%d] failed(%d) and thread%d terminated!\n", iEventIdx, |
| @@ -848,7 +844,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 56 unmodified lines | |||
| 848 | "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n", | 844 | "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n", |
| 849 | iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx); | 845 | iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx); |
| 850 | #endif | 846 | #endif |
| 851 | iWaitRet = WelsEventWait (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]); | 847 | iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]); |
| 852 | #endif//WIN32 | 848 | #endif//WIN32 |
| 853 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited | 849 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| 854 | SLayerBSInfo* pLbi = pPrivateData->pLayerBs; | 850 | SLayerBSInfo* pLbi = pPrivateData->pLayerBs; |
| @@ -958,12 +954,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 103 unmodified lines | |||
| 958 | pSliceBs->bSliceCodedFlag = true; | 954 | pSliceBs->bSliceCodedFlag = true; |
| 959 | #endif//MT_DEBUG_BS_WR | 955 | #endif//MT_DEBUG_BS_WR |
| 960 | 956 | ||
| 961 | #ifdef _WIN32 | ||
| 962 | WelsEventSignal ( | 957 | WelsEventSignal ( |
| 963 | &pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | 958 | &pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 964 | #else | ||
| 965 | WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | ||
| 966 | #endif//WIN32 | ||
| 967 | } else { // for SM_DYN_SLICE parallelization | 959 | } else { // for SM_DYN_SLICE parallelization |
| 968 | SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; | 960 | SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; |
| 969 | const int32_t kiPartitionId = iThreadIdx; | 961 | const int32_t kiPartitionId = iThreadIdx; |
| @@ -1068,11 +1060,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 98 unmodified lines | |||
| 1068 | if (uiThrdRet) // any exception?? | 1060 | if (uiThrdRet) // any exception?? |
| 1069 | break; | 1061 | break; |
| 1070 | 1062 | ||
| 1071 | #ifdef _WIN32 | ||
| 1072 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | 1063 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 1073 | #else | ||
| 1074 | WelsEventSignal (pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | ||
| 1075 | #endif//WIN32 | ||
| 1076 | } | 1064 | } |
| 1077 | } | 1065 | } |
| 1078 | #ifdef _WIN32 | 1066 | #ifdef _WIN32 |
| @@ -1152,13 +1140,8 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 73 unmodified lines | |||
| 1152 | return 0; | 1140 | return 0; |
| 1153 | } | 1141 | } |
| 1154 | 1142 | ||
| 1155 | #ifdef _WIN32 | ||
| 1156 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLbi, | 1143 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, SLayerBSInfo* pLbi, |
| 1157 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) | 1144 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) |
| 1158 | #else | ||
| 1159 | int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** pEventsList, SLayerBSInfo* pLbi, | ||
| 1160 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) | ||
| 1161 | #endif//WIN32 | ||
| 1162 | { | 1145 | { |
| 1163 | int32_t iEndMbIdx = 0; | 1146 | int32_t iEndMbIdx = 0; |
| 1164 | int32_t iIdx = 0; | 1147 | int32_t iIdx = 0; |
| @@ -1186,12 +1169,8 @@ int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT** pEven · 21 unmodified lines | |||
| 1186 | while (iIdx < kiEventCnt) { | 1169 | while (iIdx < kiEventCnt) { |
| 1187 | pPriData[iIdx].pLayerBs = pLbi; | 1170 | pPriData[iIdx].pLayerBs = pLbi; |
| 1188 | pPriData[iIdx].iSliceIndex = iIdx; | 1171 | pPriData[iIdx].iSliceIndex = iIdx; |
| 1189 | #ifdef _WIN32 | ||
| 1190 | if (pEventsList[iIdx]) | 1172 | if (pEventsList[iIdx]) |
| 1191 | WelsEventSignal (&pEventsList[iIdx]); | 1173 | WelsEventSignal (&pEventsList[iIdx]); |
| 1192 | #else | ||
| 1193 | WelsEventSignal (pEventsList[iIdx]); | ||
| 1194 | #endif//WIN32 | ||
| 1195 | ++ iIdx; | 1174 | ++ iIdx; |
| 1196 | } | 1175 | } |
| 1197 | 1176 | ||