flags(),
isAcceptNewConnections(true),
isReceivingEvents(false),
+isAutoUpdating(false),
protocolID(UDPC_DEFAULT_PROTOCOL_ID),
#ifndef NDEBUG
loggingType(UDPC_DEBUG),
std::memset(atostrBuf, 0, UDPC_ATOSTR_SIZE);
if(isThreaded) {
- flags.set(0);
+ isAutoUpdating.store(true);
} else {
- flags.reset(0);
+ isAutoUpdating.store(false);
}
rng_engine.seed(std::chrono::system_clock::now().time_since_epoch().count());
return nullptr;
}
- ctx->flags.set(0);
+ ctx->isAutoUpdating.store(true);
ctx->threadedSleepTime = std::chrono::milliseconds(UDPC_UPDATE_MS_DEFAULT);
ctx->thread = std::thread(UDPC::threadedUpdate, ctx);
return nullptr;
}
- ctx->flags.set(0);
+ ctx->isAutoUpdating.store(true);
if(updateMS < UDPC_UPDATE_MS_MIN) {
ctx->threadedSleepTime = std::chrono::milliseconds(UDPC_UPDATE_MS_MIN);
} else if(updateMS > UDPC_UPDATE_MS_MAX) {
int UDPC_enable_threaded_update(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || c->flags.test(0) || c->thread.joinable()) {
+ if(!c || c->isAutoUpdating.load() || c->thread.joinable()) {
return 0;
}
- c->flags.set(0);
+ c->isAutoUpdating.store(true);
c->threadedSleepTime = std::chrono::milliseconds(UDPC_UPDATE_MS_DEFAULT);
c->threadRunning.store(true);
c->thread = std::thread(UDPC::threadedUpdate, c);
int UDPC_enable_threaded_update_ms(UDPC_HContext ctx, int updateMS) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || c->flags.test(0) || c->thread.joinable()) {
+ if(!c || c->isAutoUpdating.load() || c->thread.joinable()) {
return 0;
}
- c->flags.set(0);
+ c->isAutoUpdating.store(true);
if(updateMS < UDPC_UPDATE_MS_MIN) {
c->threadedSleepTime = std::chrono::milliseconds(UDPC_UPDATE_MS_MIN);
} else if(updateMS > UDPC_UPDATE_MS_MAX) {
int UDPC_disable_threaded_update(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || !c->flags.test(0) || !c->thread.joinable()) {
+ if(!c || !c->isAutoUpdating.load() || !c->thread.joinable()) {
return 0;
}
c->threadRunning.store(false);
c->thread.join();
- c->flags.reset(0);
+ c->isAutoUpdating.store(false);
UDPC_CHECK_LOG(c, UDPC_LoggingType::UDPC_INFO, "Stopped threaded update");
return 1;
UDPC::Context *UDPC_ctx = UDPC::verifyContext(ctx);
if(UDPC_ctx) {
// stop thread if threaded
- if(UDPC_ctx->flags.test(0)) {
+ if(UDPC_ctx->isAutoUpdating.load()) {
UDPC_ctx->threadRunning.store(false);
UDPC_ctx->thread.join();
}
void UDPC_update(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
- if(!c || c->flags.test(0)) {
+ if(!c || c->isAutoUpdating.load()) {
// invalid or is threaded, update should not be called
return;
}