Multiple implementation of thread locks in Windows code
In the dbus Windows code there is
_dbus_win_startup_winsock (void)
{
...
if (!_DBUS_LOCK (sysdeps))
return FALSE;
...
and for example
dbus_bool_t
_dbus_daemon_is_session_bus_address_published()
...
lock = _dbus_global_lock (...);
...
Looking at the two implementations, it turned out that DBUS_LOCK() uses _dbus_lock(), which is based on _dbus_platform_rmutex_lock(), which uses WaitForSingleObject(). _dbus_global_lock() also uses WaitForSingleObject().
The main differences are that _dbus_global_lock() creates a named mutex for sharing the mutex between processes, uses a different return type and evaluates the results of WaitForSingleObject somehow.
I propose to integrate _dbus_global_lock()/_dbus_global_unlock() into the current _dbus_platform_rmutex_xxx functions, adjust the implementation (including #369 (closed)), create a new function for generating the named mutex e.g. _dbus_platform_rmutex_named_new (const char* name)
as:
DBusRMutex *
_dbus_platform_rmutex_named_new (const char* name)
{
HANDLE handle;
handle = CreateMutex (NULL, FALSE, name);
return (DBusRMutex *) handle;
}
and use that (and related) functions in the autolaunch related Windows code, to reduce this code duplication and future maintenance overhead.