fix device_data race condition with mutex

pull/1322/head
Etaash Mathamsetty 2 weeks ago committed by flightlessmango
parent 44eb25e10e
commit 0e92ec4790

@ -6,6 +6,7 @@
namespace fs = ghc::filesystem;
using namespace std;
std::mutex device_lock;
std::vector<device_batt> device_data;
std::vector<std::string> list;
bool device_found = false;
@ -28,6 +29,7 @@ static bool operator<(const device_batt& a, const device_batt& b)
void device_update(const struct overlay_params& params){
std::unique_lock<std::mutex> l(device_lock);
fs::path path("/sys/class/power_supply");
list.clear();
xbox_count = 0;
@ -87,6 +89,7 @@ void device_update(const struct overlay_params& params){
void device_info () {
device_count = 0;
std::unique_lock<std::mutex> l(device_lock);
device_data.clear();
//gamepad counters
int xbox_counter = 0;

@ -14,6 +14,7 @@ struct device_batt {
};
extern std::vector<device_batt> device_data;
extern std::mutex device_lock;
extern bool device_found;
extern int device_count;

@ -1144,6 +1144,7 @@ void HudElements::gamescope_frame_timing(){
void HudElements::device_battery()
{
#ifdef __linux__
std::unique_lock<std::mutex> l(device_lock);
if (!HUDElements.params->device_battery.empty()) {
if (device_found) {
for (int i = 0; i < device_count; i++) {

Loading…
Cancel
Save