diff --git a/VERSION b/VERSION index dc7ca5ee..afdbd993 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B2-rc2-25-g3511fb8d59+1 \ No newline at end of file +B2-rc2-28-g19c2fe9b5e+1 \ No newline at end of file diff --git a/client/src/main.c b/client/src/main.c index 5b2f3447..2c1bd70f 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -34,6 +34,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include #if SDL_VIDEO_DRIVER_X11_XINPUT2 // because SDL2 sucks and we need to turn it off @@ -69,6 +70,8 @@ static LGThread *t_cursor = NULL; static LGThread *t_frame = NULL; static SDL_Cursor *cursor = NULL; +static atomic_uint a_framesPending = 0; + struct AppState state; // this structure is initialized in config.c @@ -193,12 +196,12 @@ static int renderThread(void * unused) if (state.renderTime > 1e9) { - const float avgUPS = 1000.0f / (((float)state.renderTime / state.frameCount ) / 1e6f); + const float avgUPS = 1000.0f / (((float)state.renderTime / atomic_load_explicit(&state.frameCount, memory_order_acquire)) / 1e6f); const float avgFPS = 1000.0f / (((float)state.renderTime / state.renderCount) / 1e6f); state.lgr->update_fps(state.lgrData, avgUPS, avgFPS); + atomic_store_explicit(&state.frameCount, 0, memory_order_release); state.renderTime = 0; - state.frameCount = 0; state.renderCount = 0; } } @@ -214,7 +217,14 @@ static int renderThread(void * unused) } if (state.frameTime > 0) + { + /* if there are frames pending already, don't wait on the event */ + if (atomic_load_explicit(&a_framesPending, memory_order_acquire) > 0) + if (atomic_fetch_sub_explicit(&a_framesPending, 1, memory_order_release) > 1) + continue; + lgWaitEventAbs(e_frame, &time); + } } state.running = false; @@ -447,10 +457,12 @@ static int frameThread(void * unused) DEBUG_ERROR("renderer on frame event returned failure"); break; } - lgmpClientMessageDone(queue); - ++state.frameCount; - lgSignalEvent(e_frame); + atomic_fetch_add_explicit(&state.frameCount, 1, memory_order_relaxed); + if (atomic_fetch_add_explicit(&a_framesPending, 1, memory_order_relaxed) == 0) + lgSignalEvent(e_frame); + + lgmpClientMessageDone(queue); } lgmpClientUnsubscribe(&queue); diff --git a/client/src/main.h b/client/src/main.h index d586187c..ff5bc67c 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -18,6 +18,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include "interface/app.h" @@ -75,11 +76,11 @@ struct AppState PLGMPClientQueue frameQueue; PLGMPClientQueue pointerQueue; - uint64_t frameTime; - uint64_t lastFrameTime; - uint64_t renderTime; - uint64_t frameCount; - uint64_t renderCount; + atomic_uint_least64_t frameTime; + uint64_t lastFrameTime; + uint64_t renderTime; + uint64_t frameCount; + uint64_t renderCount; uint64_t resizeTimeout;