25 #include "dbus-internals.h"
26 #include "dbus-sysdeps.h"
27 #include "dbus-sysdeps-win.h"
28 #include "dbus-threads.h"
29 #include "dbus-list.h"
34 static CRITICAL_SECTION init_lock;
38 _dbus_threads_windows_init_global (
void)
42 _dbus_threads_windows_ensure_ctor_linked ();
44 InitializeCriticalSection (&init_lock);
45 global_init_done =
TRUE;
53 static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES;
56 static HMODULE dbus_dll_hmodule;
59 _dbus_win_get_dll_hmodule (
void)
61 return dbus_dll_hmodule;
65 #define hinst_t HANDLE
67 #define hinst_t HINSTANCE
70 BOOL WINAPI DllMain (hinst_t, DWORD, LPVOID);
74 DllMain (hinst_t hinstDLL,
81 case DLL_PROCESS_ATTACH:
82 dbus_dll_hmodule = hinstDLL;
84 case DLL_THREAD_DETACH:
85 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
87 event = TlsGetValue(dbus_cond_event_tls);
89 TlsSetValue(dbus_cond_event_tls,
NULL);
92 case DLL_PROCESS_DETACH:
93 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
95 event = TlsGetValue(dbus_cond_event_tls);
97 TlsSetValue(dbus_cond_event_tls,
NULL);
99 TlsFree(dbus_cond_event_tls);
109 _dbus_platform_cmutex_new (
void)
117 _dbus_platform_rmutex_new (
void)
125 _dbus_platform_cmutex_free (
DBusCMutex *mutex)
127 CloseHandle ((HANDLE *) mutex);
131 _dbus_platform_rmutex_free (
DBusRMutex *mutex)
133 CloseHandle ((HANDLE *) mutex);
137 _dbus_platform_cmutex_lock (
DBusCMutex *mutex)
139 WaitForSingleObject ((HANDLE *) mutex, INFINITE);
143 _dbus_platform_rmutex_lock (
DBusRMutex *mutex)
145 WaitForSingleObject ((HANDLE *) mutex, INFINITE);
149 _dbus_platform_cmutex_unlock (
DBusCMutex *mutex)
151 ReleaseMutex ((HANDLE *) mutex);
155 _dbus_platform_rmutex_unlock (
DBusRMutex *mutex)
157 ReleaseMutex ((HANDLE *) mutex);
161 _dbus_platform_condvar_new (
void)
171 InitializeCriticalSection (&cond->
lock);
178 DeleteCriticalSection (&cond->
lock);
190 HANDLE
event = TlsGetValue (dbus_cond_event_tls);
197 TlsSetValue (dbus_cond_event_tls, event);
200 EnterCriticalSection (&cond->
lock);
203 _dbus_assert (WaitForSingleObject (event, 0) == WAIT_TIMEOUT);
207 LeaveCriticalSection (&cond->
lock);
212 _dbus_platform_cmutex_unlock (mutex);
213 retval = WaitForSingleObject (event, milliseconds);
214 _dbus_platform_cmutex_lock (mutex);
216 if (retval == WAIT_TIMEOUT)
218 EnterCriticalSection (&cond->
lock);
225 retval = WaitForSingleObject (event, 0);
227 LeaveCriticalSection (&cond->
lock);
230 #ifndef DBUS_DISABLE_ASSERT
231 EnterCriticalSection (&cond->
lock);
236 LeaveCriticalSection (&cond->
lock);
239 return retval != WAIT_TIMEOUT;
246 _dbus_condvar_wait_win32 (cond, mutex, INFINITE);
250 _dbus_platform_condvar_wait_timeout (
DBusCondVar *cond,
252 int timeout_milliseconds)
254 return _dbus_condvar_wait_win32 (cond, mutex, timeout_milliseconds);
258 _dbus_platform_condvar_wake_one (
DBusCondVar *cond)
260 EnterCriticalSection (&cond->
lock);
271 LeaveCriticalSection (&cond->
lock);
280 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
282 dbus_cond_event_tls = TlsAlloc ();
283 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
294 EnterCriticalSection (&init_lock);
301 LeaveCriticalSection (&init_lock);