std::mutex atostrBufIndexMutex;
std::uint32_t atostrBufIndex;
+ std::mutex setThreadedUpdateMutex;
+
}; // struct Context
Context *verifyContext(UDPC_HContext ctx);
threadedSleepTime(std::chrono::milliseconds(UDPC_UPDATE_MS_DEFAULT)),
keysSet(),
atostrBufIndexMutex(),
-atostrBufIndex(0)
+atostrBufIndex(0),
+setThreadedUpdateMutex()
{
std::memset(atostrBuf, 0, UDPC_ATOSTR_SIZE);
int UDPC_enable_threaded_update(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || c->isAutoUpdating.load() || c->thread.joinable()) {
+ if (!c) {
+ return 0;
+ }
+
+ std::lock_guard<std::mutex> setThreadedLock(c->setThreadedUpdateMutex);
+
+ if(c->isAutoUpdating.load() || c->thread.joinable()) {
return 0;
}
int UDPC_enable_threaded_update_ms(UDPC_HContext ctx, int updateMS) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || c->isAutoUpdating.load() || c->thread.joinable()) {
+ if (!c) {
+ return 0;
+ }
+
+ std::lock_guard<std::mutex> setThreadedLock(c->setThreadedUpdateMutex);
+
+ if(c->isAutoUpdating.load() || c->thread.joinable()) {
return 0;
}
int UDPC_disable_threaded_update(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || !c->isAutoUpdating.load() || !c->thread.joinable()) {
+ if (!c) {
+ return 0;
+ }
+
+ std::lock_guard<std::mutex> setThreadedLock(c->setThreadedUpdateMutex);
+
+ if(!c->isAutoUpdating.load() || !c->thread.joinable()) {
return 0;
}