diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-09 19:54:25 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-09 19:54:25 +0300 |
commit | 1b28081102899654df629bafa876e19e629e8d7c (patch) | |
tree | 9921f395035efac722c7301c47a5c5cee5a82094 | |
parent | 69a486e038da6c430188cc46c48836f6949c0aca (diff) |
Mac + OpenMP + pthreads workaround: recent commit broke compile, just
moved it into threads.c now instead of having it duplicated in various
places.
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 30 | ||||
-rw-r--r-- | source/blender/editors/physics/physics_fluid.c | 17 | ||||
-rw-r--r-- | source/blender/editors/render/render_internal.c | 10 | ||||
-rw-r--r-- | source/blender/editors/render/render_preview.c | 22 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 6 |
7 files changed, 32 insertions, 73 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 9c393ad0ae1..2dbdfd06551 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -88,13 +88,6 @@ #include "BLI_winstuff.h" #endif -#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 - #define PTCACHE_DATA_FROM(data, type, from) if(data[type]) { memcpy(data[type], from, ptcache_data_size[type]); } #define PTCACHE_DATA_TO(data, type, index, to) if(data[type]) { memcpy(to, (char*)data[type] + (index ? index * ptcache_data_size[type] : 0), ptcache_data_size[type]); } @@ -2375,11 +2368,6 @@ typedef struct { static void *ptcache_make_cache_thread(void *ptr) { ptcache_make_cache_data *data = (ptcache_make_cache_data*)ptr; -#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 - for(; (*data->cfra_ptr <= data->endframe) && !data->break_operation; *data->cfra_ptr+=data->step) scene_update_for_newframe(data->scene, data->scene->lay); @@ -2497,10 +2485,6 @@ void BKE_ptcache_make_cache(PTCacheBaker* baker) thread_data.thread_ended = FALSE; old_progress = -1; -#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, ptcache_make_cache_thread, 1); BLI_insert_thread(&threads, (void*)&thread_data); diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index fec5f1803eb..628c2dc43a5 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -44,6 +44,10 @@ IF(WIN32) SET(INC ${INC} ${PTHREADS_INC}) ENDIF(WIN32) +IF(WITH_OPENMP) + ADD_DEFINITIONS(-DPARALLEL=1) +ENDIF(WITH_OPENMP) + BLENDERLIB(bf_blenlib "${SRC}" "${INC}") #if env['OURPLATFORM'] == 'linux2': # cflags='-pthread' diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 371fae3dda2..5f5a0720940 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -56,6 +56,12 @@ #include <sys/time.h> #endif +#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) +/* ************** libgomp (Apple gcc 4.2.1) TLS bug workaround *************** */ +extern pthread_key_t gomp_tls_key; +static void *thread_tls_data; +#endif + /* ********** basic thread control API ************ Many thread cases have an X amount of jobs, and only an Y amount of @@ -148,9 +154,17 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) tslot->avail= 1; } - if(thread_levels == 0) + if(thread_levels == 0) { MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); +#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) + /* workaround for Apple gcc 4.2.1 omp vs background thread bug, + we copy gomp thread local storage pointer to setting it again + inside the thread that we start */ + thread_tls_data = pthread_getspecific(gomp_tls_key); +#endif + } + thread_levels++; } } @@ -181,6 +195,18 @@ int BLI_available_thread_index(ListBase *threadbase) return 0; } +static void *tslot_thread_start(void *tslot_p) +{ + ThreadSlot *tslot= (ThreadSlot*)tslot_p; + +#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) + /* workaround for Apple gcc 4.2.1 omp vs background thread bug, + set gomp thread local storage pointer which was copied beforehand */ + pthread_setspecific (gomp_tls_key, thread_tls_data); +#endif + + return tslot->do_thread(tslot->callerdata); +} void BLI_insert_thread(ListBase *threadbase, void *callerdata) { @@ -190,7 +216,7 @@ void BLI_insert_thread(ListBase *threadbase, void *callerdata) if(tslot->avail) { tslot->avail= 0; tslot->callerdata= callerdata; - pthread_create(&tslot->pthread, NULL, tslot->do_thread, tslot->callerdata); + pthread_create(&tslot->pthread, NULL, tslot_thread_start, tslot); return; } } diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 65701f89c4e..1af2fa9f5b8 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -98,14 +98,6 @@ /* 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;}; @@ -328,11 +320,6 @@ static void *fluidsimSimulateThread(void *unused) { // *ptr) { //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) { @@ -1050,10 +1037,6 @@ int fluidsimBake(bContext *C, ReportList *reports, Object *ob) 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); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 85ec7cfcf34..22c4f9e729c 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -530,11 +530,6 @@ static void render_startjob(void *rjv, short *stop, short *do_update) 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, rj->reports); else @@ -640,11 +635,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) 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); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index aca13fbd66d..44ca80867e4 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -100,13 +100,6 @@ #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 */ @@ -1105,11 +1098,6 @@ 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 @@ -1140,11 +1128,6 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r 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); } @@ -1171,11 +1154,6 @@ 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); } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index b22728a16b3..1c4631837df 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -83,12 +83,6 @@ #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) |