mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Modernize atomics
- Based on C++11's `atomic` - Reworked `SafeRefCount` (based on the rewrite by @hpvb) - Replaced free atomic functions by the new `SafeNumeric<T>` - Replaced wrong cases of `volatile` by the new `SafeFlag` - Platform-specific implementations no longer needed Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
This commit is contained in:
@@ -995,9 +995,6 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) {
|
||||
|
||||
NativeScriptLanguage::NativeScriptLanguage() {
|
||||
NativeScriptLanguage::singleton = this;
|
||||
#ifndef NO_THREADS
|
||||
has_objects_to_register = false;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
profiling = false;
|
||||
@@ -1446,7 +1443,7 @@ void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeSc
|
||||
MutexLock lock(mutex);
|
||||
libs_to_init.insert(lib);
|
||||
scripts_to_register.insert(script);
|
||||
has_objects_to_register = true;
|
||||
has_objects_to_register.set();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1539,7 +1536,7 @@ void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
|
||||
|
||||
void NativeScriptLanguage::frame() {
|
||||
#ifndef NO_THREADS
|
||||
if (has_objects_to_register) {
|
||||
if (has_objects_to_register.is_set()) {
|
||||
MutexLock lock(mutex);
|
||||
for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) {
|
||||
init_library(L->get());
|
||||
@@ -1549,7 +1546,7 @@ void NativeScriptLanguage::frame() {
|
||||
register_script(S->get());
|
||||
}
|
||||
scripts_to_register.clear();
|
||||
has_objects_to_register = false;
|
||||
has_objects_to_register.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "core/ordered_hash_map.h"
|
||||
#include "core/os/thread_safe.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/safe_refcount.h"
|
||||
#include "core/script_language.h"
|
||||
#include "core/self_list.h"
|
||||
#include "scene/main/node.h"
|
||||
@@ -240,7 +241,7 @@ private:
|
||||
|
||||
Set<Ref<GDNativeLibrary> > libs_to_init;
|
||||
Set<NativeScript *> scripts_to_register;
|
||||
volatile bool has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed
|
||||
SafeFlag has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed
|
||||
void defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user