Use an event name that contains the process id
This reduces the risk for namespace collisions if two processes run the encoder simultaneously without address space layout randomization.
This commit is contained in:
parent
4814d5828d
commit
d4bdef2916
@ -91,6 +91,7 @@ int32_t iEndMbIndex; // exclusive
|
||||
|
||||
typedef struct TagSliceThreading {
|
||||
SSliceThreadPrivateData* pThreadPEncCtx;// thread context, [iThreadIdx]
|
||||
char eventNamespace[100];
|
||||
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]
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <assert.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <semaphore.h>
|
||||
#include <unistd.h>
|
||||
#endif//!_WIN32
|
||||
#ifndef SEM_NAME_MAX
|
||||
// length of semaphore name should be system constrained at least on mac 10.7
|
||||
@ -317,6 +318,13 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
||||
"pThreadPEncCtx");
|
||||
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx))
|
||||
|
||||
#ifdef _WIN32
|
||||
// Dummy event namespace, the windows events don't actually use this
|
||||
WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p", (void*) (*ppCtx));
|
||||
#else
|
||||
WelsSnprintf (pSmt->eventNamespace, sizeof(pSmt->eventNamespace), "%p%x", (void*) (*ppCtx), getpid());
|
||||
#endif//!_WIN32
|
||||
|
||||
iIdx = 0;
|
||||
while (iIdx < iNumSpatialLayers) {
|
||||
SSliceConfig* pMso = &pPara->sDependencyLayers[iIdx].sSliceCfg;
|
||||
@ -360,34 +368,34 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
||||
pSmt->pThreadHandles[iIdx] = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace);
|
||||
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));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace);
|
||||
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));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace);
|
||||
err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
|
||||
#if defined(ENABLE_TRACE_MT)
|
||||
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
|
||||
#endif
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace);
|
||||
err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
|
||||
#if defined(ENABLE_TRACE_MT)
|
||||
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
|
||||
#endif
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace);
|
||||
err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
|
||||
#if defined(ENABLE_TRACE_MT)
|
||||
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
|
||||
#endif
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (name, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace);
|
||||
err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name);
|
||||
#if defined(ENABLE_TRACE_MT)
|
||||
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
|
||||
@ -464,18 +472,18 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) {
|
||||
if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL)
|
||||
WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]);
|
||||
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pFinSliceCodingEvent[iIdx], ename);
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pExitEncodeEvent[iIdx], ename);
|
||||
#endif//_WIN32
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename);
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pReadySliceCodingEvent[iIdx], ename);
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename);
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
|
||||
WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace);
|
||||
WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename);
|
||||
|
||||
++ iIdx;
|
||||
|
Loading…
Reference in New Issue
Block a user