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);
#define NULL
A null pointer, defined appropriately for C or C++.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_threads_init_platform_specific(void)
Initialize threads as in dbus_threads_init_default(), appropriately for the platform.
dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
DBusList * list
list thread-local-stored events waiting on the cond variable
void _dbus_threads_unlock_platform_specific(void)
Undo _dbus_threads_lock_platform_specific().
void _dbus_threads_lock_platform_specific(void)
Lock a static mutex used to protect _dbus_threads_init_platform_specific().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
CRITICAL_SECTION lock
lock protecting the list
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.