>> Now, since we are using C++ in HarfBuzz, I wonder if we can use 
>> constructors to initialize the static mutexes automatically?
>
> This little gem seems to do the trick:
>
> struct hb_static_mutex_t : hb_mutex_t
> {
>   hb_static_mutex_t (void) {
>     hb_mutex_init (this);
>   }
> };
>
>
> What do you think?

I _think_ this is OK, because critical sections are allowed be initialised in 
DllMain (according to http://msdn.microsoft.com/en-us/library/ms682583.aspx): 
"There are serious limits on what you can do in a DLL entry point. ... If your 
DLL is linked with the C run-time library (CRT), the entry point provided by 
the CRT calls the constructors and destructors for global and static C++ 
objects. Therefore, these restrictions for DllMain also apply to constructors 
and destructors and any code that is called from them" but "For example, 
DllMain can create synchronization objects such as critical sections and 
mutexes"

It does seem like this would need a destructor, too, to avoid leaking 
CRITICAL_SECTION objects (unless they're only ever destroyed at process 
shutdown, when it wouldn't be necessary). Of course, then the struct would need 
to be made non-copyable to avoid inadvertent early destruction.

Bradley

_______________________________________________
HarfBuzz mailing list
HarfBuzz@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/harfbuzz

Reply via email to