summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-10-03 10:57:36 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-10-03 11:23:26 +0200
commit54418ea659061edccdf1ac16470505542dcc33f9 (patch)
treecf48aba0b9b73277b1ccc01b914646d49881f2a3 /core
parentd331b803b8e63b0dab406a12c21805a17ee0a6a8 (diff)
Remove NO_THREADS fallback code, Godot 4 requires thread support
This also removes `OS::can_use_threads` from the public API since it's always true.
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp6
-rw-r--r--core/core_bind.h2
-rw-r--r--core/debugger/remote_debugger_peer.cpp8
-rw-r--r--core/debugger/remote_debugger_peer.h8
-rw-r--r--core/os/mutex.cpp4
-rw-r--r--core/os/mutex.h27
-rw-r--r--core/os/os.cpp8
-rw-r--r--core/os/os.h2
-rw-r--r--core/os/rw_lock.h17
-rw-r--r--core/os/semaphore.h13
-rw-r--r--core/os/thread.cpp4
-rw-r--r--core/os/thread.h21
-rw-r--r--core/os/threaded_array_processor.h19
-rw-r--r--core/templates/cowdata.h2
-rw-r--r--core/templates/safe_list.h159
-rw-r--r--core/templates/safe_refcount.h139
16 files changed, 8 insertions, 431 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index a164221fc2..9152b4a215 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -425,10 +425,6 @@ void OS::delay_msec(int p_msec) const {
::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
}
-bool OS::can_use_threads() const {
- return ::OS::get_singleton()->can_use_threads();
-}
-
bool OS::is_userfs_persistent() const {
return ::OS::get_singleton()->is_userfs_persistent();
}
@@ -561,8 +557,6 @@ void OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
- ClassDB::bind_method(D_METHOD("can_use_threads"), &OS::can_use_threads);
-
ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
diff --git a/core/core_bind.h b/core/core_bind.h
index ba22971d78..4a89f4f13b 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -218,8 +218,6 @@ public:
uint64_t get_ticks_msec() const;
uint64_t get_ticks_usec() const;
- bool can_use_threads() const;
-
bool is_userfs_persistent() const;
bool is_stdout_verbose() const;
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp
index e9362b4ea4..525362ec7c 100644
--- a/core/debugger/remote_debugger_peer.cpp
+++ b/core/debugger/remote_debugger_peer.cpp
@@ -79,10 +79,8 @@ RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) {
tcp_client = p_tcp;
if (tcp_client.is_valid()) { // Attaching to an already connected stream.
connected = true;
-#ifndef NO_THREADS
running = true;
thread.start(_thread_func, this);
-#endif
} else {
tcp_client.instantiate();
}
@@ -183,10 +181,8 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po
return FAILED;
}
connected = true;
-#ifndef NO_THREADS
running = true;
thread.start(_thread_func, this);
-#endif
return OK;
}
@@ -208,9 +204,7 @@ void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) {
}
void RemoteDebuggerPeerTCP::poll() {
-#ifdef NO_THREADS
- _poll();
-#endif
+ // Nothing to do, polling is done in thread.
}
void RemoteDebuggerPeerTCP::_poll() {
diff --git a/core/debugger/remote_debugger_peer.h b/core/debugger/remote_debugger_peer.h
index 473fd8d712..2ab641d537 100644
--- a/core/debugger/remote_debugger_peer.h
+++ b/core/debugger/remote_debugger_peer.h
@@ -43,12 +43,12 @@ protected:
public:
virtual bool is_peer_connected() = 0;
+ virtual int get_max_message_size() const = 0;
virtual bool has_message() = 0;
virtual Error put_message(const Array &p_arr) = 0;
virtual Array get_message() = 0;
virtual void close() = 0;
virtual void poll() = 0;
- virtual int get_max_message_size() const = 0;
virtual bool can_block() const { return true; } // If blocking io is allowed on main thread (debug).
RemoteDebuggerPeer();
@@ -81,12 +81,12 @@ public:
Error connect_to_host(const String &p_host, uint16_t p_port);
- void poll() override;
bool is_peer_connected() override;
+ int get_max_message_size() const override;
bool has_message() override;
- Array get_message() override;
Error put_message(const Array &p_arr) override;
- int get_max_message_size() const override;
+ Array get_message() override;
+ void poll() override;
void close() override;
RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_stream = Ref<StreamPeerTCP>());
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 ee8da21751..2bdede889f 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -328,14 +328,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;
}
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..e8ebb4597f 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -34,9 +34,6 @@
#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;
@@ -128,5 +125,4 @@ Thread::~Thread() {
}
}
-#endif
#endif // PLATFORM_THREAD_OVERRIDE
diff --git a/core/os/thread.h b/core/os/thread.h
index 0fb283e224..7462ec17fb 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;
@@ -65,7 +64,6 @@ public:
};
private:
-#if !defined(NO_THREADS)
friend class Main;
static ID main_thread_id;
@@ -82,7 +80,6 @@ private:
static void (*set_priority_func)(Thread::Priority);
static void (*init_func)();
static void (*term_func)();
-#endif
public:
static void _set_platform_funcs(
@@ -91,7 +88,6 @@ public:
void (*p_init_func)() = nullptr,
void (*p_term_func)() = nullptr);
-#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 +103,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
diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h
index f98b2308c9..1482e3eef1 100644
--- a/core/templates/cowdata.h
+++ b/core/templates/cowdata.h
@@ -46,9 +46,7 @@ class CharString;
template <class T, class V>
class VMap;
-#if !defined(NO_THREADS)
SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint32_t)
-#endif
// Silence a false positive warning (see GH-52119).
#if defined(__GNUC__) && !defined(__clang__)
diff --git a/core/templates/safe_list.h b/core/templates/safe_list.h
index e850f3bd5e..95e8ca1a14 100644
--- a/core/templates/safe_list.h
+++ b/core/templates/safe_list.h
@@ -33,11 +33,9 @@
#include "core/os/memory.h"
#include "core/typedefs.h"
-#include <functional>
-
-#if !defined(NO_THREADS)
#include <atomic>
+#include <functional>
#include <type_traits>
// Design goals for these classes:
@@ -239,159 +237,4 @@ public:
}
};
-#else // NO_THREADS
-
-// Effectively the same structure without the atomics. It's probably possible to simplify it but the semantics shouldn't differ greatly.
-template <class T, class A = DefaultAllocator>
-class SafeList {
- struct SafeListNode {
- SafeListNode *next = nullptr;
-
- // If the node is logically deleted, this pointer will typically point to the previous list item in time that was also logically deleted.
- SafeListNode *graveyard_next = nullptr;
-
- std::function<void(T)> deletion_fn = [](T t) { return; };
-
- T val;
- };
-
- SafeListNode *head = nullptr;
- SafeListNode *graveyard_head = nullptr;
-
- unsigned int active_iterator_count = 0;
-
-public:
- class Iterator {
- friend class SafeList;
-
- SafeListNode *cursor = nullptr;
- SafeList *list = nullptr;
-
- public:
- Iterator(SafeListNode *p_cursor, SafeList *p_list) :
- cursor(p_cursor), list(p_list) {
- list->active_iterator_count++;
- }
-
- ~Iterator() {
- list->active_iterator_count--;
- }
-
- T &operator*() {
- return cursor->val;
- }
-
- Iterator &operator++() {
- cursor = cursor->next;
- return *this;
- }
-
- // These two operators are mostly useful for comparisons to nullptr.
- bool operator==(const void *p_other) const {
- return cursor == p_other;
- }
-
- bool operator!=(const void *p_other) const {
- return cursor != p_other;
- }
-
- // These two allow easy range-based for loops.
- bool operator==(const Iterator &p_other) const {
- return cursor == p_other.cursor;
- }
-
- bool operator!=(const Iterator &p_other) const {
- return cursor != p_other.cursor;
- }
- };
-
-public:
- // Calling this will cause an allocation.
- void insert(T p_value) {
- SafeListNode *new_node = memnew_allocator(SafeListNode, A);
- new_node->val = p_value;
- new_node->next = head;
- head = new_node;
- }
-
- Iterator find(T p_value) {
- for (Iterator it = begin(); it != end(); ++it) {
- if (*it == p_value) {
- return it;
- }
- }
- return end();
- }
-
- void erase(T p_value, std::function<void(T)> p_deletion_fn) {
- erase(find(p_value), p_deletion_fn);
- }
-
- void erase(T p_value) {
- erase(find(p_value), [](T t) { return; });
- }
-
- void erase(Iterator p_iterator, std::function<void(T)> p_deletion_fn) {
- p_iterator.cursor->deletion_fn = p_deletion_fn;
- erase(p_iterator);
- }
-
- void erase(Iterator p_iterator) {
- Iterator prev = begin();
- for (; prev != end(); ++prev) {
- if (prev.cursor && prev.cursor->next == p_iterator.cursor) {
- break;
- }
- }
- if (prev == end()) {
- // Not in the list, nothing to do.
- return;
- }
- // First, remove the node from the list.
- prev.cursor->next = p_iterator.cursor->next;
-
- // Then queue it for deletion by putting it in the node graveyard. Don't touch `next` because an iterator might still be pointing at this node.
- p_iterator.cursor->graveyard_next = graveyard_head;
- graveyard_head = p_iterator.cursor;
- }
-
- Iterator begin() {
- return Iterator(head, this);
- }
-
- Iterator end() {
- return Iterator(nullptr, this);
- }
-
- // Calling this will cause zero to many deallocations.
- bool maybe_cleanup() {
- SafeListNode *cursor = graveyard_head;
- if (active_iterator_count != 0) {
- // It's not safe to clean up with an active iterator, because that iterator could be pointing to an element that we want to delete.
- return false;
- }
- graveyard_head = nullptr;
- // Our graveyard list is now unreachable by any active iterators, detached from the main graveyard head and ready for deletion.
- while (cursor) {
- SafeListNode *tmp = cursor;
- cursor = cursor->next;
- tmp->deletion_fn(tmp->val);
- memdelete_allocator<SafeListNode, A>(tmp);
- }
- return true;
- }
-
- ~SafeList() {
-#ifdef DEBUG_ENABLED
- if (!maybe_cleanup()) {
- ERR_PRINT("There are still iterators around when destructing a SafeList. Memory will be leaked. This is a bug.");
- }
-#else
- maybe_cleanup();
-#endif
- }
-};
-
-#endif
-
#endif // SAFE_LIST_H
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h
index 1f6551762e..c4ffe5ca02 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -33,8 +33,6 @@
#include "core/typedefs.h"
-#if !defined(NO_THREADS)
-
#include <atomic>
#include <type_traits>
@@ -191,141 +189,4 @@ public:
}
};
-#else
-
-template <class T>
-class SafeNumeric {
-protected:
- T value;
-
-public:
- _ALWAYS_INLINE_ void set(T p_value) {
- value = p_value;
- }
-
- _ALWAYS_INLINE_ T get() const {
- return value;
- }
-
- _ALWAYS_INLINE_ T increment() {
- return ++value;
- }
-
- _ALWAYS_INLINE_ T postincrement() {
- return value++;
- }
-
- _ALWAYS_INLINE_ T decrement() {
- return --value;
- }
-
- _ALWAYS_INLINE_ T postdecrement() {
- return value--;
- }
-
- _ALWAYS_INLINE_ T add(T p_value) {
- return value += p_value;
- }
-
- _ALWAYS_INLINE_ T postadd(T p_value) {
- T old = value;
- value += p_value;
- return old;
- }
-
- _ALWAYS_INLINE_ T sub(T p_value) {
- return value -= p_value;
- }
-
- _ALWAYS_INLINE_ T postsub(T p_value) {
- T old = value;
- value -= p_value;
- return old;
- }
-
- _ALWAYS_INLINE_ T exchange_if_greater(T p_value) {
- if (value < p_value) {
- value = p_value;
- }
- return value;
- }
-
- _ALWAYS_INLINE_ T conditional_increment() {
- if (value == 0) {
- return 0;
- } else {
- return ++value;
- }
- }
-
- _ALWAYS_INLINE_ explicit SafeNumeric<T>(T p_value = static_cast<T>(0)) :
- value(p_value) {
- }
-};
-
-class SafeFlag {
-protected:
- bool flag;
-
-public:
- _ALWAYS_INLINE_ bool is_set() const {
- return flag;
- }
-
- _ALWAYS_INLINE_ void set() {
- flag = true;
- }
-
- _ALWAYS_INLINE_ void clear() {
- flag = false;
- }
-
- _ALWAYS_INLINE_ void set_to(bool p_value) {
- flag = p_value;
- }
-
- _ALWAYS_INLINE_ explicit SafeFlag(bool p_value = false) :
- flag(p_value) {}
-};
-
-class SafeRefCount {
- uint32_t count = 0;
-
-public:
- _ALWAYS_INLINE_ bool ref() { // true on success
- if (count != 0) {
- ++count;
- return true;
- } else {
- return false;
- }
- }
-
- _ALWAYS_INLINE_ uint32_t refval() { // none-zero on success
- if (count != 0) {
- return ++count;
- } else {
- return 0;
- }
- }
-
- _ALWAYS_INLINE_ bool unref() { // true if must be disposed of
- return --count == 0;
- }
-
- _ALWAYS_INLINE_ uint32_t unrefval() { // 0 if must be disposed of
- return --count;
- }
-
- _ALWAYS_INLINE_ uint32_t get() const {
- return count;
- }
-
- _ALWAYS_INLINE_ void init(uint32_t p_value = 1) {
- count = p_value;
- }
-};
-
-#endif
-
#endif // SAFE_REFCOUNT_H