Merge pull request #392 from mstorsjo/unify-threading-ifdefs

Unify ifdef conditions related to threading code
This commit is contained in:
Ethan Hugg 2014-03-03 08:23:30 -08:00
commit e9593682eb
6 changed files with 19 additions and 25 deletions

View File

@ -184,7 +184,7 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
return WELS_THREAD_ERROR_OK;
}
#elif defined(__GNUC__)
#else
void WelsSleep (uint32_t dwMilliseconds) {
usleep (dwMilliseconds * 1000); // microseconds

View File

@ -62,8 +62,6 @@ typedef HANDLE WELS_EVENT;
#else // NON-WINDOWS
#if defined(__GNUC__) // LINUX, MACOS etc
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@ -86,8 +84,6 @@ typedef sem_t WELS_EVENT;
#define WELS_THREAD_ROUTINE_TYPE void *
#define WELS_THREAD_ROUTINE_RETURN(rc) return (void*)(intptr_t)rc;
#endif//__GNUC__
#endif//_WIN32
typedef int32_t WELS_THREAD_ERROR_CODE;
@ -109,10 +105,10 @@ WELS_THREAD_ERROR_CODE WelsMutexLock (WELS_MUTEX* mutex);
WELS_THREAD_ERROR_CODE WelsMutexUnlock (WELS_MUTEX* mutex);
WELS_THREAD_ERROR_CODE WelsMutexDestroy (WELS_MUTEX* mutex);
#ifdef __GNUC__
#ifndef _WIN32
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//__GNUC__
#endif//!_WIN32
WELS_THREAD_ERROR_CODE WelsEventInit (WELS_EVENT* event);
WELS_THREAD_ERROR_CODE WelsEventDestroy (WELS_EVENT* event);
WELS_THREAD_ERROR_CODE WelsEventSignal (WELS_EVENT* event);

View File

@ -102,9 +102,9 @@ WELS_EVENT* pSliceCodedEvent[MAX_THREADS_NUM];// events for slice coded stat
WELS_EVENT* pReadySliceCodingEvent[MAX_THREADS_NUM]; // events for slice coding ready, [iThreadIdx]
#endif//_WIN32
#if defined(__GNUC__)
#if !defined(_WIN32)
WELS_THREAD_HANDLE* pUpdateMbListThrdHandles; // thread handles for update mb list thread, [iThreadIdx]
#endif//__GNUC__
#endif//!_WIN32
#ifdef _WIN32
WELS_EVENT* pUpdateMbListEvent; // signal to update mb list neighbor for various slices
WELS_EVENT* pFinUpdateMbListEvent; // signal to indicate finish updating mb list

View File

@ -75,9 +75,9 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx);
int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t kiSliceCount);
int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, int32_t& iSliceSize);
#if defined(__GNUC__)
#if !defined(_WIN32)
WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg);
#endif//__GNUC__
#endif//!_WIN32
WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg);

View File

@ -2171,7 +2171,7 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) {
WelsMultipleEventsWaitAllBlocking (iThreadCount, & (*ppCtx)->pSliceThreading->pFinSliceCodingEvent[0]);
}
#elif defined(__GNUC__)
#else
while (iThreadIdx < iThreadCount) {
int res = 0;
if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) {
@ -3300,7 +3300,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo * pFbi, const SSou
} else {
WelsSleep (1);
}
#else//__GNUC__
#else
// TODO for pthread platforms
// alternate implementation using blocking due non-blocking with timeout mode not support at wels thread lib, tune back if available
WelsMultipleEventsWaitAllBlocking (iNumThreadsRunning, &pCtx->pSliceThreading->pSliceCodedEvent[0]);

View File

@ -41,13 +41,13 @@
#if defined(MT_ENABLED)
#include <assert.h>
#if defined(__GNUC__) && !defined(_WIN32)
#if !defined(_WIN32)
#include <semaphore.h>
#ifndef SEM_NAME_MAX
// length of semaphore name should be system constrained at least on mac 10.7
#define SEM_NAME_MAX 32
#endif//SEM_NAME_MAX
#endif//__GNUC__
#endif//!_WIN32
#include "slice_multi_threading.h"
#include "mt_defs.h"
#include "nal_encap.h"
@ -332,13 +332,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pReadySliceCodingEvent), FreeMemorySvc (ppCtx))
pSmt->pFinSliceCodingEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pFinSliceCodingEvent");
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pFinSliceCodingEvent), FreeMemorySvc (ppCtx))
#endif//_WIN32
#if defined(__GNUC__)
#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//__GNUC__
#endif//!_WIN32
#ifdef _WIN32
pSmt->pUpdateMbListEvent = (WELS_EVENT*)pMa->WelsMalloc (sizeof (WELS_EVENT) * iThreadNum, "pUpdateMbListEvent");
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pUpdateMbListEvent), FreeMemorySvc (ppCtx))
@ -386,10 +384,10 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
iIdx = 0;
while (iIdx < iThreadNum) {
#if defined(__GNUC__) && !defined(_WIN32) // for posix threading
#if !defined(_WIN32) // for posix threading
char name[SEM_NAME_MAX] = {0};
WELS_THREAD_ERROR_CODE err = 0;
#endif//__GNUC__
#endif//!_WIN32
pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) (*ppCtx);
pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx;
pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx;
@ -767,7 +765,7 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl
return iReturn;
}
#if defined(__GNUC__) && !defined(_WIN32)
#if !defined(_WIN32)
WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) {
SSliceThreadPrivateData* pPrivateData = (SSliceThreadPrivateData*)arg;
sWelsEncCtx* pEncPEncCtx = NULL;
@ -806,7 +804,7 @@ WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) {
WELS_THREAD_ROUTINE_RETURN (uiThrdRet);
}
#endif//__GNUC__
#endif//!_WIN32
// thread process for coding one pSlice
WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
@ -1148,10 +1146,10 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) {
// We need extra threads for update_mb_list_proc on __GNUC__ like OS (mac/linux)
// due to WelsMultipleEventsWaitSingleBlocking implememtation can not work well
// in case waiting pUpdateMbListEvent and pReadySliceCodingEvent events at the same time
#if defined(__GNUC__) && !defined(_WIN32)
#if !defined(_WIN32)
WelsThreadCreate (&pCtx->pSliceThreading->pUpdateMbListThrdHandles[iIdx], UpdateMbListThreadProc,
&pCtx->pSliceThreading->pThreadPEncCtx[iIdx], 0);
#endif//__GNUC__
#endif//!_WIN32
++ iIdx;
}