Xpl0itU / savemii

Savegame manager for the Nintendo Wii U
GNU General Public License v3.0
73 stars 10 forks source link

[sugestion] tryWaitAndPop is not atomic #41

Open xenonymdotcom opened 1 year ago

xenonymdotcom commented 1 year ago

https://github.com/Xpl0itU/savemii/blob/987ff28fdfad9f1398a1759c24d5bd4bff1d604b/include/LockingQueue.h#L48 as it stands tryWaitAndPop will exit false on timeout or item inserted if the queue was empty when entered if the return was wrapped in an if queue.empty() cause and in fact the while is superfluious the code could be just if (queue.empty()) { signal.wait_for(lock, std::chrono::milliseconds(_milli)); if (queue.empty()) { return false; } } this would make the function atomic as the lock would not get released if you entered it when the queue was empty and an item was added, which as it stands could be consumed by another waiter.