ref: 1eaa38b1306118b82eb3d0aaeaf2c3aceaa35a6f
parent: ae63f064a0b99faf8c396e068b88aa395d5178ff
author: Martin Storsjö <[email protected]>
date: Mon Mar 3 17:23:34 EST 2014
Simplify code by allocating the arrays of events and thread handles statically This avoids having to malloc a whole lot of separate arrays, all which are all bounded by MAX_THREADS_NUM.
--- a/codec/encoder/core/inc/mt_defs.h
+++ b/codec/encoder/core/inc/mt_defs.h
@@ -91,17 +91,17 @@
typedef struct TagSliceThreading {
SSliceThreadPrivateData* pThreadPEncCtx;// thread context, [iThreadIdx]
-WELS_THREAD_HANDLE* pThreadHandles;// thread handles, [iThreadIdx]
-WELS_EVENT* pSliceCodedEvent;// events for slice coded state, [iThreadIdx]
-WELS_EVENT* pReadySliceCodingEvent; // events for slice coding ready, [iThreadIdx]
-WELS_EVENT* pUpdateMbListEvent; // signal to update mb list neighbor for various slices
-WELS_EVENT* pFinUpdateMbListEvent; // signal to indicate finish updating mb list
+WELS_THREAD_HANDLE pThreadHandles[MAX_THREADS_NUM];// thread handles, [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_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
#ifdef _WIN32
-WELS_EVENT* pFinSliceCodingEvent; // notify slice coding thread is done
-WELS_EVENT* pExitEncodeEvent; // event for exit encoding event
+WELS_EVENT pFinSliceCodingEvent[MAX_THREADS_NUM]; // notify slice coding thread is done
+WELS_EVENT pExitEncodeEvent[MAX_THREADS_NUM]; // event for exit encoding event
#else
-WELS_THREAD_HANDLE* pUpdateMbListThrdHandles; // thread handles for update mb list thread, [iThreadIdx]
+WELS_THREAD_HANDLE pUpdateMbListThrdHandles[MAX_THREADS_NUM]; // thread handles for update mb list thread, [iThreadIdx]
#endif//_WIN32
WELS_MUTEX mutexSliceNumUpdate; // for dynamic slicing mode MT
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -316,33 +316,7 @@
pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum,
"pThreadPEncCtx");
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx))
- pSmt->pThreadHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum,
- "pThreadHandles");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadHandles), FreeMemorySvc (ppCtx))
- pSmt->pSliceCodedEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pSliceCodedEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceCodedEvent), FreeMemorySvc (ppCtx))
- pSmt->pReadySliceCodingEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum,
- "pReadySliceCodingEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pReadySliceCodingEvent), FreeMemorySvc (ppCtx))
-
- pSmt->pUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pUpdateMbListEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pUpdateMbListEvent), FreeMemorySvc (ppCtx))
- pSmt->pFinUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinUpdateMbListEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinUpdateMbListEvent), FreeMemorySvc (ppCtx))
-
-#ifdef _WIN32
- pSmt->pFinSliceCodingEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinSliceCodingEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinSliceCodingEvent), FreeMemorySvc (ppCtx))
-
- pSmt->pExitEncodeEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pExitEncodeEvent");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pExitEncodeEvent), FreeMemorySvc (ppCtx))
-#else
- pSmt->pUpdateMbListThrdHandles = (WELS_THREAD_HANDLE*)pMa->WelsMalloc (sizeof (WELS_THREAD_HANDLE) * iThreadNum,
- "pUpdateMbListThrdHandles");
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pUpdateMbListThrdHandles), FreeMemorySvc (ppCtx))
-#endif//!_WIN32
-
iIdx = 0;
while (iIdx < iNumSpatialLayers) {
SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg;
@@ -515,25 +489,6 @@
++ iIdx;
}
- if (pSmt->pSliceCodedEvent != NULL) {
- pMa->WelsFree (pSmt->pSliceCodedEvent, "pSliceCodedEvent");
- pSmt->pSliceCodedEvent = NULL;
- }
- if (pSmt->pReadySliceCodingEvent != NULL) {
- pMa->WelsFree (pSmt->pReadySliceCodingEvent, "pReadySliceCodingEvent");
- pSmt->pReadySliceCodingEvent = NULL;
- }
-#ifdef _WIN32
- if (pSmt->pExitEncodeEvent != NULL) {
- pMa->WelsFree (pSmt->pExitEncodeEvent, "pExitEncodeEvent");
- pSmt->pExitEncodeEvent = NULL;
- }
- if (pSmt->pFinSliceCodingEvent != NULL) {
- pMa->WelsFree (pSmt->pFinSliceCodingEvent, "pFinSliceCodingEvent");
- pSmt->pFinSliceCodingEvent = NULL;
- }
-#endif//_WIN32
-
WelsMutexDestroy (&pSmt->mutexSliceNumUpdate);
WelsMutexDestroy (&((*ppCtx)->mutexEncoderError));
@@ -541,10 +496,6 @@
pMa->WelsFree (pSmt->pThreadPEncCtx, "pThreadPEncCtx");
pSmt->pThreadPEncCtx = NULL;
}
- if (pSmt->pThreadHandles != NULL) {
- pMa->WelsFree (pSmt->pThreadHandles, "pThreadHandles");
- pSmt->pThreadHandles = NULL;
- }
pSliceB = (*ppCtx)->pSliceBs;
iIdx = 0;
@@ -573,21 +524,6 @@
}
++ iIdx;
}
-
- if (pSmt->pUpdateMbListEvent != NULL) {
- pMa->WelsFree (pSmt->pUpdateMbListEvent, "pUpdateMbListEvent");
- pSmt->pUpdateMbListEvent = NULL;
- }
- if (pSmt->pFinUpdateMbListEvent != NULL) {
- pMa->WelsFree (pSmt->pFinUpdateMbListEvent, "pFinUpdateMbListEvent");
- pSmt->pFinUpdateMbListEvent = NULL;
- }
-#ifndef _WIN32
- if (pSmt->pUpdateMbListThrdHandles) {
- pMa->WelsFree (pSmt->pUpdateMbListThrdHandles, "pUpdateMbListThrdHandles");
- pSmt->pUpdateMbListThrdHandles = NULL;
- }
-#endif//!_WIN32
#ifdef MT_DEBUG
// file handle for debug