Index: source/blender/blenlib/BLI_threads.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenlib/BLI_threads.h,v retrieving revision 1.9 diff -b -u -r1.9 BLI_threads.h --- source/blender/blenlib/BLI_threads.h 21 Dec 2006 15:44:46 -0000 1.9 +++ source/blender/blenlib/BLI_threads.h 9 Mar 2007 14:52:09 -0000 @@ -31,9 +31,30 @@ #ifndef BLI_THREADS_H #define BLI_THREADS_H -/* one custom lock available now. can be extended */ -#define LOCK_IMAGE 0 -#define LOCK_CUSTOM1 1 +/* + Lock identifiers. + + In the event that you need to change the number of locks, add + one before LOCK_LAST, and update the initalizers for g_locks[] in + blender/source/blender/blenlib/intern/threads.c +*/ +enum + { LOCK_IMAGE + /* lock to keep render engine from accessing the frame + buffer from multiple threads simultaneously */ + + , LOCK_CUSTOM1 + /* lock to keep */ + + , LOCK_TRACE + /* lock to keep Blender_Trace patch from accessing + Python from multiple threads simultaneously */ + + , LOCK_LAST + /* must be last, because it is used as the size + of the g_locks[] array. */ + }; + /* for tables, button in UI, etc */ #define BLENDER_MAX_THREADS 8 Index: source/blender/blenlib/intern/threads.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenlib/intern/threads.c,v retrieving revision 1.13 diff -b -u -r1.13 threads.c --- source/blender/blenlib/intern/threads.c 21 Dec 2006 15:44:46 -0000 1.13 +++ source/blender/blenlib/intern/threads.c 9 Mar 2007 14:52:09 -0000 @@ -84,8 +84,12 @@ ************************************************ */ static pthread_mutex_t _malloc_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_locks[ LOCK_LAST ] + = { PTHREAD_MUTEX_INITIALIZER /* LOCK_IMAGE */ + , PTHREAD_MUTEX_INITIALIZER /* LOCK_CUSTOM1 */ + , PTHREAD_MUTEX_INITIALIZER /* LOCK_TRACE */ + /* LOCK_LAST - NO ENTRY HERE */ }; + static int thread_levels= 0; /* threads can be invoked inside threads */ /* just a max for security reasons */ @@ -99,12 +103,12 @@ int avail; } ThreadSlot; -static void BLI_lock_malloc_thread() +static void BLI_lock_malloc_thread( void ) { pthread_mutex_lock(&_malloc_lock); } -static void BLI_unlock_malloc_thread() +static void BLI_unlock_malloc_thread( void ) { pthread_mutex_unlock(&_malloc_lock); } @@ -204,18 +208,16 @@ void BLI_lock_thread(int type) { - if (type==LOCK_IMAGE) - pthread_mutex_lock(&_image_lock); - else if (type==LOCK_CUSTOM1) - pthread_mutex_lock(&_custom1_lock); + assert( type >= 0 ); + assert( type < LOCK_LAST ); + pthread_mutex_lock( &g_locks[ type ] ); } void BLI_unlock_thread(int type) { - if (type==LOCK_IMAGE) - pthread_mutex_unlock(&_image_lock); - else if(type==LOCK_CUSTOM1) - pthread_mutex_unlock(&_custom1_lock); + assert( type >= 0 ); + assert( type < LOCK_LAST ); + pthread_mutex_unlock( &g_locks[ type ] ); } /* eof */