[Bf-committers] Patch 6196 - Small multithreading optimization

Early Ehlinger early at respower.com
Fri Mar 9 15:18:14 CET 2007


For your consideration: a very small optimization designed to replace 
two "if" statements from BLI_threads with two array indexing operations.

This patch modifies BLI_lock_thread and BLI_unlock_thread to remove the 
"if" statement.

The exact mechanism is:

1) replace LOCK_IMAGE, LOCK_CUSTOM1 #-defines with an enum.
2) add LOCK_LAST to the enum to serve as an array bounds.
3) replace _image_lock and _custom1_lock with g_locks[ LOCK_LAST ].
4) ensure that g_locks[] is initialized properly.
5) modify BLI_lock_thread/BLI_unlock_thread to simply index into g_locks 
rather than use an if statement to decide which lock to use.
6) add some assert()'s for bounds checking the array.

As a (very) minor additional tweak, BLI_unlock_malloc_thread and 
BLI_lock_malloc_thread are modified to have ( void ) as parameters in 
order to remove two annoying warnings under MSVC:

warning C4113: 'void (__cdecl *)()' differs in parameter lists from 
'void (__cdecl *)(void)'

Shows up in the call to MEM_set_lock_callback otherwise.

-- Early Ehlinger, President, ResPower, Inc.


More information about the Bf-committers mailing list