diff --git a/src/main.cpp b/src/main.cpp index fef62ee908..33a498e49e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,6 @@ #include "sdlwindow.hpp" #include "wlserver.hpp" #include "gpuvis_trace_utils.h" -#include "steamcompmgr_shared.hpp" #if HAVE_OPENVR #include "vr_session.hpp" @@ -763,8 +762,8 @@ int main(int argc, char **argv) { fprintf( stderr, "Failed to initialize OpenVR runtime\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -775,8 +774,8 @@ int main(int argc, char **argv) { fprintf( stderr, "Failed to initialize output\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -786,8 +785,8 @@ int main(int argc, char **argv) if ( !SDL_Vulkan_CreateSurface( g_SDLWindow, instance, &surface ) ) { fprintf(stderr, "SDL_Vulkan_CreateSurface failed: %s", SDL_GetError() ); - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); return 1; } } @@ -798,8 +797,8 @@ int main(int argc, char **argv) { fprintf( stderr, "Failed to initialize Vulkan\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -808,8 +807,8 @@ int main(int argc, char **argv) { fprintf( stderr, "vulkan_init_formats failed\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -818,8 +817,8 @@ int main(int argc, char **argv) { fprintf( stderr, "vulkan_make_output failed\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -851,8 +850,8 @@ int main(int argc, char **argv) { fprintf( stderr, "Cannot specify -w without -h\n" ); if ( BIsSDLSession() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); } return 1; } @@ -865,16 +864,16 @@ int main(int argc, char **argv) { if ( !wlserver_init() ) { - sdl_latch = -1; - sdlLatchSem.signal(); + g_sdlLatch = 1; + g_sdlLatch.notify_one(); fprintf( stderr, "Failed to initialize wlserver\n" ); return 1; } else - sdl_latch |= 1; + g_sdlLatch = 1; - sdlLatchSem.signal(); + g_sdlLatch.notify_one(); } #if HAVE_OPENVR diff --git a/src/sdlwindow.cpp b/src/sdlwindow.cpp index d75c66454e..6e03ffde6c 100644 --- a/src/sdlwindow.cpp +++ b/src/sdlwindow.cpp @@ -108,8 +108,7 @@ extern bool g_bForceRelativeMouse; static std::string gamescope_str = DEFAULT_TITLE; -std::atomic sdl_latch = {0}; //sdl_latch to notify sdl thread when wl-server is fully initialized -sem sdlLatchSem; +std::atomic g_sdlLatch = {0}; //g_sdlLatch to notify sdl thread when wl-server is fully initialized void inputSDLThreadRun( void ) { @@ -184,28 +183,23 @@ void inputSDLThreadRun( void ) SDL_Surface *icon_surface = nullptr; SDL_Cursor *cursor = nullptr; - bool latch_cleared_successfully = true; { - int64_t sdl_latch_cached = sdl_latch.load(std::memory_order_relaxed); + bool sdlLatch_cached = g_sdlLatch.load(std::memory_order_relaxed); bool loop_done = false; while (!loop_done) { - if ( sdl_latch_cached == 0 && (sdl_latch_cached=sdl_latch.load()) == 0) - sdlLatchSem.wait(); + if ( sdlLatch_cached == 0 && (sdlLatch_cached=g_sdlLatch.load(std::memory_order_consume)) == 0) + g_sdlLatch.wait(0); - if ( (sdl_latch_cached = sdl_latch.load(std::memory_order_relaxed)) < 0 ) { - latch_cleared_successfully = false; - loop_done=true; - } - if ( sdl_latch_cached != 0 && sdl_latch.load() > 0) + if ( sdlLatch_cached != 0) loop_done=true; } } - while( latch_cleared_successfully && SDL_WaitEvent( &event ) ) + while( SDL_WaitEvent( &event ) ) { fake_timestamp++; diff --git a/src/sdlwindow.hpp b/src/sdlwindow.hpp index 5d7e6a902e..fbe10ac5ac 100644 --- a/src/sdlwindow.hpp +++ b/src/sdlwindow.hpp @@ -22,5 +22,4 @@ void sdlwindow_cursor(std::shared_ptr> pixels, uint32_t wi extern SDL_Window *g_SDLWindow; -extern std::atomic sdl_latch; //sdl_latch to notify sdl thread when wl-server is fully initialized -extern sem sdlLatchSem; \ No newline at end of file +extern std::atomic g_sdlLatch; //sdl_latch to notify sdl thread when wl-server is fully initialized \ No newline at end of file diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 9e5d2fd147..c24ba58bad 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -1106,7 +1106,32 @@ static std::atomic g_bForceRepaint{false}; static int g_nCursorScaleHeight = -1; +// poor man's semaphore +class sem +{ +public: + void wait( void ) + { + std::unique_lock lock(mtx); + + while(count == 0){ + cv.wait(lock); + } + count--; + } + void signal( void ) + { + std::unique_lock lock(mtx); + count++; + cv.notify_one(); + } + +private: + std::mutex mtx; + std::condition_variable cv; + int count = 0; +}; sem statsThreadSem; std::mutex statsEventQueueLock; diff --git a/src/steamcompmgr_shared.hpp b/src/steamcompmgr_shared.hpp index ab346b6230..7de514583d 100644 --- a/src/steamcompmgr_shared.hpp +++ b/src/steamcompmgr_shared.hpp @@ -4,39 +4,10 @@ #include #include #include "gamescope-control-protocol.h" -#include -#include struct commit_t; struct wlserver_vk_swapchain_feedback; -// poor man's semaphore -class sem -{ -public: - void wait( void ) - { - std::unique_lock lock(mtx); - - while(count == 0){ - cv.wait(lock); - } - count--; - } - - void signal( void ) - { - std::unique_lock lock(mtx); - count++; - cv.notify_one(); - } - -private: - std::mutex mtx; - std::condition_variable cv; - int count = 0; -}; - struct motif_hints_t { unsigned long flags;