diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-01-28 21:45:16 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-01-28 21:45:29 +0300 |
commit | 773d85ab320b0a115ef23321435649e1a8a1ef63 (patch) | |
tree | 265efab63d8f46ce971262229ff53c5e4992dd83 /source | |
parent | 424100cecbb202004e1687d5066b2c88e7a58f58 (diff) |
Based on Sergey's suggestion, use spinlocks for threaded loading of
waveforms.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 15 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 7 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 15 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_preview.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_sound_types.h | 4 |
5 files changed, 25 insertions, 20 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 43daaf2120c..25ac3c91b7f 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -118,9 +118,10 @@ void BKE_sound_free(bSound *sound) sound_free_waveform(sound); - if (sound->mutex) { - BLI_mutex_free(sound->mutex); - sound->mutex = NULL; + if (sound->spinlock) { + BLI_spin_end(sound->spinlock); + MEM_freeN(sound->spinlock); + sound->spinlock = NULL; } #endif /* WITH_AUDASPACE */ @@ -709,18 +710,18 @@ void sound_read_waveform(bSound *sound, short *stop) MEM_freeN(waveform->data); } MEM_freeN(waveform); - BLI_mutex_lock(sound->mutex); + BLI_spin_lock(sound->spinlock); sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); return; } sound_free_waveform(sound); - BLI_mutex_lock(sound->mutex); + BLI_spin_lock(sound->spinlock); sound->waveform = waveform; sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); } void sound_update_scene(Main *bmain, struct Scene *scene) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 34ad6d3ea61..9daa6931282 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6872,9 +6872,10 @@ static void direct_link_sound(FileData *fd, bSound *sound) sound->waveform = NULL; } - if (sound->mutex) - sound->mutex = BLI_mutex_alloc(); - + if (sound->spinlock) { + sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound->spinlock); + } /* clear waveform loading flag */ sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 6d7e4ad1d8d..3be6cd79504 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -70,6 +70,7 @@ #include "WM_api.h" +#include "MEM_guardedalloc.h" /* own include */ #include "sequencer_intern.h" @@ -200,23 +201,25 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc SoundWaveform *waveform; - if (!sound->mutex) - sound->mutex = BLI_mutex_alloc(); + if (!sound->spinlock) { + sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound->spinlock); + } - BLI_mutex_lock(sound->mutex); + BLI_spin_lock(sound->spinlock); if (!seq->sound->waveform) { if (!(sound->flags & SOUND_FLAGS_WAVEFORM_LOADING)) { /* prevent sounds from reloading */ seq->sound->flags |= SOUND_FLAGS_WAVEFORM_LOADING; - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); sequencer_preview_add_sound(C, seq); } else { - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); } return; /* nothing to draw */ } - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); waveform = seq->sound->waveform; diff --git a/source/blender/editors/space_sequencer/sequencer_preview.c b/source/blender/editors/space_sequencer/sequencer_preview.c index da00b0ff6e1..57c81e919e5 100644 --- a/source/blender/editors/space_sequencer/sequencer_preview.c +++ b/source/blender/editors/space_sequencer/sequencer_preview.c @@ -95,9 +95,9 @@ static void preview_startjob(void *data, short *stop, short *do_update, float *p sound = previewjb->sound; /* make sure we cleanup the loading flag! */ - BLI_mutex_lock(sound->mutex); + BLI_spin_lock(sound->spinlock); sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING; - BLI_mutex_unlock(sound->mutex); + BLI_spin_unlock(sound->spinlock); BLI_mutex_lock(pj->mutex); previewjb = previewjb->next; diff --git a/source/blender/makesdna/DNA_sound_types.h b/source/blender/makesdna/DNA_sound_types.h index 4ab22e4f7b7..cb132c1b550 100644 --- a/source/blender/makesdna/DNA_sound_types.h +++ b/source/blender/makesdna/DNA_sound_types.h @@ -95,8 +95,8 @@ typedef struct bSound { */ void *playback_handle; - /* mutex for asynchronous loading of sounds */ - void *mutex; + /* spinlock for asynchronous loading of sounds */ + void *spinlock; /* XXX unused currently (SOUND_TYPE_LIMITER) */ /* float start, end; */ } bSound; |