shithub: openh264

Download patch

ref: e9593682eb769a27c1e178ff734b459b3c07452d
parent: d940a204ebc11de6f0542e978ae2b2405cee4d56
parent: e0951599ea38f590bf52b355c26df5f14c125c38
author: Ethan Hugg <ethanhugg@gmail.com>
date: Mon Mar 3 03:23:30 EST 2014

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

Unify ifdef conditions related to threading code

--- a/codec/common/WelsThreadLib.cpp
+++ b/codec/common/WelsThreadLib.cpp
@@ -184,7 +184,7 @@
   return WELS_THREAD_ERROR_OK;
 }
 
-#elif   defined(__GNUC__)
+#else
 
 void WelsSleep (uint32_t dwMilliseconds) {
   usleep (dwMilliseconds * 1000);	// microseconds
--- a/codec/common/WelsThreadLib.h
+++ b/codec/common/WelsThreadLib.h
@@ -62,8 +62,6 @@
 
 #else	// NON-WINDOWS
 
-#if defined(__GNUC__) // LINUX, MACOS etc
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -86,8 +84,6 @@
 #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    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);
--- a/codec/encoder/core/inc/mt_defs.h
+++ b/codec/encoder/core/inc/mt_defs.h
@@ -102,9 +102,9 @@
 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
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -75,9 +75,9 @@
 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);
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2171,7 +2171,7 @@
       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 @@
             } 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]);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -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 @@
   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 @@
 
   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 @@
   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_RETURN (uiThrdRet);
 }
-#endif//__GNUC__
+#endif//!_WIN32
 
 // thread process for coding one pSlice
 WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
@@ -1148,10 +1146,10 @@
     // 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;
   }