mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-09 14:21:58 +00:00
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)
This commit is contained in:
@@ -122,8 +122,8 @@ public:
|
||||
int message_count_to_read = 0;
|
||||
bool exit_threads = false;
|
||||
|
||||
Thread *reader_thread = nullptr;
|
||||
Thread *writer_thread = nullptr;
|
||||
Thread reader_thread;
|
||||
Thread writer_thread;
|
||||
|
||||
int func1_count = 0;
|
||||
|
||||
@@ -221,20 +221,16 @@ public:
|
||||
}
|
||||
|
||||
void init_threads() {
|
||||
reader_thread = Thread::create(&SharedThreadState::static_reader_thread_loop, this);
|
||||
writer_thread = Thread::create(&SharedThreadState::static_writer_thread_loop, this);
|
||||
reader_thread.start(&SharedThreadState::static_reader_thread_loop, this);
|
||||
writer_thread.start(&SharedThreadState::static_writer_thread_loop, this);
|
||||
}
|
||||
void destroy_threads() {
|
||||
exit_threads = true;
|
||||
reader_threadwork.main_start_work();
|
||||
writer_threadwork.main_start_work();
|
||||
|
||||
Thread::wait_to_finish(reader_thread);
|
||||
memdelete(reader_thread);
|
||||
reader_thread = nullptr;
|
||||
Thread::wait_to_finish(writer_thread);
|
||||
memdelete(writer_thread);
|
||||
writer_thread = nullptr;
|
||||
reader_thread.wait_to_finish();
|
||||
writer_thread.wait_to_finish();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user