Revision: 25443 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25443 Author: damien78 Date: 2009-12-17 18:05:28 +0100 (Thu, 17 Dec 2009)
Log Message: ----------- OSX vs OpenMP : implement workaround to fix crashes when using mop from a background thread Fix# 20043 & 20392 The issue is that OSX lib does not implement TLS (Thread Local Storage), so libgomp uses pthread functions to read/write thread specific vars. But this implementation is currently (gcc 4.2) buggy : the write function is called only at lib start (in main thread), and the var is undefined for background thread. The workaround is to perform this gomp_tls_key var write at beginning of background threads that use openMP. (Currently: render & fluidsim) Modified Paths: -------------- trunk/blender/intern/elbeem/CMakeLists.txt trunk/blender/intern/elbeem/SConscript trunk/blender/source/blender/editors/CMakeLists.txt trunk/blender/source/blender/editors/physics/SConscript trunk/blender/source/blender/editors/physics/physics_fluid.c trunk/blender/source/blender/editors/screen/SConscript trunk/blender/source/blender/editors/screen/screen_ops.c Modified: trunk/blender/intern/elbeem/CMakeLists.txt =================================================================== --- trunk/blender/intern/elbeem/CMakeLists.txt 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/intern/elbeem/CMakeLists.txt 2009-12-17 17:05:28 UTC (rev 25443) @@ -33,9 +33,9 @@ ADD_DEFINITIONS(-DUSE_MSVC6FIXES) ENDIF(WINDOWS) -IF(WITH_OPENMP AND NOT APPLE) +IF(WITH_OPENMP) ADD_DEFINITIONS(-DPARALLEL=1) -ENDIF(WITH_OPENMP AND NOT APPLE) +ENDIF(WITH_OPENMP) BLENDERLIB_NOLIST(bf_elbeem "${SRC}" "${INC}") #, libtype='blender', priority=0 ) Modified: trunk/blender/intern/elbeem/SConscript =================================================================== --- trunk/blender/intern/elbeem/SConscript 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/intern/elbeem/SConscript 2009-12-17 17:05:28 UTC (rev 25443) @@ -8,8 +8,7 @@ defs = 'NOGUI ELBEEM_BLENDER=1' if env['WITH_BF_OPENMP']: - if env['OURPLATFORM'] != 'darwin': - defs += ' PARALLEL' + defs += ' PARALLEL' if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): defs += ' USE_MSVC6FIXES' Modified: trunk/blender/source/blender/editors/CMakeLists.txt =================================================================== --- trunk/blender/source/blender/editors/CMakeLists.txt 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/source/blender/editors/CMakeLists.txt 2009-12-17 17:05:28 UTC (rev 25443) @@ -71,6 +71,10 @@ ADD_DEFINITIONS(-DWITH_FFMPEG) ENDIF(WITH_FFMPEG) +IF(WITH_OPENMP) + ADD_DEFINITIONS(-DPARALLEL=1) +ENDIF(WITH_OPENMP) + IF(NOT WITH_ELBEEM) ADD_DEFINITIONS(-DDISABLE_ELBEEM) ENDIF(NOT WITH_ELBEEM) Modified: trunk/blender/source/blender/editors/physics/SConscript =================================================================== --- trunk/blender/source/blender/editors/physics/SConscript 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/source/blender/editors/physics/SConscript 2009-12-17 17:05:28 UTC (rev 25443) @@ -8,6 +8,8 @@ incs += ' ../../gpu' incs += ' ../../makesrna ../../render/extern/include #/intern/elbeem/extern' +defs = '' + if env['OURPLATFORM'] == 'linux2': cflags='-pthread' incs += ' ../../../extern/binreloc/include' @@ -15,4 +17,9 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] -env.BlenderLib ( 'bf_editors_physics', sources, Split(incs), [], libtype=['core'], priority=[45] ) + +if env['OURPLATFORM'] == 'darwin': + if env['WITH_BF_OPENMP']: + defs += ' PARALLEL=1' + +env.BlenderLib ( 'bf_editors_physics', sources, Split(incs), Split(defs), libtype=['core'], priority=[45] ) Modified: trunk/blender/source/blender/editors/physics/physics_fluid.c =================================================================== --- trunk/blender/source/blender/editors/physics/physics_fluid.c 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/source/blender/editors/physics/physics_fluid.c 2009-12-17 17:05:28 UTC (rev 25443) @@ -98,6 +98,14 @@ /* enable/disable overall compilation */ #ifndef DISABLE_ELBEEM +#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 */ /* from header info.c */ static int start_progress_bar(void) {return 0;}; @@ -320,6 +328,11 @@ //char* fnameCfgPath = (char*)(ptr); int ret=0; +#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 + ret = elbeemSimulate(); BLI_lock_thread(LOCK_CUSTOM1); if(globalBakeState==0) { @@ -1036,6 +1049,11 @@ // set to neutral, -1 means user abort, -2 means init error globalBakeState = 0; globalBakeFrame = 0; + +#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 BLI_init_threads(&threads, fluidsimSimulateThread, 1); BLI_insert_thread(&threads, targetFile); Modified: trunk/blender/source/blender/editors/screen/SConscript =================================================================== --- trunk/blender/source/blender/editors/screen/SConscript 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/source/blender/editors/screen/SConscript 2009-12-17 17:05:28 UTC (rev 25443) @@ -22,4 +22,8 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] +if env['OURPLATFORM'] == 'darwin': + if env['WITH_BF_OPENMP']: + defs += ' PARALLEL=1' + env.BlenderLib ( 'bf_editors_screen', sources, Split(incs), Split(defs), libtype=['core'], priority=[105] ) Modified: trunk/blender/source/blender/editors/screen/screen_ops.c =================================================================== --- trunk/blender/source/blender/editors/screen/screen_ops.c 2009-12-17 16:28:45 UTC (rev 25442) +++ trunk/blender/source/blender/editors/screen/screen_ops.c 2009-12-17 17:05:28 UTC (rev 25443) @@ -96,6 +96,12 @@ #define KM_MODAL_STEP10 3 #define KM_MODAL_STEP10_OFF 4 +#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 /* ************** Exported Poll tests ********************** */ int ED_operator_regionactive(bContext *C) @@ -3015,6 +3021,11 @@ rj->stop= stop; rj->do_update= do_update; +#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(rj->anim) RE_BlenderAnim(rj->re, rj->scene, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step); else @@ -3096,6 +3107,11 @@ WM_jobs_timer(steve, 0.2, NC_SCENE|ND_RENDER_RESULT, 0); WM_jobs_callbacks(steve, render_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 + /* get a render result image, and make sure it is empty */ ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs