Based on Sergey's suggestion, use spinlocks for threaded loading of

waveforms.
This commit is contained in:
Antony Riakiotakis
2015-01-28 19:45:16 +01:00
parent 424100cecb
commit 773d85ab32
5 changed files with 25 additions and 20 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;