diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/mutex.cpp | 4 | ||||
-rw-r--r-- | core/os/mutex.h | 27 | ||||
-rw-r--r-- | core/os/os.cpp | 14 | ||||
-rw-r--r-- | core/os/os.h | 2 | ||||
-rw-r--r-- | core/os/rw_lock.h | 17 | ||||
-rw-r--r-- | core/os/semaphore.h | 13 | ||||
-rw-r--r-- | core/os/thread.cpp | 44 | ||||
-rw-r--r-- | core/os/thread.h | 40 | ||||
-rw-r--r-- | core/os/threaded_array_processor.h | 19 |
9 files changed, 32 insertions, 148 deletions
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index 1d4400bfc1..512db1737a 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -40,11 +40,7 @@ void _global_unlock() { _global_mutex.unlock(); } -#ifndef NO_THREADS - template class MutexImpl<std::recursive_mutex>; template class MutexImpl<std::mutex>; template class MutexLock<MutexImpl<std::recursive_mutex>>; template class MutexLock<MutexImpl<std::mutex>>; - -#endif diff --git a/core/os/mutex.h b/core/os/mutex.h index a51248807b..eb58418bd6 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -34,8 +34,6 @@ #include "core/error/error_list.h" #include "core/typedefs.h" -#if !defined(NO_THREADS) - #include <mutex> template <class StdMutexT> @@ -79,29 +77,4 @@ extern template class MutexImpl<std::mutex>; extern template class MutexLock<MutexImpl<std::recursive_mutex>>; extern template class MutexLock<MutexImpl<std::mutex>>; -#else - -class FakeMutex { - FakeMutex() {} -}; - -template <class MutexT> -class MutexImpl { -public: - _ALWAYS_INLINE_ void lock() const {} - _ALWAYS_INLINE_ void unlock() const {} - _ALWAYS_INLINE_ Error try_lock() const { return OK; } -}; - -template <class MutexT> -class MutexLock { -public: - explicit MutexLock(const MutexT &p_mutex) {} -}; - -using Mutex = MutexImpl<FakeMutex>; -using BinaryMutex = MutexImpl<FakeMutex>; // Non-recursive, handle with care - -#endif // !NO_THREADS - #endif // MUTEX_H diff --git a/core/os/os.cpp b/core/os/os.cpp index 62d6740685..bbb2a94fe7 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -329,14 +329,6 @@ String OS::get_processor_name() const { return ""; } -bool OS::can_use_threads() const { -#ifdef NO_THREADS - return false; -#else - return true; -#endif -} - void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) { has_server_feature_callback = p_callback; } @@ -520,10 +512,10 @@ void OS::add_frame_delay(bool p_can_draw) { if (is_in_low_processor_usage_mode() || !p_can_draw) { dynamic_delay = get_low_processor_usage_mode_sleep_usec(); } - const int target_fps = Engine::get_singleton()->get_target_fps(); - if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) { + const int max_fps = Engine::get_singleton()->get_max_fps(); + if (max_fps > 0 && !Engine::get_singleton()->is_editor_hint()) { // Override the low processor usage mode sleep delay if the target FPS is lower. - dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps)); + dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / max_fps)); } if (dynamic_delay > 0) { diff --git a/core/os/os.h b/core/os/os.h index aa45a3b8a8..1a5e45968d 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -299,8 +299,6 @@ public: virtual String get_unique_id() const; - virtual bool can_use_threads() const; - bool has_feature(const String &p_feature); void set_has_server_feature_callback(HasServerFeatureCallback p_callback); diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index a046f474ea..d3206547c7 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -33,8 +33,6 @@ #include "core/error/error_list.h" -#if !defined(NO_THREADS) - #include <shared_mutex> class RWLock { @@ -72,21 +70,6 @@ public: } }; -#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 { const RWLock &lock; diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 72df52dd34..1a93d3ee2c 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -34,8 +34,6 @@ #include "core/error/error_list.h" #include "core/typedefs.h" -#if !defined(NO_THREADS) - #include <condition_variable> #include <mutex> @@ -70,15 +68,4 @@ public: } }; -#else - -class Semaphore { -public: - _ALWAYS_INLINE_ void post() const {} - _ALWAYS_INLINE_ void wait() const {} - _ALWAYS_INLINE_ bool try_wait() const { return true; } -}; - -#endif - #endif // SEMAPHORE_H diff --git a/core/os/thread.cpp b/core/os/thread.cpp index c8072b7280..712f4793eb 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -34,15 +34,9 @@ #include "thread.h" #include "core/object/script_language.h" - -#if !defined(NO_THREADS) - #include "core/templates/safe_refcount.h" -Error (*Thread::set_name_func)(const String &) = nullptr; -void (*Thread::set_priority_func)(Thread::Priority) = nullptr; -void (*Thread::init_func)() = nullptr; -void (*Thread::term_func)() = nullptr; +Thread::PlatformFunctions Thread::platform_functions; uint64_t Thread::_thread_id_hash(const std::thread::id &p_t) { static std::hash<std::thread::id> hasher; @@ -52,30 +46,27 @@ uint64_t Thread::_thread_id_hash(const std::thread::id &p_t) { Thread::ID Thread::main_thread_id = _thread_id_hash(std::this_thread::get_id()); thread_local Thread::ID Thread::caller_id = 0; -void Thread::_set_platform_funcs( - Error (*p_set_name_func)(const String &), - void (*p_set_priority_func)(Thread::Priority), - void (*p_init_func)(), - void (*p_term_func)()) { - Thread::set_name_func = p_set_name_func; - Thread::set_priority_func = p_set_priority_func; - Thread::init_func = p_init_func; - Thread::term_func = p_term_func; +void Thread::_set_platform_functions(const PlatformFunctions &p_functions) { + platform_functions = p_functions; } void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_callback, void *p_userdata) { Thread::caller_id = _thread_id_hash(p_self->thread.get_id()); - if (set_priority_func) { - set_priority_func(p_settings.priority); + if (platform_functions.set_priority) { + platform_functions.set_priority(p_settings.priority); } - if (init_func) { - init_func(); + if (platform_functions.init) { + platform_functions.init(); + } + ScriptServer::thread_enter(); // Scripts may need to attach a stack. + if (platform_functions.wrapper) { + platform_functions.wrapper(p_callback, p_userdata); + } else { + p_callback(p_userdata); } - ScriptServer::thread_enter(); //scripts may need to attach a stack - p_callback(p_userdata); ScriptServer::thread_exit(); - if (term_func) { - term_func(); + if (platform_functions.term) { + platform_functions.term(); } } @@ -108,8 +99,8 @@ void Thread::wait_to_finish() { } Error Thread::set_name(const String &p_name) { - if (set_name_func) { - return set_name_func(p_name); + if (platform_functions.set_name) { + return platform_functions.set_name(p_name); } return ERR_UNAVAILABLE; @@ -128,5 +119,4 @@ Thread::~Thread() { } } -#endif #endif // PLATFORM_THREAD_OVERRIDE diff --git a/core/os/thread.h b/core/os/thread.h index 0fb283e224..86442de760 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -35,15 +35,14 @@ #ifdef PLATFORM_THREAD_OVERRIDE #include "platform_thread.h" #else + #ifndef THREAD_H #define THREAD_H +#include "core/templates/safe_refcount.h" #include "core/typedefs.h" -#if !defined(NO_THREADS) -#include "core/templates/safe_refcount.h" #include <thread> -#endif class String; @@ -64,8 +63,15 @@ public: Settings() { priority = PRIORITY_NORMAL; } }; + struct PlatformFunctions { + Error (*set_name)(const String &) = nullptr; + void (*set_priority)(Thread::Priority) = nullptr; + void (*init)() = nullptr; + void (*wrapper)(Thread::Callback, void *) = nullptr; + void (*term)() = nullptr; + }; + private: -#if !defined(NO_THREADS) friend class Main; static ID main_thread_id; @@ -78,20 +84,11 @@ private: static void callback(Thread *p_self, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata); - static Error (*set_name_func)(const String &); - static void (*set_priority_func)(Thread::Priority); - static void (*init_func)(); - static void (*term_func)(); -#endif + static PlatformFunctions platform_functions; public: - static void _set_platform_funcs( - Error (*p_set_name_func)(const String &), - void (*p_set_priority_func)(Thread::Priority), - void (*p_init_func)() = nullptr, - void (*p_term_func)() = nullptr); + static void _set_platform_functions(const PlatformFunctions &p_functions); -#if !defined(NO_THREADS) _FORCE_INLINE_ ID get_id() const { return id; } // get the ID of the caller thread _FORCE_INLINE_ static ID get_caller_id() { return caller_id; } @@ -107,19 +104,6 @@ public: Thread(); ~Thread(); -#else - _FORCE_INLINE_ ID get_id() const { return 0; } - // get the ID of the caller thread - _FORCE_INLINE_ static ID get_caller_id() { return 0; } - // get the ID of the main thread - _FORCE_INLINE_ static ID get_main_id() { return 0; } - - static Error set_name(const String &p_name) { return ERR_UNAVAILABLE; } - - void start(Thread::Callback p_callback, void *p_user, const Settings &p_settings = Settings()) {} - bool is_started() const { return false; } - void wait_to_finish() {} -#endif }; #endif // THREAD_H diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h index 935fc7a360..95a2253f14 100644 --- a/core/os/threaded_array_processor.h +++ b/core/os/threaded_array_processor.h @@ -49,8 +49,6 @@ struct ThreadArrayProcessData { } }; -#ifndef NO_THREADS - template <class T> void process_array_thread(void *ud) { T &data = *(T *)ud; @@ -86,21 +84,4 @@ void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_us memdelete_arr(threads); } -#else - -template <class C, class M, class U> -void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { - ThreadArrayProcessData<C, U> data; - data.method = p_method; - data.instance = p_instance; - data.userdata = p_userdata; - data.index.set(0); - data.elements = p_elements; - for (uint32_t i = 0; i < p_elements; i++) { - data.process(i); - } -} - -#endif - #endif // THREADED_ARRAY_PROCESSOR_H |