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"    36 static CRITICAL_SECTION init_lock;
    40 _dbus_threads_windows_init_global (
void)
    44   _dbus_threads_windows_ensure_ctor_linked ();
    46   InitializeCriticalSection (&init_lock);
    47   global_init_done = 
TRUE;
    55 static DWORD dbus_cond_event_tls = TLS_OUT_OF_INDEXES;
    58 static HMODULE dbus_dll_hmodule;
    61 _dbus_win_get_dll_hmodule (
void)
    63   return dbus_dll_hmodule;
    67 #define hinst_t HANDLE    69 #define hinst_t HINSTANCE    72 BOOL WINAPI DllMain (hinst_t, DWORD, LPVOID);
    76 DllMain (hinst_t hinstDLL,
    83     case DLL_PROCESS_ATTACH:
    84       dbus_dll_hmodule = hinstDLL;
    86     case DLL_THREAD_DETACH:
    87       if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
    89           event = TlsGetValue(dbus_cond_event_tls);
    91           TlsSetValue(dbus_cond_event_tls, 
NULL);
    94     case DLL_PROCESS_DETACH: 
    95       if (dbus_cond_event_tls != TLS_OUT_OF_INDEXES)
    97           event = TlsGetValue(dbus_cond_event_tls);
    99           TlsSetValue(dbus_cond_event_tls, 
NULL);
   101           TlsFree(dbus_cond_event_tls); 
   111 _dbus_platform_cmutex_new (
void)
   119 _dbus_platform_rmutex_new (
void)
   127 _dbus_platform_cmutex_free (
DBusCMutex *mutex)
   129   CloseHandle ((HANDLE *) mutex);
   133 _dbus_platform_rmutex_free (
DBusRMutex *mutex)
   135   CloseHandle ((HANDLE *) mutex);
   139 _dbus_platform_cmutex_lock (
DBusCMutex *mutex)
   141   WaitForSingleObject ((HANDLE *) mutex, INFINITE);
   145 _dbus_platform_rmutex_lock (
DBusRMutex *mutex)
   147   WaitForSingleObject ((HANDLE *) mutex, INFINITE);
   151 _dbus_platform_cmutex_unlock (
DBusCMutex *mutex)
   153   ReleaseMutex ((HANDLE *) mutex);
   157 _dbus_platform_rmutex_unlock (
DBusRMutex *mutex)
   159   ReleaseMutex ((HANDLE *) mutex);
   163 _dbus_platform_condvar_new (
void)
   173   InitializeCriticalSection (&cond->
lock);
   180   DeleteCriticalSection (&cond->
lock);
   192   HANDLE 
event = TlsGetValue (dbus_cond_event_tls);
   199       TlsSetValue (dbus_cond_event_tls, event);
   202   EnterCriticalSection (&cond->
lock);
   205   _dbus_assert (WaitForSingleObject (event, 0) == WAIT_TIMEOUT);
   209   LeaveCriticalSection (&cond->
lock);
   214   _dbus_platform_cmutex_unlock (mutex);
   215   retval = WaitForSingleObject (event, milliseconds);
   216   _dbus_platform_cmutex_lock (mutex);
   218   if (retval == WAIT_TIMEOUT)
   220       EnterCriticalSection (&cond->
lock);
   227       retval = WaitForSingleObject (event, 0);
   229       LeaveCriticalSection (&cond->
lock);
   232 #ifndef DBUS_DISABLE_ASSERT   233   EnterCriticalSection (&cond->
lock);
   238   LeaveCriticalSection (&cond->
lock);
   241   return retval != WAIT_TIMEOUT;
   248   _dbus_condvar_wait_win32 (cond, mutex, INFINITE);
   252 _dbus_platform_condvar_wait_timeout (
DBusCondVar               *cond,
   254                                      int                        timeout_milliseconds)
   256   return _dbus_condvar_wait_win32 (cond, mutex, timeout_milliseconds);
   260 _dbus_platform_condvar_wake_one (
DBusCondVar *cond)
   262   EnterCriticalSection (&cond->
lock);
   273   LeaveCriticalSection (&cond->
lock);
   282   if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
   284       dbus_cond_event_tls = TlsAlloc ();
   285       if (dbus_cond_event_tls == TLS_OUT_OF_INDEXES)
   296   EnterCriticalSection (&init_lock);
   303   LeaveCriticalSection (&init_lock);
   306 #ifdef DBUS_ENABLE_VERBOSE_MODE   308 _dbus_print_thread (
void)
 #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". 
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...
#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.