summaryrefslogtreecommitdiff
path: root/servers/rendering
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 /servers/rendering
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 'servers/rendering')
-rw-r--r--servers/rendering/rendering_server_wrap_mt.cpp10
-rw-r--r--servers/rendering/rendering_server_wrap_mt.h2
2 files changed, 4 insertions, 8 deletions
diff --git a/servers/rendering/rendering_server_wrap_mt.cpp b/servers/rendering/rendering_server_wrap_mt.cpp
index 3572c4dc78..9b8d35e5b3 100644
--- a/servers/rendering/rendering_server_wrap_mt.cpp
+++ b/servers/rendering/rendering_server_wrap_mt.cpp
@@ -97,7 +97,7 @@ void RenderingServerWrapMT::init() {
print_verbose("RenderingServerWrapMT: Creating render thread");
DisplayServer::get_singleton()->release_rendering_thread();
if (create_thread) {
- thread = Thread::create(_thread_callback, this);
+ thread.start(_thread_callback, this);
print_verbose("RenderingServerWrapMT: Starting render thread");
}
while (!draw_thread_up) {
@@ -136,12 +136,9 @@ void RenderingServerWrapMT::finish() {
canvas_light_occluder_free_cached_ids();
canvas_occluder_polygon_free_cached_ids();
- if (thread) {
+ if (create_thread) {
command_queue.push(this, &RenderingServerWrapMT::thread_exit);
- Thread::wait_to_finish(thread);
- memdelete(thread);
-
- thread = nullptr;
+ thread.wait_to_finish();
} else {
rendering_server->finish();
}
@@ -160,7 +157,6 @@ RenderingServerWrapMT::RenderingServerWrapMT(RenderingServer *p_contained, bool
rendering_server = p_contained;
create_thread = p_create_thread;
- thread = nullptr;
draw_pending = 0;
draw_thread_up = false;
pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
diff --git a/servers/rendering/rendering_server_wrap_mt.h b/servers/rendering/rendering_server_wrap_mt.h
index 3db90c32df..8df1623608 100644
--- a/servers/rendering/rendering_server_wrap_mt.h
+++ b/servers/rendering/rendering_server_wrap_mt.h
@@ -46,7 +46,7 @@ class RenderingServerWrapMT : public RenderingServer {
Thread::ID server_thread;
volatile bool exit;
- Thread *thread;
+ Thread thread;
volatile bool draw_thread_up;
bool create_thread;