History

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.

Martin Storsjö committed 12 years ago

Commit 5480ffa1 parent adb27ff3 files · +21 −33Browse files

Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 3 files). Show all

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+19−27
@@ -43,11 +43,11 @@ · 42 unmodified lines
4343 #include <assert.h>
4444 #if !defined(_WIN32)
4545 #include <semaphore.h>
46+#endif//!_WIN32
4647 #ifndef SEM_NAME_MAX
4748 // length of semaphore name should be system constrained at least on mac 10.7
4849 #define SEM_NAME_MAX 32
4950 #endif//SEM_NAME_MAX
50−#endif//!_WIN32
5151 #include "slice_multi_threading.h"
5252 #include "mt_defs.h"
5353 #include "nal_encap.h"
@@ -352,23 +352,25 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 298 unmodified lines
352352
353353 iIdx = 0;
354354 while (iIdx < iThreadNum) {
355−#if !defined(_WIN32) // for posix threading
356355 char name[SEM_NAME_MAX] = {0};
357356 WELS_THREAD_ERROR_CODE err = 0;
358−#endif//!_WIN32
359357 pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) (*ppCtx);
360358 pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx;
361359 pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx;
362360 pSmt->pThreadHandles[iIdx] = 0;
363361
364362 #ifdef _WIN32
365− WelsEventInit (&pSmt->pUpdateMbListEvent[iIdx]);
366− WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]);
367− WelsEventInit (&pSmt->pSliceCodedEvent[iIdx]);
368− WelsEventInit (&pSmt->pReadySliceCodingEvent[iIdx]);
369− WelsEventInit (&pSmt->pFinSliceCodingEvent[iIdx]);
370− WelsEventInit (&pSmt->pExitEncodeEvent[iIdx]);
371−#else
363+ WelsSnprintf (name, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx));
364+ err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name);
365+#if defined(ENABLE_TRACE_MT)
366+ WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
367+#endif
368+ WelsSnprintf (name, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx));
369+ err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name);
370+#if defined(ENABLE_TRACE_MT)
371+ WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
372+#endif
373+#endif//_WIN32
372374 // length of semaphore name should be system constrained at least on mac 10.7
373375 WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
374376 err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
@@ -391,7 +393,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 16 unmodified lines
391393 WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
392394 (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
393395 #endif
394−#endif//_WIN32
395396
396397 ++ iIdx;
397398 }
@@ -457,25 +458,17 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 59 unmodified lines
457458 return;
458459
459460 while (iIdx < iThreadNum) {
461+ char ename[SEM_NAME_MAX] = {0};
462+ // length of semaphore name should be system constrained at least on mac 10.7
460463 #ifdef _WIN32
461464 if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL)
462465 WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]);
463466
464− if (pSmt->pSliceCodedEvent != NULL)
465− WelsEventDestroy (&pSmt->pSliceCodedEvent[iIdx]);
466− if (pSmt->pReadySliceCodingEvent != NULL)
467− WelsEventDestroy (&pSmt->pReadySliceCodingEvent[iIdx]);
468− if (pSmt->pFinSliceCodingEvent != NULL)
469− WelsEventDestroy (&pSmt->pFinSliceCodingEvent[iIdx]);
470− if (pSmt->pExitEncodeEvent != NULL)
471− WelsEventDestroy (&pSmt->pExitEncodeEvent[iIdx]);
472− if (pSmt->pUpdateMbListEvent != NULL)
473− WelsEventDestroy (&pSmt->pUpdateMbListEvent[iIdx]);
474− if (pSmt->pFinUpdateMbListEvent != NULL)
475− WelsEventDestroy (&pSmt->pFinUpdateMbListEvent[iIdx]);
476−#else
477− char ename[SEM_NAME_MAX] = {0};
478− // length of semaphore name should be system constrained at least on mac 10.7
467+ WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx));
468+ WelsEventClose (&pSmt->pFinSliceCodingEvent[iIdx], ename);
469+ WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx));
470+ WelsEventClose (&pSmt->pExitEncodeEvent[iIdx], ename);
471+#endif//_WIN32
479472 WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
480473 WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename);
481474 WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
@@ -484,7 +477,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 2 unmodified lines
484477 WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename);
485478 WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
486479 WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename);
487−#endif//_WIN32
488480
489481 ++ iIdx;
490482 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t