From 29ded2483cb6cca8bae387b98e4d495fe718bfe0 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 15 Mar 2022 23:46:02 +0100 Subject: [PATCH] sys: Make sure deferred call adding is thread safe --- lib/libimhex/source/api/imhex_api.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index e5071e477..3a4a17c58 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -172,15 +172,17 @@ namespace hex { return { unlocalizedName, maxValue }; } - - std::vector> s_deferredCalls; - void doLater(const std::function &function) { + static std::mutex tasksMutex; + std::scoped_lock lock(tasksMutex); + getDeferredCalls().push_back(function); } std::vector> &getDeferredCalls() { - return s_deferredCalls; + static std::vector> deferredCalls; + + return deferredCalls; } }