summaryrefslogtreecommitdiff
path: root/core/core_bind.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-01-31 15:24:56 +0100
committerGitHub <noreply@github.com>2021-01-31 15:24:56 +0100
commit5525cd85c60455b0bb9716bbef0ad2ad8111d752 (patch)
tree52ff0e2d3e01dd2655feff1cf88f07e10d84aad1 /core/core_bind.cpp
parent02eb11450b4151b02db861b5029783e52e16c603 (diff)
parent99fe462452be44efa618e83ad9bbecd722ae6ecd (diff)
Merge pull request #45315 from RandomShaper/modernize_thread
Modernize Thread
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 99c68eb433..456a97e5e5 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1995,24 +1995,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 {
@@ -2020,18 +2009,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;
}
@@ -2047,10 +2031,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 {