summaryrefslogtreecommitdiff
path: root/core/core_bind.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2021-01-19 13:29:41 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2021-01-29 12:02:13 +0100
commit99fe462452be44efa618e83ad9bbecd722ae6ecd (patch)
tree9bd84bc560b2c8049234d92d217396d21e68ba28 /core/core_bind.cpp
parent6ddfc8e7187bd2b25b5caa61dee8fdca05af6298 (diff)
Modernize Thread
- Based on C++11's `thread` and `thread_local` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed (except for the few cases of non-portable functions) - Simpler for `NO_THREADS` - Thread ids are now the same across platforms (main is 1; others follow)
Diffstat (limited to 'core/core_bind.cpp')
-rw-r--r--core/core_bind.cpp26
1 files changed, 3 insertions, 23 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 000b628ba7..48b407420a 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1990,24 +1990,13 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia
Thread::Settings s;
s.priority = (Thread::Priority)p_priority;
- thread = Thread::create(_start_func, ud, s);
- if (!thread) {
- active = false;
- target_method = StringName();
- target_instance = nullptr;
- userdata = Variant();
- return ERR_CANT_CREATE;
- }
+ thread.start(_start_func, ud, s);
return OK;
}
String _Thread::get_id() const {
- if (!thread) {
- return String();
- }
-
- return itos(thread->get_id());
+ return itos(thread.get_id());
}
bool _Thread::is_active() const {
@@ -2015,18 +2004,13 @@ bool _Thread::is_active() const {
}
Variant _Thread::wait_to_finish() {
- ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion.");
ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion.");
- Thread::wait_to_finish(thread);
+ thread.wait_to_finish();
Variant r = ret;
active = false;
target_method = StringName();
target_instance = nullptr;
userdata = Variant();
- if (thread) {
- memdelete(thread);
- }
- thread = nullptr;
return r;
}
@@ -2042,10 +2026,6 @@ void _Thread::_bind_methods() {
BIND_ENUM_CONSTANT(PRIORITY_HIGH);
}
-_Thread::~_Thread() {
- ERR_FAIL_COND_MSG(active, "Reference to a Thread object was lost while the thread is still running...");
-}
-
////// _ClassDB //////
PackedStringArray _ClassDB::get_class_list() const {