mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 15:21:56 -05: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:
@@ -197,7 +197,8 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
|
||||
preview->preview->length = len_s;
|
||||
|
||||
if (preview->playback.is_valid()) {
|
||||
preview->thread = Thread::create(_preview_thread, preview);
|
||||
preview->thread = memnew(Thread);
|
||||
preview->thread->start(_preview_thread, preview);
|
||||
}
|
||||
|
||||
return preview->preview;
|
||||
@@ -218,7 +219,8 @@ void AudioStreamPreviewGenerator::_notification(int p_what) {
|
||||
for (Map<ObjectID, Preview>::Element *E = previews.front(); E; E = E->next()) {
|
||||
if (!E->get().generating) {
|
||||
if (E->get().thread) {
|
||||
Thread::wait_to_finish(E->get().thread);
|
||||
E->get().thread->wait_to_finish();
|
||||
memdelete(E->get().thread);
|
||||
E->get().thread = nullptr;
|
||||
}
|
||||
if (!ObjectDB::get_instance(E->key())) { //no longer in use, get rid of preview
|
||||
|
||||
Reference in New Issue
Block a user