Commit: 773d85ab320b0a115ef23321435649e1a8a1ef63
Author: Antony Riakiotakis
Date:   Wed Jan 28 19:45:16 2015 +0100
Branches: master
https://developer.blender.org/rB773d85ab320b0a115ef23321435649e1a8a1ef63

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

===================================================================

M       source/blender/blenkernel/intern/sound.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/space_sequencer/sequencer_draw.c
M       source/blender/editors/space_sequencer/sequencer_preview.c
M       source/blender/makesdna/DNA_sound_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/sound.c 
b/source/blender/blenkernel/intern/sound.c
index 43daaf2..25ac3c9 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 34ad6d3..9daa693 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 6d7e4ad..3be6cd7 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 da00b0f..57c81e9 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 4ab22e4..cb132c1 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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to