ref: 5480ffafdf395a429ae5b9f966ecbd6b3169b36c
parent: adb27ff0b1d407ad467ed53811a481bf1199db91
author: Martin Storsjö <[email protected]>
date: Sun Mar 2 18:09:13 EST 2014
Use the WelsEventOpen interface with an event name on windows as well This unifies the event creation interface, even if the event name itself is unused on windows, allowing use the exact same code to initialize events regardless of the actual platform. Some ifdefs still remain in the event initialization code, since some events are only used on windows.
--- a/codec/common/WelsThreadLib.cpp
+++ b/codec/common/WelsThreadLib.cpp
@@ -91,7 +91,7 @@
return WELS_THREAD_ERROR_OK;
}
-WELS_THREAD_ERROR_CODE WelsEventInit (WELS_EVENT* event) {
+WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT* event, const char* event_name) {
WELS_EVENT h = CreateEvent (NULL, FALSE, FALSE, NULL);
if (h == NULL) {
@@ -126,7 +126,7 @@
return WaitForMultipleObjects (nCount, event_list, TRUE, INFINITE);
}
-WELS_THREAD_ERROR_CODE WelsEventDestroy (WELS_EVENT* event) {
+WELS_THREAD_ERROR_CODE WelsEventClose (WELS_EVENT* event, const char* event_name) {
CloseHandle (*event);
*event = NULL;
--- a/codec/common/WelsThreadLib.h
+++ b/codec/common/WelsThreadLib.h
@@ -105,12 +105,8 @@
WELS_THREAD_ERROR_CODE WelsMutexUnlock (WELS_MUTEX* mutex);
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 WelsEventClose (WELS_EVENT* event, const char* event_name);
-#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);
WELS_THREAD_ERROR_CODE WelsEventWait (WELS_EVENT* event);
WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t dwMilliseconds);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -43,11 +43,11 @@
#include <assert.h>
#if !defined(_WIN32)
#include <semaphore.h>
+#endif//!_WIN32
#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//!_WIN32
#include "slice_multi_threading.h"
#include "mt_defs.h"
#include "nal_encap.h"
@@ -352,10 +352,8 @@
iIdx = 0;
while (iIdx < iThreadNum) {
-#if !defined(_WIN32) // for posix threading
char name[SEM_NAME_MAX] = {0};
WELS_THREAD_ERROR_CODE err = 0;
-#endif//!_WIN32
pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) (*ppCtx);
pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx;
pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx;
@@ -362,13 +360,17 @@
pSmt->pThreadHandles[iIdx] = 0;
#ifdef _WIN32
- WelsEventInit (&pSmt->pUpdateMbListEvent[iIdx]);
- WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]);
- WelsEventInit (&pSmt->pSliceCodedEvent[iIdx]);
- WelsEventInit (&pSmt->pReadySliceCodingEvent[iIdx]);
- WelsEventInit (&pSmt->pFinSliceCodingEvent[iIdx]);
- WelsEventInit (&pSmt->pExitEncodeEvent[iIdx]);
-#else
+ WelsSnprintf (name, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx));
+ err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name);
+#if defined(ENABLE_TRACE_MT)
+ WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
+#endif
+ WelsSnprintf (name, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx));
+ err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name);
+#if defined(ENABLE_TRACE_MT)
+ WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
+#endif
+#endif//_WIN32
// length of semaphore name should be system constrained at least on mac 10.7
WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
@@ -391,7 +393,6 @@
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
(void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
#endif
-#endif//_WIN32
++ iIdx;
}
@@ -457,25 +458,17 @@
return;
while (iIdx < iThreadNum) {
+ char ename[SEM_NAME_MAX] = {0};
+ // length of semaphore name should be system constrained at least on mac 10.7
#ifdef _WIN32
if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL)
WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]);
- if (pSmt->pSliceCodedEvent != NULL)
- WelsEventDestroy (&pSmt->pSliceCodedEvent[iIdx]);
- if (pSmt->pReadySliceCodingEvent != NULL)
- WelsEventDestroy (&pSmt->pReadySliceCodingEvent[iIdx]);
- if (pSmt->pFinSliceCodingEvent != NULL)
- WelsEventDestroy (&pSmt->pFinSliceCodingEvent[iIdx]);
- if (pSmt->pExitEncodeEvent != NULL)
- WelsEventDestroy (&pSmt->pExitEncodeEvent[iIdx]);
- if (pSmt->pUpdateMbListEvent != NULL)
- WelsEventDestroy (&pSmt->pUpdateMbListEvent[iIdx]);
- if (pSmt->pFinUpdateMbListEvent != NULL)
- WelsEventDestroy (&pSmt->pFinUpdateMbListEvent[iIdx]);
-#else
- 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, "fs%d%p", iIdx, (void*) (*ppCtx));
+ WelsEventClose (&pSmt->pFinSliceCodingEvent[iIdx], ename);
+ WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx));
+ WelsEventClose (&pSmt->pExitEncodeEvent[iIdx], ename);
+#endif//_WIN32
WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename);
WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
@@ -484,7 +477,6 @@
WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename);
WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename);
-#endif//_WIN32
++ iIdx;
}