From 573a01212bf5b27a97f25689b8a608a98c4498c0 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Sun, 14 Jul 2019 20:51:23 +0200 Subject: [PATCH] Switch to atomic_bool for thread synchronisation. --- dll/item_db_loader.cpp | 4 ++-- dll/item_db_loader.h | 3 ++- dll/steam_inventory.h | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dll/item_db_loader.cpp b/dll/item_db_loader.cpp index 69660b4..4e27e55 100644 --- a/dll/item_db_loader.cpp +++ b/dll/item_db_loader.cpp @@ -17,9 +17,9 @@ #include "item_db_loader.h" #include -#include "json.hpp" +#include "../json/json.hpp" -void read_items_db(std::string items_db, std::map> *items, bool *is_loadedb) +void read_items_db(std::string items_db, std::map> *items, std::atomic_bool *is_loadedb) { std::ifstream items_file(items_db); // If there is a file and we opened it diff --git a/dll/item_db_loader.h b/dll/item_db_loader.h index 6d78509..89c0912 100644 --- a/dll/item_db_loader.h +++ b/dll/item_db_loader.h @@ -18,6 +18,7 @@ #include "base.h" // For SteamItemDef_t -void read_items_db(std::string items_db, std::map> *items, bool *is_loaded); +#include +void read_items_db(std::string items_db, std::map> *items, std::atomic_bool *is_loaded); #endif//__ITEM_DB_LOADER_INCLUDED__ \ No newline at end of file diff --git a/dll/steam_inventory.h b/dll/steam_inventory.h index ea583f0..bdf9c9e 100644 --- a/dll/steam_inventory.h +++ b/dll/steam_inventory.h @@ -16,6 +16,7 @@ . */ #include "item_db_loader.h" +#include struct Steam_Inventory_Requests { double timeout = 0.1; @@ -57,7 +58,7 @@ class Steam_Inventory : // Or find a server somewhere to hold the data for us then cache on local settings. bool need_load_definitions = true; - bool items_loaded = false; + std::atomic_bool items_loaded = false; struct Steam_Inventory_Requests* new_inventory_result(const SteamItemInstanceID_t* pInstanceIDs = NULL, uint32 unCountInstanceIDs = 0) { @@ -90,7 +91,7 @@ public: Steam_Inventory(class Settings *settings, class SteamCallResults *callback_results, class SteamCallBacks *callbacks) { - std::thread items_load_thread(read_items_db, Local_Storage::get_program_path() + PATH_SEPARATOR + "steam_items.json", &items, &items_loaded); + std::thread items_load_thread(read_items_db, Local_Storage::get_game_settings_path() + PATH_SEPARATOR + "items.json", &items, &items_loaded); items_load_thread.detach(); this->settings = settings;