mirror of
https://github.com/godotengine/godot.git
synced 2025-01-27 04:12:02 +00:00
Merge pull request #45314 from RandomShaper/modernize_rwlock
Modernize RWLock
This commit is contained in:
commit
d39f6386ce
@ -52,29 +52,29 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
|
||||
}
|
||||
|
||||
if (path_cache != "") {
|
||||
ResourceCache::lock->write_lock();
|
||||
ResourceCache::lock.write_lock();
|
||||
ResourceCache::resources.erase(path_cache);
|
||||
ResourceCache::lock->write_unlock();
|
||||
ResourceCache::lock.write_unlock();
|
||||
}
|
||||
|
||||
path_cache = "";
|
||||
|
||||
ResourceCache::lock->read_lock();
|
||||
ResourceCache::lock.read_lock();
|
||||
bool has_path = ResourceCache::resources.has(p_path);
|
||||
ResourceCache::lock->read_unlock();
|
||||
ResourceCache::lock.read_unlock();
|
||||
|
||||
if (has_path) {
|
||||
if (p_take_over) {
|
||||
ResourceCache::lock->write_lock();
|
||||
ResourceCache::lock.write_lock();
|
||||
Resource **res = ResourceCache::resources.getptr(p_path);
|
||||
if (res) {
|
||||
(*res)->set_name("");
|
||||
}
|
||||
ResourceCache::lock->write_unlock();
|
||||
ResourceCache::lock.write_unlock();
|
||||
} else {
|
||||
ResourceCache::lock->read_lock();
|
||||
ResourceCache::lock.read_lock();
|
||||
bool exists = ResourceCache::resources.has(p_path);
|
||||
ResourceCache::lock->read_unlock();
|
||||
ResourceCache::lock.read_unlock();
|
||||
|
||||
ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion).");
|
||||
}
|
||||
@ -82,9 +82,9 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
|
||||
path_cache = p_path;
|
||||
|
||||
if (path_cache != "") {
|
||||
ResourceCache::lock->write_lock();
|
||||
ResourceCache::lock.write_lock();
|
||||
ResourceCache::resources[path_cache] = this;
|
||||
ResourceCache::lock->write_unlock();
|
||||
ResourceCache::lock.write_unlock();
|
||||
}
|
||||
|
||||
_change_notify("resource_path");
|
||||
@ -315,9 +315,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->write_lock();
|
||||
}
|
||||
ResourceCache::lock.write_lock();
|
||||
|
||||
if (p_remapped) {
|
||||
ResourceLoader::remapped_list.add(&remapped_list);
|
||||
@ -325,9 +323,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
|
||||
ResourceLoader::remapped_list.remove(&remapped_list);
|
||||
}
|
||||
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->write_unlock();
|
||||
}
|
||||
ResourceCache::lock.write_unlock();
|
||||
}
|
||||
|
||||
bool Resource::is_translation_remapped() const {
|
||||
@ -338,38 +334,24 @@ bool Resource::is_translation_remapped() const {
|
||||
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
|
||||
void Resource::set_id_for_path(const String &p_path, int p_id) {
|
||||
if (p_id == -1) {
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->write_lock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.write_lock();
|
||||
ResourceCache::resource_path_cache[p_path].erase(get_path());
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->write_unlock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.write_unlock();
|
||||
} else {
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->write_lock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.write_lock();
|
||||
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->write_unlock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.write_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int Resource::get_id_for_path(const String &p_path) const {
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->read_lock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.read_lock();
|
||||
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
|
||||
int result = ResourceCache::resource_path_cache[p_path][get_path()];
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->read_unlock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.read_unlock();
|
||||
return result;
|
||||
} else {
|
||||
if (ResourceCache::path_cache_lock) {
|
||||
ResourceCache::path_cache_lock->read_unlock();
|
||||
}
|
||||
ResourceCache::path_cache_lock.read_unlock();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -403,9 +385,9 @@ Resource::Resource() :
|
||||
|
||||
Resource::~Resource() {
|
||||
if (path_cache != "") {
|
||||
ResourceCache::lock->write_lock();
|
||||
ResourceCache::lock.write_lock();
|
||||
ResourceCache::resources.erase(path_cache);
|
||||
ResourceCache::lock->write_unlock();
|
||||
ResourceCache::lock.write_unlock();
|
||||
}
|
||||
if (owners.size()) {
|
||||
WARN_PRINT("Resource is still owned.");
|
||||
@ -417,18 +399,11 @@ HashMap<String, Resource *> ResourceCache::resources;
|
||||
HashMap<String, HashMap<String, int>> ResourceCache::resource_path_cache;
|
||||
#endif
|
||||
|
||||
RWLock *ResourceCache::lock = nullptr;
|
||||
RWLock ResourceCache::lock;
|
||||
#ifdef TOOLS_ENABLED
|
||||
RWLock *ResourceCache::path_cache_lock = nullptr;
|
||||
RWLock ResourceCache::path_cache_lock;
|
||||
#endif
|
||||
|
||||
void ResourceCache::setup() {
|
||||
lock = RWLock::create();
|
||||
#ifdef TOOLS_ENABLED
|
||||
path_cache_lock = RWLock::create();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResourceCache::clear() {
|
||||
if (resources.size()) {
|
||||
ERR_PRINT("Resources still in use at exit (run with --verbose for details).");
|
||||
@ -442,29 +417,25 @@ void ResourceCache::clear() {
|
||||
}
|
||||
|
||||
resources.clear();
|
||||
memdelete(lock);
|
||||
#ifdef TOOLS_ENABLED
|
||||
memdelete(path_cache_lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResourceCache::reload_externals() {
|
||||
}
|
||||
|
||||
bool ResourceCache::has(const String &p_path) {
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
bool b = resources.has(p_path);
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
Resource *ResourceCache::get(const String &p_path) {
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
|
||||
Resource **res = resources.getptr(p_path);
|
||||
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
|
||||
if (!res) {
|
||||
return nullptr;
|
||||
@ -474,26 +445,26 @@ Resource *ResourceCache::get(const String &p_path) {
|
||||
}
|
||||
|
||||
void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) {
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
const String *K = nullptr;
|
||||
while ((K = resources.next(K))) {
|
||||
Resource *r = resources[*K];
|
||||
p_resources->push_back(Ref<Resource>(r));
|
||||
}
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
}
|
||||
|
||||
int ResourceCache::get_cached_resource_count() {
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
int rc = resources.size();
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ResourceCache::dump(const char *p_file, bool p_short) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
|
||||
Map<String, int> type_count;
|
||||
|
||||
@ -530,6 +501,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
|
||||
memdelete(f);
|
||||
}
|
||||
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
#endif
|
||||
}
|
||||
|
@ -149,16 +149,15 @@ typedef Ref<Resource> RES;
|
||||
class ResourceCache {
|
||||
friend class Resource;
|
||||
friend class ResourceLoader; //need the lock
|
||||
static RWLock *lock;
|
||||
static RWLock lock;
|
||||
static HashMap<String, Resource *> resources;
|
||||
#ifdef TOOLS_ENABLED
|
||||
static HashMap<String, HashMap<String, int>> resource_path_cache; // each tscn has a set of resource paths and IDs
|
||||
static RWLock *path_cache_lock;
|
||||
static RWLock path_cache_lock;
|
||||
#endif // TOOLS_ENABLED
|
||||
friend void unregister_core_types();
|
||||
static void clear();
|
||||
friend void register_core_types();
|
||||
static void setup();
|
||||
|
||||
public:
|
||||
static void reload_externals();
|
||||
|
@ -323,9 +323,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String &
|
||||
ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Attempted to load a resource already being loaded from this thread, cyclic reference?");
|
||||
}
|
||||
//lock first if possible
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_lock();
|
||||
}
|
||||
ResourceCache::lock.read_lock();
|
||||
|
||||
//get ptr
|
||||
Resource **rptr = ResourceCache::resources.getptr(local_path);
|
||||
@ -340,9 +338,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String &
|
||||
load_task.progress = 1.0;
|
||||
}
|
||||
}
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_unlock();
|
||||
}
|
||||
ResourceCache::lock.read_unlock();
|
||||
}
|
||||
|
||||
if (p_source_resource != String()) {
|
||||
@ -535,9 +531,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
|
||||
}
|
||||
|
||||
//Is it cached?
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_lock();
|
||||
}
|
||||
ResourceCache::lock.read_lock();
|
||||
|
||||
Resource **rptr = ResourceCache::resources.getptr(local_path);
|
||||
|
||||
@ -546,9 +540,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
|
||||
|
||||
//it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached
|
||||
if (res.is_valid()) {
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_unlock();
|
||||
}
|
||||
ResourceCache::lock.read_unlock();
|
||||
thread_load_mutex->unlock();
|
||||
|
||||
if (r_error) {
|
||||
@ -559,9 +551,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
|
||||
}
|
||||
}
|
||||
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_unlock();
|
||||
}
|
||||
ResourceCache::lock.read_unlock();
|
||||
|
||||
//load using task (but this thread)
|
||||
ThreadLoadTask load_task;
|
||||
@ -955,9 +945,7 @@ String ResourceLoader::path_remap(const String &p_path) {
|
||||
}
|
||||
|
||||
void ResourceLoader::reload_translation_remaps() {
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_lock();
|
||||
}
|
||||
ResourceCache::lock.read_lock();
|
||||
|
||||
List<Resource *> to_reload;
|
||||
SelfList<Resource> *E = remapped_list.first();
|
||||
@ -967,9 +955,7 @@ void ResourceLoader::reload_translation_remaps() {
|
||||
E = E->next();
|
||||
}
|
||||
|
||||
if (ResourceCache::lock) {
|
||||
ResourceCache::lock->read_unlock();
|
||||
}
|
||||
ResourceCache::lock.read_unlock();
|
||||
|
||||
//now just make sure to not delete any of these resources while changing locale..
|
||||
while (to_reload.front()) {
|
||||
|
@ -983,9 +983,9 @@ void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, co
|
||||
|
||||
// NOTE: For implementation simplicity reasons, this method doesn't allow setters to have optional arguments at the end.
|
||||
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
|
||||
lock->read_lock();
|
||||
lock.read_lock();
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
lock->read_unlock();
|
||||
lock.read_unlock();
|
||||
|
||||
ERR_FAIL_COND(!type);
|
||||
|
||||
@ -1541,11 +1541,7 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
|
||||
return var;
|
||||
}
|
||||
|
||||
RWLock *ClassDB::lock = nullptr;
|
||||
|
||||
void ClassDB::init() {
|
||||
lock = RWLock::create();
|
||||
}
|
||||
RWLock ClassDB::lock;
|
||||
|
||||
void ClassDB::cleanup_defaults() {
|
||||
default_values.clear();
|
||||
@ -1568,8 +1564,6 @@ void ClassDB::cleanup() {
|
||||
classes.clear();
|
||||
resource_base_extensions.clear();
|
||||
compat_classes.clear();
|
||||
|
||||
memdelete(lock);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -146,7 +146,7 @@ public:
|
||||
return memnew(T);
|
||||
}
|
||||
|
||||
static RWLock *lock;
|
||||
static RWLock lock;
|
||||
static HashMap<StringName, ClassInfo> classes;
|
||||
static HashMap<StringName, StringName> resource_base_extensions;
|
||||
static HashMap<StringName, StringName> compat_classes;
|
||||
@ -387,7 +387,6 @@ public:
|
||||
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
|
||||
|
||||
static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
|
||||
static void init();
|
||||
|
||||
static void set_current_api(APIType p_api);
|
||||
static APIType get_current_api();
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "rw_lock.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
RWLock *(*RWLock::create_func)() = nullptr;
|
||||
|
||||
RWLock *RWLock::create() {
|
||||
ERR_FAIL_COND_V(!create_func, nullptr);
|
||||
|
||||
return create_func();
|
||||
}
|
@ -33,55 +33,83 @@
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
|
||||
#if !defined(NO_THREADS)
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
class RWLock {
|
||||
protected:
|
||||
static RWLock *(*create_func)();
|
||||
mutable std::shared_timed_mutex mutex;
|
||||
|
||||
public:
|
||||
virtual void read_lock() = 0; ///< Lock the rwlock, block if locked by someone else
|
||||
virtual void read_unlock() = 0; ///< Unlock the rwlock, let other threads continue
|
||||
virtual Error read_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock.
|
||||
// Lock the rwlock, block if locked by someone else
|
||||
void read_lock() const {
|
||||
mutex.lock_shared();
|
||||
}
|
||||
|
||||
virtual void write_lock() = 0; ///< Lock the rwlock, block if locked by someone else
|
||||
virtual void write_unlock() = 0; ///< Unlock the rwlock, let other thwrites continue
|
||||
virtual Error write_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock.
|
||||
// Unlock the rwlock, let other threads continue
|
||||
void read_unlock() const {
|
||||
mutex.unlock_shared();
|
||||
}
|
||||
|
||||
static RWLock *create(); ///< Create a rwlock
|
||||
// Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock.
|
||||
Error read_try_lock() const {
|
||||
return mutex.try_lock_shared() ? OK : ERR_BUSY;
|
||||
}
|
||||
|
||||
virtual ~RWLock() {}
|
||||
// Lock the rwlock, block if locked by someone else
|
||||
void write_lock() {
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
// Unlock the rwlock, let other thwrites continue
|
||||
void write_unlock() {
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
// Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock.
|
||||
Error write_try_lock() {
|
||||
return mutex.try_lock() ? OK : ERR_BUSY;
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class RWLock {
|
||||
public:
|
||||
void read_lock() const {}
|
||||
void read_unlock() const {}
|
||||
Error read_try_lock() const { return OK; }
|
||||
|
||||
void write_lock() {}
|
||||
void write_unlock() {}
|
||||
Error write_try_lock() { return OK; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class RWLockRead {
|
||||
RWLock *lock;
|
||||
const RWLock &lock;
|
||||
|
||||
public:
|
||||
RWLockRead(const RWLock *p_lock) {
|
||||
lock = const_cast<RWLock *>(p_lock);
|
||||
if (lock) {
|
||||
lock->read_lock();
|
||||
}
|
||||
RWLockRead(const RWLock &p_lock) :
|
||||
lock(p_lock) {
|
||||
lock.read_lock();
|
||||
}
|
||||
~RWLockRead() {
|
||||
if (lock) {
|
||||
lock->read_unlock();
|
||||
}
|
||||
lock.read_unlock();
|
||||
}
|
||||
};
|
||||
|
||||
class RWLockWrite {
|
||||
RWLock *lock;
|
||||
RWLock &lock;
|
||||
|
||||
public:
|
||||
RWLockWrite(RWLock *p_lock) {
|
||||
lock = p_lock;
|
||||
if (lock) {
|
||||
lock->write_lock();
|
||||
}
|
||||
RWLockWrite(RWLock &p_lock) :
|
||||
lock(p_lock) {
|
||||
lock.write_lock();
|
||||
}
|
||||
~RWLockWrite() {
|
||||
if (lock) {
|
||||
lock->write_unlock();
|
||||
}
|
||||
lock.write_unlock();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -39,11 +39,3 @@ Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const
|
||||
void ThreadDummy::make_default() {
|
||||
Thread::create_func = &ThreadDummy::create;
|
||||
}
|
||||
|
||||
RWLock *RWLockDummy::create() {
|
||||
return memnew(RWLockDummy);
|
||||
}
|
||||
|
||||
void RWLockDummy::make_default() {
|
||||
RWLock::create_func = &RWLockDummy::create;
|
||||
}
|
||||
|
@ -44,19 +44,4 @@ public:
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
class RWLockDummy : public RWLock {
|
||||
static RWLock *create();
|
||||
|
||||
public:
|
||||
virtual void read_lock() {}
|
||||
virtual void read_unlock() {}
|
||||
virtual Error read_try_lock() { return OK; }
|
||||
|
||||
virtual void write_lock() {}
|
||||
virtual void write_unlock() {}
|
||||
virtual Error write_try_lock() { return OK; }
|
||||
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
#endif // THREAD_DUMMY_H
|
||||
|
@ -103,7 +103,6 @@ void register_core_types() {
|
||||
static_assert(sizeof(Callable) <= 16);
|
||||
|
||||
ObjectDB::setup();
|
||||
ResourceCache::setup();
|
||||
|
||||
StringName::setup();
|
||||
ResourceLoader::initialize();
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "drivers/unix/net_socket_posix.h"
|
||||
#include "drivers/unix/rw_lock_posix.h"
|
||||
#include "drivers/unix/thread_posix.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
@ -119,10 +118,8 @@ int OS_Unix::unix_initialize_audio(int p_audio_driver) {
|
||||
void OS_Unix::initialize_core() {
|
||||
#ifdef NO_THREADS
|
||||
ThreadDummy::make_default();
|
||||
RWLockDummy::make_default();
|
||||
#else
|
||||
ThreadPosix::make_default();
|
||||
RWLockPosix::make_default();
|
||||
#endif
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_posix.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
#include "rw_lock_posix.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void RWLockPosix::read_lock() {
|
||||
int err = pthread_rwlock_rdlock(&rwlock);
|
||||
if (err != 0) {
|
||||
perror("Acquiring lock failed");
|
||||
}
|
||||
ERR_FAIL_COND(err != 0);
|
||||
}
|
||||
|
||||
void RWLockPosix::read_unlock() {
|
||||
pthread_rwlock_unlock(&rwlock);
|
||||
}
|
||||
|
||||
Error RWLockPosix::read_try_lock() {
|
||||
if (pthread_rwlock_tryrdlock(&rwlock) != 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
void RWLockPosix::write_lock() {
|
||||
int err = pthread_rwlock_wrlock(&rwlock);
|
||||
ERR_FAIL_COND(err != 0);
|
||||
}
|
||||
|
||||
void RWLockPosix::write_unlock() {
|
||||
pthread_rwlock_unlock(&rwlock);
|
||||
}
|
||||
|
||||
Error RWLockPosix::write_try_lock() {
|
||||
if (pthread_rwlock_trywrlock(&rwlock) != 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
RWLock *RWLockPosix::create_func_posix() {
|
||||
return memnew(RWLockPosix);
|
||||
}
|
||||
|
||||
void RWLockPosix::make_default() {
|
||||
create_func = create_func_posix;
|
||||
}
|
||||
|
||||
RWLockPosix::RWLockPosix() {
|
||||
//rwlock=PTHREAD_RWLOCK_INITIALIZER; fails on OSX
|
||||
pthread_rwlock_init(&rwlock, nullptr);
|
||||
}
|
||||
|
||||
RWLockPosix::~RWLockPosix() {
|
||||
pthread_rwlock_destroy(&rwlock);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,62 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_posix.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RWLOCKPOSIX_H
|
||||
#define RWLOCKPOSIX_H
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
#include "core/os/rw_lock.h"
|
||||
#include <pthread.h>
|
||||
|
||||
class RWLockPosix : public RWLock {
|
||||
pthread_rwlock_t rwlock;
|
||||
|
||||
static RWLock *create_func_posix();
|
||||
|
||||
public:
|
||||
virtual void read_lock();
|
||||
virtual void read_unlock();
|
||||
virtual Error read_try_lock();
|
||||
|
||||
virtual void write_lock();
|
||||
virtual void write_unlock();
|
||||
virtual Error write_try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
RWLockPosix();
|
||||
|
||||
~RWLockPosix();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // RWLOCKPOSIX_H
|
@ -1,87 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_windows.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#if defined(WINDOWS_ENABLED)
|
||||
|
||||
#include "rw_lock_windows.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void RWLockWindows::read_lock() {
|
||||
AcquireSRWLockShared(&lock);
|
||||
}
|
||||
|
||||
void RWLockWindows::read_unlock() {
|
||||
ReleaseSRWLockShared(&lock);
|
||||
}
|
||||
|
||||
Error RWLockWindows::read_try_lock() {
|
||||
if (TryAcquireSRWLockShared(&lock) == 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
void RWLockWindows::write_lock() {
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
}
|
||||
|
||||
void RWLockWindows::write_unlock() {
|
||||
ReleaseSRWLockExclusive(&lock);
|
||||
}
|
||||
|
||||
Error RWLockWindows::write_try_lock() {
|
||||
if (TryAcquireSRWLockExclusive(&lock) == 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
RWLock *RWLockWindows::create_func_windows() {
|
||||
return memnew(RWLockWindows);
|
||||
}
|
||||
|
||||
void RWLockWindows::make_default() {
|
||||
create_func = create_func_windows;
|
||||
}
|
||||
|
||||
RWLockWindows::RWLockWindows() {
|
||||
InitializeSRWLock(&lock);
|
||||
}
|
||||
|
||||
RWLockWindows::~RWLockWindows() {
|
||||
}
|
||||
|
||||
#endif
|
@ -1,63 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_windows.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RWLOCKWINDOWS_H
|
||||
#define RWLOCKWINDOWS_H
|
||||
|
||||
#if defined(WINDOWS_ENABLED)
|
||||
|
||||
#include "core/os/rw_lock.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class RWLockWindows : public RWLock {
|
||||
SRWLOCK lock;
|
||||
|
||||
static RWLock *create_func_windows();
|
||||
|
||||
public:
|
||||
virtual void read_lock();
|
||||
virtual void read_unlock();
|
||||
virtual Error read_try_lock();
|
||||
|
||||
virtual void write_lock();
|
||||
virtual void write_unlock();
|
||||
virtual Error write_try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
RWLockWindows();
|
||||
|
||||
~RWLockWindows();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // RWLOCKWINDOWS_H
|
@ -388,8 +388,6 @@ Error Main::test_setup() {
|
||||
|
||||
engine = memnew(Engine);
|
||||
|
||||
ClassDB::init();
|
||||
|
||||
register_core_types();
|
||||
register_core_driver_types();
|
||||
|
||||
@ -507,8 +505,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
||||
|
||||
engine = memnew(Engine);
|
||||
|
||||
ClassDB::init();
|
||||
|
||||
MAIN_PRINT("Main: Initialize CORE");
|
||||
|
||||
register_core_types();
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "drivers/windows/dir_access_windows.h"
|
||||
#include "drivers/windows/file_access_windows.h"
|
||||
#include "drivers/windows/mutex_windows.h"
|
||||
#include "drivers/windows/rw_lock_windows.h"
|
||||
#include "drivers/windows/semaphore_windows.h"
|
||||
#include "main/main.h"
|
||||
#include "platform/windows/windows_terminal_logger.h"
|
||||
@ -132,7 +131,6 @@ void OS_UWP::initialize_core() {
|
||||
//RedirectIOToConsole();
|
||||
|
||||
ThreadUWP::make_default();
|
||||
RWLockWindows::make_default();
|
||||
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "core/version_generated.gen.h"
|
||||
#include "drivers/windows/dir_access_windows.h"
|
||||
#include "drivers/windows/file_access_windows.h"
|
||||
#include "drivers/windows/rw_lock_windows.h"
|
||||
#include "drivers/windows/thread_windows.h"
|
||||
#include "joypad_windows.h"
|
||||
#include "lang_table.h"
|
||||
@ -178,7 +177,6 @@ void OS_Windows::initialize() {
|
||||
//RedirectIOToConsole();
|
||||
|
||||
ThreadWindows::make_default();
|
||||
RWLockWindows::make_default();
|
||||
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
||||
|
@ -2136,20 +2136,11 @@ AnimatedTexture::AnimatedTexture() {
|
||||
pause = false;
|
||||
oneshot = false;
|
||||
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
|
||||
|
||||
#ifndef NO_THREADS
|
||||
rw_lock = RWLock::create();
|
||||
#else
|
||||
rw_lock = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
AnimatedTexture::~AnimatedTexture() {
|
||||
RS::get_singleton()->free(proxy);
|
||||
RS::get_singleton()->free(proxy_ph);
|
||||
if (rw_lock) {
|
||||
memdelete(rw_lock);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
@ -745,7 +745,7 @@ class AnimatedTexture : public Texture2D {
|
||||
GDCLASS(AnimatedTexture, Texture2D);
|
||||
|
||||
//use readers writers lock for this, since its far more times read than written to
|
||||
RWLock *rw_lock;
|
||||
RWLock rw_lock;
|
||||
|
||||
public:
|
||||
enum {
|
||||
|
Loading…
Reference in New Issue
Block a user