[cairo] New per-scaled_font mutex to fix locking bugs

Bill Spitzak spitzak at d2.com
Mon Feb 5 18:08:24 PST 2007



Carl Worth wrote:

> For win32, I took a guess and came up with the following
> 
> 	typedef CRITICAL_SECTION cairo_mutex_t;
> 	# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
> 	# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
> 	# define CAIRO_MUTEX_NIL_INITIALIZER {}
> 
> The only thing I'm unsure of there is the NIL_INITIALIZER. This is
> only used when initializing the mutex for a nil surface, so the value
> won't ever be looked at, but it does need to compile at least.

I assumme your intention is to be able to type:

	static cairo_mutex_t foo = CAIRO_MUTEX_NIL_INITIALIZER;

Unfortunately as far as I can tell this is quite impossible. Windows 
insists you call InitializeCriticalSection(&cs), the mutex will not work 
without this code being executed because the existence, rather than the 
use, of the mutex is recorded by the system. The only proper way to do 
this is to put another lock around it, which is impossible because you 
would require an infinite recursion of locks. They could fix it by 
providing at least one CriticalSection object that you know is already 
initialized, but I have never heard of one. Normal solution is to some 
how provide some "init()" function and whatever necessary kludges are 
needed to make sure this is run before any attempt is made to lock anything.



More information about the cairo mailing list