OSX : Bugfix [#21293] add OpenMP apple gcc bug workaround for render preview
authorDamien Plisson <damien.plisson@yahoo.fr>
Mon, 22 Feb 2010 10:29:49 +0000 (10:29 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Mon, 22 Feb 2010 10:29:49 +0000 (10:29 +0000)
All openMP calls from a background thread need to have this thread var init workaround

source/blender/editors/render/Makefile
source/blender/editors/render/SConscript
source/blender/editors/render/render_preview.c

index ed25f0be02a86a2e540fee27b55a4e87135e8cb0..85b70172e0a0062db56e39fd603ed3eb0d8b170b 100644 (file)
@@ -54,3 +54,9 @@ CPPFLAGS += -I../../render/extern/include
 # own include 
 
 CPPFLAGS += -I../include 
+
+ifeq ($(OS), darwin)
+    ifeq ($(WITH_BF_OPENMP), true)
+        CPPFLAGS += -DPARALLEL=1
+    endif
+endif
index 575f988544c3cf1566c4f90a2333b2cb2000cde2..2b9737557cd0f6e8b1da465992d7a5fb6c8713a0 100644 (file)
@@ -24,4 +24,8 @@ if env['WITH_BF_QUICKTIME']:
 if env['USE_QTKIT']:
    env.Append(CFLAGS=['-DUSE_QTKIT'])
 
+if env['OURPLATFORM'] == 'darwin':
+    if env['WITH_BF_OPENMP']:
+       env.Append(CFLAGS=['-DPARALLEL=1'])
+
 env.BlenderLib ( 'bf_editors_render', sources, Split(incs), [], libtype=['core'], priority=[45])
index 1563c5a8e1d95758e94d84d2b34b0b82503f1036..aca13fbd66d5eaa8ab234cd9a2e4f99c669ea1b1 100644 (file)
 #define PR_XMAX                200
 #define PR_YMAX                195
 
+#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2)
+/* ************** libgomp (Apple gcc 4.2.1) TLS bug workaround *************** */
+#include <pthread.h>
+extern pthread_key_t gomp_tls_key;
+static void *thread_tls_data;
+#endif
+
 /* XXX */
 static int qtest() {return 0;}
 /* XXX */
@@ -1098,6 +1105,11 @@ static void common_preview_startjob(void *customdata, short *stop, short *do_upd
 {
        ShaderPreview *sp= customdata;
 
+#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2)
+       // Workaround for Apple gcc 4.2.1 omp vs background thread bug
+       pthread_setspecific (gomp_tls_key, thread_tls_data);
+#endif
+       
        if(sp->pr_method == PR_ICON_RENDER)
                icon_preview_startjob(customdata, stop, do_update);
        else
@@ -1127,7 +1139,12 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r
        WM_jobs_customdata(steve, sp, shader_preview_free);
        WM_jobs_timer(steve, 0.1, NC_MATERIAL, NC_MATERIAL);
        WM_jobs_callbacks(steve, common_preview_startjob, NULL, NULL);
-       
+
+#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2)
+       // Workaround for Apple gcc 4.2.1 omp vs background thread bug
+       thread_tls_data = pthread_getspecific(gomp_tls_key);
+#endif
+               
        WM_jobs_start(CTX_wm_manager(C), steve);
 }
 
@@ -1154,6 +1171,11 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
        WM_jobs_timer(steve, 0.1, NC_MATERIAL, NC_MATERIAL);
        WM_jobs_callbacks(steve, common_preview_startjob, NULL, shader_preview_updatejob);
        
+#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2)
+       // Workaround for Apple gcc 4.2.1 omp vs background thread bug
+       thread_tls_data = pthread_getspecific(gomp_tls_key);
+#endif
+       
        WM_jobs_start(CTX_wm_manager(C), steve);
 }