diff options
author | myaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com> | 2023-02-22 16:49:48 -0500 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 16:43:47 +0200 |
commit | 6ed9e03449097cea58189df53cd53aaf061b3f59 (patch) | |
tree | ce72305936edf142e549ebc7dc69e308dcca042e /core/io | |
parent | db3fadc560bae67b882fabf3022f8d72a3ab3561 (diff) |
Fix data races in startup/teardown
(cherry picked from commit d337ed1c64de89ed410cfe208ea162e4cd4ae503)
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/ip.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 28b7037120..65728f34f6 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -75,7 +75,7 @@ struct _IP_ResolverPrivate { Semaphore sem; Thread thread; - bool thread_abort = false; + SafeFlag thread_abort; void resolve_queues() { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { @@ -111,7 +111,7 @@ struct _IP_ResolverPrivate { static void _thread_function(void *self) { _IP_ResolverPrivate *ipr = static_cast<_IP_ResolverPrivate *>(self); - while (!ipr->thread_abort) { + while (!ipr->thread_abort.is_set()) { ipr->sem.wait(); ipr->resolve_queues(); } @@ -343,12 +343,12 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); - resolver->thread_abort = false; + resolver->thread_abort.clear(); resolver->thread.start(_IP_ResolverPrivate::_thread_function, resolver); } IP::~IP() { - resolver->thread_abort = true; + resolver->thread_abort.set(); resolver->sem.post(); resolver->thread.wait_to_finish(); |