From 5a7559e39d2cd8306a99adbc6d39e90716b14687 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 19 Dec 2024 22:48:41 -0500 Subject: Rewrote APState so connection happens on thread The whole file is more thread-safe than before, with a few notable exceptions. This fixes a read-after-free issue where, when reconnecting after a disconnection, the client thread would attempt to lock a mutex owned and already destroyed by the main thread. --- src/ap_state.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ap_state.h') diff --git a/src/ap_state.h b/src/ap_state.h index f310ee8..a23b13d 100644 --- a/src/ap_state.h +++ b/src/ap_state.h @@ -51,8 +51,13 @@ bool AP_HasCheckedGameLocation(int location_id); bool AP_HasCheckedHuntPanel(int location_id); +// This doesn't lock the state mutex, for speed, so it must ONLY be called from +// RecalculateReachability, which is only called from the APState thread anyway. bool AP_HasItem(int item_id, int quantity = 1); +// This doesn't lock the client mutex because it is ONLY to be called from +// RecalculateReachability, which is only called from within a client callback +// anyway. std::string AP_GetItemName(int item_id); DoorShuffleMode AP_GetDoorShuffleMode(); @@ -63,10 +68,12 @@ bool AP_IsColorShuffle(); bool AP_IsPaintingShuffle(); +// WARNING: Not thread-safe! const std::map& AP_GetPaintingMapping(); bool AP_IsPaintingMappedTo(const std::string& painting_id); +// WARNING: Not thread-safe! const std::set& AP_GetCheckedPaintings(); bool AP_IsPaintingChecked(const std::string& painting_id); @@ -93,6 +100,7 @@ SunwarpAccess AP_GetSunwarpAccess(); bool AP_IsSunwarpShuffle(); +// WARNING: Not thread-safe! const std::map& AP_GetSunwarpMapping(); bool AP_HasReachedGoal(); -- cgit 1.4.1