Skip to content

Commit

Permalink
steamcompmgr, wlserver: fix various data races found w/ thread sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkautarch committed Sep 1, 2024
1 parent d4ca0b9 commit 387113d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ float focusedWindowScaleY = 1.0f;
float focusedWindowOffsetX = 0.0f;
float focusedWindowOffsetY = 0.0f;

uint32_t inputCounter;
std::atomic<uint32_t> inputCounter;
uint32_t lastPublishedInputCounter;

std::atomic<bool> hasRepaint = false;
Expand Down Expand Up @@ -1432,9 +1432,8 @@ void MouseCursor::checkSuspension()
if ( ShouldDrawCursor() )
{
const bool suspended = int64_t( get_time_in_nanos() ) - int64_t( wlserver.ulLastMovedCursorTime ) > int64_t( cursorHideTime );
if (!wlserver.bCursorHidden && suspended) {
wlserver.bCursorHidden = true;

const bool bCursorWasHidden = suspended ? wlserver.bCursorHidden.exchange(true) : wlserver.bCursorHidden.load();
if (!bCursorWasHidden && suspended) {
steamcompmgr_win_t *window = m_ctx->focus.inputFocusWindow;
// Rearm warp count
if (window)
Expand Down Expand Up @@ -7518,12 +7517,12 @@ steamcompmgr_main(int argc, char **argv)

bool flush_root = false;

if ( inputCounter != lastPublishedInputCounter )
if ( auto currentInputCount = inputCounter.load(); currentInputCount != lastPublishedInputCounter )
{
XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeInputCounterAtom, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&inputCounter, 1 );
(unsigned char *)&currentInputCount, 1 );

lastPublishedInputCounter = inputCounter;
lastPublishedInputCounter = currentInputCount;
flush_root = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/steamcompmgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extern float focusedWindowOffsetY;

extern bool g_bFSRActive;

extern uint32_t inputCounter;
extern std::atomic<uint32_t> inputCounter;
extern uint64_t g_lastWinSeq;

void nudge_steamcompmgr( void );
Expand Down
4 changes: 2 additions & 2 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,9 +2168,9 @@ void wlserver_notify_dropdown( struct wlr_surface *wlrsurface, int nX, int nY )
void wlserver_mousehide()
{
wlserver.ulLastMovedCursorTime = 0;
if ( wlserver.bCursorHidden != true )
const bool bCursorWasHidden = wlserver.bCursorHidden.exchange(true);
if ( bCursorWasHidden != true )
{
wlserver.bCursorHidden = true;
hasRepaint = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/wlserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ struct wlserver_t {
return mouse_constraint.load( std::memory_order_relaxed ) != nullptr;
}

uint64_t ulLastMovedCursorTime = 0;
bool bCursorHidden = true;
bool bCursorHasImage = true;
std::atomic<uint64_t> ulLastMovedCursorTime = 0;
std::atomic<bool> bCursorHidden = true;
std::atomic<bool> bCursorHasImage = true;

bool button_held[ WLSERVER_BUTTON_COUNT ];
std::set <uint32_t> touch_down_ids;
Expand Down

0 comments on commit 387113d

Please sign in to comment.