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"
38 static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES;
41 static HMODULE dbus_dll_hmodule;
44 _dbus_win_get_dll_hmodule (
void)
46 return dbus_dll_hmodule;
50 #define hinst_t HANDLE
52 #define hinst_t HINSTANCE
55 BOOL WINAPI DllMain (hinst_t, DWORD, LPVOID);
59 DllMain (hinst_t hinstDLL,
66 case DLL_PROCESS_ATTACH:
67 dbus_dll_hmodule = hinstDLL;
69 case DLL_THREAD_DETACH:
70 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
72 event = TlsGetValue(dbus_cond_event_tls);
74 TlsSetValue(dbus_cond_event_tls,
NULL);
77 case DLL_PROCESS_DETACH:
78 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
80 event = TlsGetValue(dbus_cond_event_tls);
82 TlsSetValue(dbus_cond_event_tls,
NULL);
84 TlsFree(dbus_cond_event_tls);
94 _dbus_platform_cmutex_new (
void)
102 _dbus_platform_rmutex_new (
void)
110 _dbus_platform_cmutex_free (
DBusCMutex *mutex)
112 CloseHandle ((HANDLE *) mutex);
116 _dbus_platform_rmutex_free (
DBusRMutex *mutex)
118 CloseHandle ((HANDLE *) mutex);
122 _dbus_platform_cmutex_lock (
DBusCMutex *mutex)
124 WaitForSingleObject ((HANDLE *) mutex, INFINITE);
128 _dbus_platform_rmutex_lock (
DBusRMutex *mutex)
130 WaitForSingleObject ((HANDLE *) mutex, INFINITE);
134 _dbus_platform_cmutex_unlock (
DBusCMutex *mutex)
136 ReleaseMutex ((HANDLE *) mutex);
140 _dbus_platform_rmutex_unlock (
DBusRMutex *mutex)
142 ReleaseMutex ((HANDLE *) mutex);
146 _dbus_platform_condvar_new (
void)
156 InitializeCriticalSection (&cond->
lock);
163 DeleteCriticalSection (&cond->
lock);
175 HANDLE
event = TlsGetValue (dbus_cond_event_tls);
182 TlsSetValue (dbus_cond_event_tls, event);
185 EnterCriticalSection (&cond->
lock);
188 _dbus_assert (WaitForSingleObject (event, 0) == WAIT_TIMEOUT);
192 LeaveCriticalSection (&cond->
lock);
197 _dbus_platform_cmutex_unlock (mutex);
198 retval = WaitForSingleObject (event, milliseconds);
199 _dbus_platform_cmutex_lock (mutex);
201 if (retval == WAIT_TIMEOUT)
203 EnterCriticalSection (&cond->
lock);
210 retval = WaitForSingleObject (event, 0);
212 LeaveCriticalSection (&cond->
lock);
215 #ifndef DBUS_DISABLE_ASSERT
216 EnterCriticalSection (&cond->
lock);
221 LeaveCriticalSection (&cond->
lock);
224 return retval != WAIT_TIMEOUT;
231 _dbus_condvar_wait_win32 (cond, mutex, INFINITE);
235 _dbus_platform_condvar_wait_timeout (
DBusCondVar *cond,
237 int timeout_milliseconds)
239 return _dbus_condvar_wait_win32 (cond, mutex, timeout_milliseconds);
243 _dbus_platform_condvar_wake_one (
DBusCondVar *cond)
245 EnterCriticalSection (&cond->
lock);
256 LeaveCriticalSection (&cond->
lock);
265 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
267 dbus_cond_event_tls = TlsAlloc ();
268 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
#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
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".
dbus_bool_t dbus_threads_init(const DBusThreadFunctions *functions)
Initializes threads, like dbus_threads_init_default().
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.