From 99fe462452be44efa618e83ad9bbecd722ae6ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Tue, 19 Jan 2021 13:29:41 +0100 Subject: 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) --- modules/theora/video_stream_theora.cpp | 7 ++----- modules/theora/video_stream_theora.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'modules/theora') diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 243265769e..1026d58b85 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -140,9 +140,7 @@ void VideoStreamPlaybackTheora::clear() { #ifdef THEORA_USE_THREAD_STREAMING thread_exit = true; thread_sem->post(); //just in case - Thread::wait_to_finish(thread); - memdelete(thread); - thread = nullptr; + thread.wait_to_finish(); ring_buffer.clear(); #endif @@ -181,7 +179,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { int read = file->get_buffer(read_buffer.ptr(), to_read); ring_buffer.write(read_buffer.ptr(), read); - thread = Thread::create(_streaming_thread, this); + thread.start(_streaming_thread, this); #endif @@ -669,7 +667,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { ring_buffer.resize(rb_power); read_buffer.resize(RB_SIZE_KB * 1024); thread_sem = Semaphore::create(); - thread = nullptr; thread_exit = false; thread_eof = false; diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index d2036b5cb4..c315d682da 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -112,7 +112,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback { Vector read_buffer; bool thread_eof; Semaphore *thread_sem; - Thread *thread; + Thread thread; volatile bool thread_exit; static void _streaming_thread(void *ud); -- cgit v1.2.3