[PR #710] [CLOSED] Make AvPlayerQueue size atomic #1730

Closed
opened 2026-02-27 21:13:44 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/710
Author: @OFFTKP
Created: 9/1/2024
Status: Closed

Base: mainHead: as


📝 Commits (1)

  • 0be9ebc Make AvPlayerQueue size atomic

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 src/core/libraries/avplayer/avplayer_common.h (+8 -1)

📄 Description

std::queue::size is not thread safe, and also

if (Size() == 0) {
    return std::nullopt;
}
std::lock_guard guard(m_mutex);
auto result = std::move(m_queue.front());
m_queue.pop();

doesn't look thread safe, because the Size() == 0 check can be false, but before the mutex is locked a different thread pops an element or clears the queue making size 0, which leads to UB

Added another size check after locking the mutex instead of locking it at the start of the function, so that Pop doesn't unconditionally lock but it also doesn't try to pop from an empty queue


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/710 **Author:** [@OFFTKP](https://github.com/OFFTKP) **Created:** 9/1/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `as` --- ### 📝 Commits (1) - [`0be9ebc`](https://github.com/shadps4-emu/shadPS4/commit/0be9ebcdce6f38a19bfdf08a6fcab134d3fcce1a) Make AvPlayerQueue size atomic ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/core/libraries/avplayer/avplayer_common.h` (+8 -1) </details> ### 📄 Description std::queue::size is not thread safe, and also ```cpp if (Size() == 0) { return std::nullopt; } std::lock_guard guard(m_mutex); auto result = std::move(m_queue.front()); m_queue.pop(); ``` doesn't look thread safe, because the Size() == 0 check can be false, but before the mutex is locked a different thread pops an element or clears the queue making size 0, which leads to UB Added another size check after locking the mutex instead of locking it at the start of the function, so that Pop doesn't unconditionally lock but it also doesn't try to pop from an empty queue --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:13:44 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#1730
No description provided.