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.
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 3 files). Show all
Unified · Split
| @@ -43,11 +43,11 @@ · 42 unmodified lines | |||
| 43 | #include <assert.h> | 43 | #include <assert.h> |
| 44 | #if !defined(_WIN32) | 44 | #if !defined(_WIN32) |
| 45 | #include <semaphore.h> | 45 | #include <semaphore.h> |
| 46 | #endif//!_WIN32 | ||
| 46 | #ifndef SEM_NAME_MAX | 47 | #ifndef SEM_NAME_MAX |
| 47 | // length of semaphore name should be system constrained at least on mac 10.7 | 48 | // length of semaphore name should be system constrained at least on mac 10.7 |
| 48 | #define SEM_NAME_MAX 32 | 49 | #define SEM_NAME_MAX 32 |
| 49 | #endif//SEM_NAME_MAX | 50 | #endif//SEM_NAME_MAX |
| 50 | #endif//!_WIN32 | ||
| 51 | #include "slice_multi_threading.h" | 51 | #include "slice_multi_threading.h" |
| 52 | #include "mt_defs.h" | 52 | #include "mt_defs.h" |
| 53 | #include "nal_encap.h" | 53 | #include "nal_encap.h" |
| @@ -352,23 +352,25 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 298 unmodified lines | |||
| 352 | 352 | ||
| 353 | iIdx = 0; | 353 | iIdx = 0; |
| 354 | while (iIdx < iThreadNum) { | 354 | while (iIdx < iThreadNum) { |
| 355 | #if !defined(_WIN32) // for posix threading | ||
| 356 | char name[SEM_NAME_MAX] = {0}; | 355 | char name[SEM_NAME_MAX] = {0}; |
| 357 | WELS_THREAD_ERROR_CODE err = 0; | 356 | WELS_THREAD_ERROR_CODE err = 0; |
| 358 | #endif//!_WIN32 | ||
| 359 | pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) (*ppCtx); | 357 | pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) (*ppCtx); |
| 360 | pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx; | 358 | pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx; |
| 361 | pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; | 359 | pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; |
| 362 | pSmt->pThreadHandles[iIdx] = 0; | 360 | pSmt->pThreadHandles[iIdx] = 0; |
| 363 | 361 | ||
| 364 | #ifdef _WIN32 | 362 | #ifdef _WIN32 |
| 365 | WelsEventInit (&pSmt->pUpdateMbListEvent[iIdx]); | 363 | WelsSnprintf (name, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx)); |
| 366 | WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]); | 364 | err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name); |
| 367 | WelsEventInit (&pSmt->pSliceCodedEvent[iIdx]); | 365 | #if defined(ENABLE_TRACE_MT) |
| 368 | WelsEventInit (&pSmt->pReadySliceCodingEvent[iIdx]); | 366 | WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno); |
| 369 | WelsEventInit (&pSmt->pFinSliceCodingEvent[iIdx]); | 367 | #endif |
| 370 | WelsEventInit (&pSmt->pExitEncodeEvent[iIdx]); | 368 | WelsSnprintf (name, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx)); |
| 371 | #else | 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 | ||
| 372 | // length of semaphore name should be system constrained at least on mac 10.7 | 374 | // length of semaphore name should be system constrained at least on mac 10.7 |
| 373 | WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); | 375 | WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx)); |
| 374 | err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name); | 376 | err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name); |
| @@ -391,7 +393,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 16 unmodified lines | |||
| 391 | WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx, | 393 | WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx, |
| 392 | (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); | 394 | (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); |
| 393 | #endif | 395 | #endif |
| 394 | #endif//_WIN32 | ||
| 395 | 396 | ||
| 396 | ++ iIdx; | 397 | ++ iIdx; |
| 397 | } | 398 | } |
| @@ -457,25 +458,17 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 59 unmodified lines | |||
| 457 | return; | 458 | return; |
| 458 | 459 | ||
| 459 | while (iIdx < iThreadNum) { | 460 | 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 | ||
| 460 | #ifdef _WIN32 | 463 | #ifdef _WIN32 |
| 461 | if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL) | 464 | if (pSmt->pThreadHandles != NULL && pSmt->pThreadHandles[iIdx] != NULL) |
| 462 | WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]); | 465 | WelsThreadDestroy (&pSmt->pThreadHandles[iIdx]); |
| 463 | 466 | ||
| 464 | if (pSmt->pSliceCodedEvent != NULL) | 467 | WelsSnprintf (ename, SEM_NAME_MAX, "fs%d%p", iIdx, (void*) (*ppCtx)); |
| 465 | WelsEventDestroy (&pSmt->pSliceCodedEvent[iIdx]); | 468 | WelsEventClose (&pSmt->pFinSliceCodingEvent[iIdx], ename); |
| 466 | if (pSmt->pReadySliceCodingEvent != NULL) | 469 | WelsSnprintf (ename, SEM_NAME_MAX, "ee%d%p", iIdx, (void*) (*ppCtx)); |
| 467 | WelsEventDestroy (&pSmt->pReadySliceCodingEvent[iIdx]); | 470 | WelsEventClose (&pSmt->pExitEncodeEvent[iIdx], ename); |
| 468 | if (pSmt->pFinSliceCodingEvent != NULL) | 471 | #endif//_WIN32 |
| 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 | ||
| 479 | WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); | 472 | WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx)); |
| 480 | WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename); | 473 | WelsEventClose (&pSmt->pSliceCodedEvent[iIdx], ename); |
| 481 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); | 474 | WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx)); |
| @@ -484,7 +477,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 2 unmodified lines | |||
| 484 | WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename); | 477 | WelsEventClose (&pSmt->pUpdateMbListEvent[iIdx], ename); |
| 485 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); | 478 | WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx)); |
| 486 | WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename); | 479 | WelsEventClose (&pSmt->pFinUpdateMbListEvent[iIdx], ename); |
| 487 | #endif//_WIN32 | ||
| 488 | 480 | ||
| 489 | ++ iIdx; | 481 | ++ iIdx; |
| 490 | } | 482 | } |