Direct3D thread safety review

Stefan Dösinger stefandoesinger at
Fri May 18 10:19:22 CDT 2007


After writing some tests for synchronisation in ddraw, I have new versions of 
my thread safety patches for ddraw. I want to show them for some ideas / 
comments before sending them in.

Basically windows ddraw seems to hold a DLL global lock whenever some code of 
the DLL is executed even in functions that wouldn't need it(like AddRef, can 
use interlocked addref), unrelated calls(2 different ddraw objects or 
surfaces) or before checking errornous params.

As per Alexandre's comments, we don't want to copy all this insane locking 
exactly(until we find an app that really needs this. Basically my 2 patches 
handle it like this(for the ddraw object only - all others will follow):

* When a method needs locking, the lock is aquired after printing the trace, 
but before checking error conditions(like windows).
* If a method doesn't need locking(e.g. unimplemented, or just a getter for 
static info(GetCaps), or QI / AddRef / Release), then the lock is not held

Since ddraw, d3d8 and d3d9 need their own locking anyway, my plan is to 
implement locking in them and assume synchronised calls in wined3d - ie no 
wined3d locking. No 2 threads may call wined3d at the same time, and 
ddraw/d3d8/d3d9 have to take care of that. That keeps the code simpler.

Attached is my test(threading.c), the locking for main and ddraw(merged it 
accidentally - need to split it up again. The plan is to continue like that 
for the rest of ddraw and d3d8/9

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-DDraw-Make-the-ddraw-list-lock-a-global-dll-lock.patch
Type: text/x-diff
Size: 2751 bytes
Desc: not available
Url :
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-DDraw-Hold-the-lock-in-IDirectDrawX-methods.patch
Type: text/x-diff
Size: 21236 bytes
Desc: not available
Url :
-------------- next part --------------
A non-text attachment was scrubbed...
Name: threading.c
Type: text/x-csrc
Size: 13676 bytes
Desc: not available
Url :

More information about the wine-devel mailing list