27#include "dbus-internals.h"
28#include "dbus-sysdeps.h"
29#include "dbus-sysdeps-win.h"
30#include "dbus-threads.h"
37#ifdef DBUS_DISABLE_ASSERT
38#define THREAD_CHECK_TRUE(func_name, result_or_call) \
39 do { if (!(result_or_call)) { } } while (0)
41#define THREAD_CHECK_TRUE(func_name, result_or_call) do { \
42 if (!(result_or_call)) { \
43 _dbus_warn_check_failed ("thread function %s failed (windows error code=%ld) in %s", \
44 func_name, GetLastError (), _DBUS_FUNCTION_NAME); \
51static CRITICAL_SECTION init_lock;
55_dbus_threads_windows_init_global (
void)
59 _dbus_threads_windows_ensure_ctor_linked ();
61 InitializeCriticalSection (&init_lock);
62 global_init_done =
TRUE;
70static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES;
73static HMODULE dbus_dll_hmodule;
76_dbus_win_get_dll_hmodule (
void)
78 return dbus_dll_hmodule;
84#define hinst_t HINSTANCE
87BOOL WINAPI DllMain (hinst_t, DWORD, LPVOID);
91DllMain (hinst_t hinstDLL,
98 case DLL_PROCESS_ATTACH:
99 dbus_dll_hmodule = hinstDLL;
101 case DLL_THREAD_DETACH:
102 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
104 event = TlsGetValue(dbus_cond_event_tls);
106 TlsSetValue(dbus_cond_event_tls,
NULL);
109 case DLL_PROCESS_DETACH:
110 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
112 event = TlsGetValue(dbus_cond_event_tls);
114 TlsSetValue(dbus_cond_event_tls,
NULL);
116 TlsFree(dbus_cond_event_tls);
126_dbus_platform_cmutex_new (
void)
130 THREAD_CHECK_TRUE (
"CreateMutex", handle);
135_dbus_platform_rmutex_new (
void)
139 THREAD_CHECK_TRUE (
"CreateMutex", handle);
144_dbus_win_rmutex_named_new (
const char *name)
147 handle = CreateMutex (
NULL,
FALSE, name);
148 THREAD_CHECK_TRUE (
"CreateMutex", handle);
155 THREAD_CHECK_TRUE (
"CloseHandle", CloseHandle ((HANDLE *) mutex));
161 THREAD_CHECK_TRUE (
"CloseHandle", CloseHandle ((HANDLE *) mutex));
167 THREAD_CHECK_TRUE (
"WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0);
173 THREAD_CHECK_TRUE (
"WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0);
177_dbus_platform_cmutex_unlock (
DBusCMutex *mutex)
179 THREAD_CHECK_TRUE (
"ReleaseMutex", ReleaseMutex ((HANDLE *) mutex));
183_dbus_platform_rmutex_unlock (
DBusRMutex *mutex)
185 THREAD_CHECK_TRUE (
"ReleaseMutex", ReleaseMutex ((HANDLE *) mutex));
189_dbus_platform_condvar_new (
void)
199 InitializeCriticalSection (&cond->
lock);
206 DeleteCriticalSection (&cond->
lock);
218 HANDLE
event = TlsGetValue (dbus_cond_event_tls);
225 TlsSetValue (dbus_cond_event_tls, event);
228 EnterCriticalSection (&cond->
lock);
231 _dbus_assert (WaitForSingleObject (event, 0) == WAIT_TIMEOUT);
235 LeaveCriticalSection (&cond->
lock);
240 _dbus_platform_cmutex_unlock (mutex);
241 retval = WaitForSingleObject (event, milliseconds);
242 _dbus_platform_cmutex_lock (mutex);
244 if (retval == WAIT_TIMEOUT)
246 EnterCriticalSection (&cond->
lock);
253 retval = WaitForSingleObject (event, 0);
255 LeaveCriticalSection (&cond->
lock);
258#ifndef DBUS_DISABLE_ASSERT
259 EnterCriticalSection (&cond->
lock);
264 LeaveCriticalSection (&cond->
lock);
267 return retval != WAIT_TIMEOUT;
274 _dbus_condvar_wait_win32 (cond, mutex, INFINITE);
278_dbus_platform_condvar_wait_timeout (
DBusCondVar *cond,
280 int timeout_milliseconds)
282 return _dbus_condvar_wait_win32 (cond, mutex, timeout_milliseconds);
288 EnterCriticalSection (&cond->
lock);
299 LeaveCriticalSection (&cond->
lock);
308 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
310 dbus_cond_event_tls = TlsAlloc ();
311 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
322 EnterCriticalSection (&init_lock);
329 LeaveCriticalSection (&init_lock);
332#ifdef DBUS_ENABLE_VERBOSE_MODE
334_dbus_print_thread (
void)
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
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().
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
void _dbus_threads_lock_platform_specific(void)
Lock a static mutex used to protect _dbus_threads_init_platform_specific().
void _dbus_threads_unlock_platform_specific(void)
Undo _dbus_threads_lock_platform_specific().
dbus_bool_t _dbus_threads_init_platform_specific(void)
Initialize threads as in dbus_threads_init_default(), appropriately for the platform.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
CRITICAL_SECTION lock
lock protecting the list
DBusList * list
list thread-local-stored events waiting on the cond variable