25#include "dbus-internals.h"
26#include "dbus-sysdeps.h"
27#include "dbus-sysdeps-win.h"
28#include "dbus-threads.h"
35#ifdef DBUS_DISABLE_ASSERT
36#define THREAD_CHECK_TRUE(func_name, result_or_call) \
37 do { if (!(result_or_call)) { } } while (0)
39#define THREAD_CHECK_TRUE(func_name, result_or_call) do { \
40 if (!(result_or_call)) { \
41 _dbus_warn_check_failed ("thread function %s failed (windows error code=%ld) in %s", \
42 func_name, GetLastError (), _DBUS_FUNCTION_NAME); \
49static CRITICAL_SECTION init_lock;
53_dbus_threads_windows_init_global (
void)
57 _dbus_threads_windows_ensure_ctor_linked ();
59 InitializeCriticalSection (&init_lock);
60 global_init_done =
TRUE;
68static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES;
71static HMODULE dbus_dll_hmodule;
74_dbus_win_get_dll_hmodule (
void)
76 return dbus_dll_hmodule;
82#define hinst_t HINSTANCE
85BOOL WINAPI DllMain (hinst_t, DWORD, LPVOID);
89DllMain (hinst_t hinstDLL,
96 case DLL_PROCESS_ATTACH:
97 dbus_dll_hmodule = hinstDLL;
99 case DLL_THREAD_DETACH:
100 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
102 event = TlsGetValue(dbus_cond_event_tls);
104 TlsSetValue(dbus_cond_event_tls,
NULL);
107 case DLL_PROCESS_DETACH:
108 if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
110 event = TlsGetValue(dbus_cond_event_tls);
112 TlsSetValue(dbus_cond_event_tls,
NULL);
114 TlsFree(dbus_cond_event_tls);
124_dbus_platform_cmutex_new (
void)
128 THREAD_CHECK_TRUE (
"CreateMutex", handle);
133_dbus_platform_rmutex_new (
void)
137 THREAD_CHECK_TRUE (
"CreateMutex", handle);
142_dbus_win_rmutex_named_new (
const char *name)
145 handle = CreateMutex (
NULL,
FALSE, name);
146 THREAD_CHECK_TRUE (
"CreateMutex", handle);
153 THREAD_CHECK_TRUE (
"CloseHandle", CloseHandle ((HANDLE *) mutex));
159 THREAD_CHECK_TRUE (
"CloseHandle", CloseHandle ((HANDLE *) mutex));
165 THREAD_CHECK_TRUE (
"WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0);
171 THREAD_CHECK_TRUE (
"WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0);
175_dbus_platform_cmutex_unlock (
DBusCMutex *mutex)
177 THREAD_CHECK_TRUE (
"ReleaseMutex", ReleaseMutex ((HANDLE *) mutex));
181_dbus_platform_rmutex_unlock (
DBusRMutex *mutex)
183 THREAD_CHECK_TRUE (
"ReleaseMutex", ReleaseMutex ((HANDLE *) mutex));
187_dbus_platform_condvar_new (
void)
197 InitializeCriticalSection (&cond->
lock);
204 DeleteCriticalSection (&cond->
lock);
216 HANDLE
event = TlsGetValue (dbus_cond_event_tls);
223 TlsSetValue (dbus_cond_event_tls, event);
226 EnterCriticalSection (&cond->
lock);
229 _dbus_assert (WaitForSingleObject (event, 0) == WAIT_TIMEOUT);
233 LeaveCriticalSection (&cond->
lock);
238 _dbus_platform_cmutex_unlock (mutex);
239 retval = WaitForSingleObject (event, milliseconds);
240 _dbus_platform_cmutex_lock (mutex);
242 if (retval == WAIT_TIMEOUT)
244 EnterCriticalSection (&cond->
lock);
251 retval = WaitForSingleObject (event, 0);
253 LeaveCriticalSection (&cond->
lock);
256#ifndef DBUS_DISABLE_ASSERT
257 EnterCriticalSection (&cond->
lock);
262 LeaveCriticalSection (&cond->
lock);
265 return retval != WAIT_TIMEOUT;
272 _dbus_condvar_wait_win32 (cond, mutex, INFINITE);
276_dbus_platform_condvar_wait_timeout (
DBusCondVar *cond,
278 int timeout_milliseconds)
280 return _dbus_condvar_wait_win32 (cond, mutex, timeout_milliseconds);
286 EnterCriticalSection (&cond->
lock);
297 LeaveCriticalSection (&cond->
lock);
306 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
308 dbus_cond_event_tls = TlsAlloc ();
309 if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
320 EnterCriticalSection (&init_lock);
327 LeaveCriticalSection (&init_lock);
330#ifdef DBUS_ENABLE_VERBOSE_MODE
332_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