Tracking: Make frame accessor cache safe for threading
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 14 Aug 2017 09:28:58 +0000 (11:28 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 14 Aug 2017 09:43:19 +0000 (11:43 +0200)
source/blender/blenkernel/intern/tracking_util.c
source/blender/blenkernel/tracking_private.h

index 2d61e9e4019aa2cf638af5fe58f8544fc6943cc7..bf2dabfab8bfc218c238ca96e91c7caaecdc3b47 100644 (file)
@@ -707,12 +707,11 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
 {
        ImBuf *ibuf, *orig_ibuf, *final_ibuf;
        int64_t transform_key = 0;
-
        if (transform != NULL) {
                transform_key = libmv_frameAccessorgetTransformKey(transform);
        }
-
        /* First try to get fully processed image from the cache. */
+       BLI_spin_lock(&accessor->cache_lock);
        ibuf = accesscache_get(accessor,
                               clip_index,
                               frame,
@@ -720,6 +719,7 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
                               downscale,
                               region,
                               transform_key);
+       BLI_spin_unlock(&accessor->cache_lock);
        if (ibuf != NULL) {
                CACHE_PRINTF("Used buffer from cache for frame %d\n", frame);
                return ibuf;
@@ -846,6 +846,7 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
         * cache and for how long.
         */
        if (false) {
+               BLI_spin_lock(&accessor->cache_lock);
                accesscache_put(accessor,
                                clip_index,
                                frame,
@@ -854,6 +855,7 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
                                region,
                                transform_key,
                                final_ibuf);
+               BLI_spin_unlock(&accessor->cache_lock);
        }
 
        return final_ibuf;
@@ -990,6 +992,8 @@ TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR
                                       accessor_get_mask_for_track_callback,
                                       accessor_release_mask_callback);
 
+       BLI_spin_init(&accessor->cache_lock);
+
        return accessor;
 }
 
index 1a68a1cac6af00f5c1b1b4799f1829564a763d5f..07236fb2096591d6ba7ae65df7fc5d82b94870e9 100644 (file)
@@ -125,6 +125,7 @@ typedef struct TrackingImageAccessor {
        int num_tracks;
        int start_frame;
        struct libmv_FrameAccessor *libmv_accessor;
+       SpinLock cache_lock;
 } TrackingImageAccessor;
 
 TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP],