From: Wander Lairson Costa Date: Tue, 22 Sep 2020 15:15:34 +0000 (-0300) Subject: Replace POSIX unnamed semaphores by dali-core primitives X-Git-Tag: dali_2.0.8~2^2~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=ab6cbfee8350d766373eb77adb9ea512ba18343a Replace POSIX unnamed semaphores by dali-core primitives POSIX unnamed semaphores are not implemented in macOS, making the initialization of the main thread and the render thread racy. Change-Id: I897604104645ab4c68ad6ebe219eda3b06060046 --- diff --git a/dali/internal/adaptor/common/combined-update-render-controller.cpp b/dali/internal/adaptor/common/combined-update-render-controller.cpp index a0f690e..818b4f0 100644 --- a/dali/internal/adaptor/common/combined-update-render-controller.cpp +++ b/dali/internal/adaptor/common/combined-update-render-controller.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "dali/public-api/common/dali-common.h" // INTERNAL INCLUDES #include @@ -92,9 +93,8 @@ const unsigned int MAXIMUM_UPDATE_REQUESTS = 2; CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions, ThreadMode threadMode ) : mFpsTracker( environmentOptions ), mUpdateStatusLogger( environmentOptions ), - mEventThreadSemaphore(), - mGraphicsInitializeSemaphore(), - mSurfaceSemaphore(), + mEventThreadSemaphore(0), + mSurfaceSemaphore(0), mUpdateRenderThreadWaitCondition(), mAdaptorInterfaces( adaptorInterfaces ), mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ), @@ -137,11 +137,6 @@ CombinedUpdateRenderController::CombinedUpdateRenderController( AdaptorInternalS } mSleepTrigger = TriggerEventFactory::CreateTriggerEvent( MakeCallback( this, &CombinedUpdateRenderController::ProcessSleepRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER ); - - // Initialize to 0 so that it just waits if sem_post has not been called - sem_init( &mEventThreadSemaphore, 0, 0 ); - sem_init( &mGraphicsInitializeSemaphore, 0, 0 ); - sem_init( &mSurfaceSemaphore, 0, 0 ); } CombinedUpdateRenderController::~CombinedUpdateRenderController() @@ -162,6 +157,7 @@ void CombinedUpdateRenderController::Initialize() DALI_ASSERT_ALWAYS( ! mUpdateRenderThread ); // Create Update/Render Thread + ConditionalWait::ScopedLock lock(mGraphicsInitializeWait); mUpdateRenderThread = new pthread_t(); int error = pthread_create( mUpdateRenderThread, NULL, InternalUpdateRenderThreadEntryFunc, this ); DALI_ASSERT_ALWAYS( !error && "Return code from pthread_create() when creating UpdateRenderThread" ); @@ -179,7 +175,7 @@ void CombinedUpdateRenderController::Start() // Wait until all threads created in Initialise are up and running for( unsigned int i = 0; i < CREATED_THREAD_COUNT; ++i ) { - sem_wait( &mEventThreadSemaphore ); + mEventThreadSemaphore.Acquire(); } Dali::RenderSurfaceInterface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface(); @@ -321,7 +317,7 @@ void CombinedUpdateRenderController::ReplaceSurface( Dali::RenderSurfaceInterfac } // Wait until the surface has been replaced - sem_wait( &mSurfaceSemaphore ); + mSurfaceSemaphore.Acquire(); LOG_EVENT( "Surface replaced, event-thread continuing" ); } @@ -344,7 +340,7 @@ void CombinedUpdateRenderController::DeleteSurface( Dali::RenderSurfaceInterface } // Wait until the surface has been deleted - sem_wait( &mSurfaceSemaphore ); + mSurfaceSemaphore.Acquire(); LOG_EVENT( "Surface deleted, event-thread continuing" ); } @@ -352,6 +348,7 @@ void CombinedUpdateRenderController::DeleteSurface( Dali::RenderSurfaceInterface void CombinedUpdateRenderController::WaitForGraphicsInitialization() { + ConditionalWait::ScopedLock lk(mGraphicsInitializeWait); LOG_EVENT_TRACE; if( mUpdateRenderThread ) @@ -359,7 +356,7 @@ void CombinedUpdateRenderController::WaitForGraphicsInitialization() LOG_EVENT( "Waiting for graphics initialisation, event-thread blocked" ); // Wait until the graphics has been initialised - sem_wait( &mGraphicsInitializeSemaphore ); + mGraphicsInitializeWait.Wait(lk); LOG_EVENT( "graphics initialised, event-thread continuing" ); } @@ -944,7 +941,7 @@ Dali::RenderSurfaceInterface* CombinedUpdateRenderController::ShouldSurfaceBeRep void CombinedUpdateRenderController::SurfaceReplaced() { // Just increment the semaphore - sem_post( &mSurfaceSemaphore ); + mSurfaceSemaphore.Release(1); } Dali::RenderSurfaceInterface* CombinedUpdateRenderController::ShouldSurfaceBeDeleted() @@ -960,7 +957,7 @@ Dali::RenderSurfaceInterface* CombinedUpdateRenderController::ShouldSurfaceBeDel void CombinedUpdateRenderController::SurfaceDeleted() { // Just increment the semaphore - sem_post( &mSurfaceSemaphore ); + mSurfaceSemaphore.Release(1); } bool CombinedUpdateRenderController::ShouldSurfaceBeResized() @@ -982,12 +979,12 @@ void CombinedUpdateRenderController::SurfaceResized() void CombinedUpdateRenderController::NotifyThreadInitialised() { // Just increment the semaphore - sem_post( &mEventThreadSemaphore ); + mEventThreadSemaphore.Release(1); } void CombinedUpdateRenderController::NotifyGraphicsInitialised() { - sem_post( &mGraphicsInitializeSemaphore ); + mGraphicsInitializeWait.Notify(); } void CombinedUpdateRenderController::AddPerformanceMarker( PerformanceInterface::MarkerType type ) diff --git a/dali/internal/adaptor/common/combined-update-render-controller.h b/dali/internal/adaptor/common/combined-update-render-controller.h index c87a1a6..8c2da95 100644 --- a/dali/internal/adaptor/common/combined-update-render-controller.h +++ b/dali/internal/adaptor/common/combined-update-render-controller.h @@ -24,6 +24,7 @@ #include #include #include +#include #include // INTERNAL INCLUDES @@ -343,9 +344,9 @@ private: FpsTracker mFpsTracker; ///< Object that tracks the FPS UpdateStatusLogger mUpdateStatusLogger; ///< Object that logs the update-status as required. - sem_t mEventThreadSemaphore; ///< Used by the event thread to ensure all threads have been initialised. - sem_t mGraphicsInitializeSemaphore; ///< Used by the render thread to ensure the graphics has been initialised. - sem_t mSurfaceSemaphore; ///< Used by the event thread to ensure the surface has been deleted or replaced. + Semaphore<> mEventThreadSemaphore; ///< Used by the event thread to ensure all threads have been initialised, and when replacing the surface. + ConditionalWait mGraphicsInitializeWait; ///< Used by the render thread to ensure the graphics has been initialised. + Semaphore<> mSurfaceSemaphore; ///< Used by the event thread to ensure the surface has been deleted or replaced. ConditionalWait mUpdateRenderThreadWaitCondition; ///< The wait condition for the update-render-thread.