diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-04-18 06:03:19 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-04-18 06:03:19 +0400 |
commit | dfe2f8dc03267e041102837e92f547fb04881510 (patch) | |
tree | d9582c4667ce5b9e39e2adce40832aa4f44b4fe7 /source/blender/blenlib/intern/threads.c | |
parent | d7e08f2d33207fdf76b1b597ef0de9dec26e3987 (diff) | |
parent | 00e46ef739cf2bfddb8805af056aa59fd3b3c71c (diff) |
Merged changes in the trunk up to revision 28247.
Diffstat (limited to 'source/blender/blenlib/intern/threads.c')
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 351e0be1102..de7842727df 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -29,6 +29,7 @@ */ #include <errno.h> +#include <string.h> #include "MEM_guardedalloc.h" @@ -106,6 +107,8 @@ static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _preview_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t _rcache_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_t mainid; static int thread_levels= 0; /* threads can be invoked inside threads */ /* just a max for security reasons */ @@ -129,6 +132,11 @@ static void BLI_unlock_malloc_thread(void) pthread_mutex_unlock(&_malloc_lock); } +void BLI_threadapi_init(void) +{ + mainid = pthread_self(); +} + /* tot = 0 only initializes malloc mutex in a safe way (see sequence.c) problem otherwise: scene render will kill of the mutex! */ @@ -136,7 +144,7 @@ static void BLI_unlock_malloc_thread(void) void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) { int a; - + if(threadbase != NULL && tot > 0) { threadbase->first= threadbase->last= NULL; @@ -204,6 +212,13 @@ static void *tslot_thread_start(void *tslot_p) return tslot->do_thread(tslot->callerdata); } +int BLI_thread_is_main(void) { + pthread_t tid; + tid = pthread_self(); + + return !memcmp(&tid, &mainid, sizeof(pthread_t)); +} + void BLI_insert_thread(ListBase *threadbase, void *callerdata) { ThreadSlot *tslot; @@ -327,6 +342,8 @@ void BLI_lock_thread(int type) pthread_mutex_lock(&_viewer_lock); else if (type==LOCK_CUSTOM1) pthread_mutex_lock(&_custom1_lock); + else if (type==LOCK_RCACHE) + pthread_mutex_lock(&_rcache_lock); } void BLI_unlock_thread(int type) @@ -339,6 +356,8 @@ void BLI_unlock_thread(int type) pthread_mutex_unlock(&_viewer_lock); else if(type==LOCK_CUSTOM1) pthread_mutex_unlock(&_custom1_lock); + else if(type==LOCK_RCACHE) + pthread_mutex_unlock(&_rcache_lock); } /* Mutex Locks */ |