Skip to content

Commit

Permalink
Remove NO_THREADS fallback code, Godot 4 requires thread support
Browse files Browse the repository at this point in the history
This also removes `OS::can_use_threads` from the public API since it's always
true.
  • Loading branch information
akien-mga committed Oct 3, 2022
1 parent d331b80 commit 54418ea
Show file tree
Hide file tree
Showing 29 changed files with 12 additions and 560 deletions.
6 changes: 0 additions & 6 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ class OS : public Object {
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;
Expand Down
8 changes: 1 addition & 7 deletions core/debugger/remote_debugger_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions core/debugger/remote_debugger_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class RemoteDebuggerPeer : public RefCounted {

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();
Expand Down Expand Up @@ -81,12 +81,12 @@ class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer {

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>());
Expand Down
4 changes: 0 additions & 4 deletions core/os/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 0 additions & 27 deletions core/os/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include "core/error/error_list.h"
#include "core/typedefs.h"

#if !defined(NO_THREADS)

#include <mutex>

template <class StdMutexT>
Expand Down Expand Up @@ -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
8 changes: 0 additions & 8 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ class OS {

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);
Expand Down
17 changes: 0 additions & 17 deletions core/os/rw_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

#include "core/error/error_list.h"

#if !defined(NO_THREADS)

#include <shared_mutex>

class RWLock {
Expand Down Expand Up @@ -72,21 +70,6 @@ class RWLock {
}
};

#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;

Expand Down
13 changes: 0 additions & 13 deletions core/os/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include "core/error/error_list.h"
#include "core/typedefs.h"

#if !defined(NO_THREADS)

#include <condition_variable>
#include <mutex>

Expand Down Expand Up @@ -70,15 +68,4 @@ class Semaphore {
}
};

#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
4 changes: 0 additions & 4 deletions core/os/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,5 +125,4 @@ Thread::~Thread() {
}
}

#endif
#endif // PLATFORM_THREAD_OVERRIDE
21 changes: 2 additions & 19 deletions core/os/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -65,7 +64,6 @@ class Thread {
};

private:
#if !defined(NO_THREADS)
friend class Main;

static ID main_thread_id;
Expand All @@ -82,7 +80,6 @@ class Thread {
static void (*set_priority_func)(Thread::Priority);
static void (*init_func)();
static void (*term_func)();
#endif

public:
static void _set_platform_funcs(
Expand All @@ -91,7 +88,6 @@ class Thread {
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; }
Expand All @@ -107,19 +103,6 @@ class Thread {

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
Expand Down
19 changes: 0 additions & 19 deletions core/os/threaded_array_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ struct ThreadArrayProcessData {
}
};

#ifndef NO_THREADS

template <class T>
void process_array_thread(void *ud) {
T &data = *(T *)ud;
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions core/templates/cowdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
Loading

0 comments on commit 54418ea

Please sign in to comment.