24#include "dbus-threads.h"
25#include "dbus-internals.h"
26#include "dbus-threads-internal.h"
30static int thread_init_generation = 0;
64 *location_p = _dbus_platform_rmutex_new ();
88 *location_p = _dbus_platform_cmutex_new ();
97 if (location_p ==
NULL)
100 if (*location_p !=
NULL)
101 _dbus_platform_rmutex_free (*location_p);
110 if (location_p ==
NULL)
113 if (*location_p !=
NULL)
114 _dbus_platform_cmutex_free (*location_p);
128 _dbus_platform_rmutex_lock (mutex);
142 _dbus_platform_cmutex_lock (mutex);
156 _dbus_platform_rmutex_unlock (mutex);
170 _dbus_platform_cmutex_unlock (mutex);
187 return _dbus_platform_condvar_new ();
218 _dbus_platform_condvar_free (cond);
227 if (location_p ==
NULL)
230 if (*location_p !=
NULL)
231 _dbus_platform_condvar_free (*location_p);
247 _dbus_platform_condvar_wait (cond, mutex);
264 int timeout_milliseconds)
269 return _dbus_platform_condvar_wait_timeout (cond, mutex,
270 timeout_milliseconds);
284 _dbus_platform_condvar_wake_one (cond);
291shutdown_global_locks (
void *nil)
295 for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
298 _dbus_platform_rmutex_free (global_locks[i]);
299 global_locks[i] =
NULL;
304init_global_locks (
void)
309 for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
313 global_locks[i] = _dbus_platform_rmutex_new ();
315 if (global_locks[i] ==
NULL)
319 _dbus_platform_rmutex_lock (global_locks[_DBUS_LOCK_shutdown_funcs]);
320 ok = _dbus_register_shutdown_func_unlocked (shutdown_global_locks,
NULL);
321 _dbus_platform_rmutex_unlock (global_locks[_DBUS_LOCK_shutdown_funcs]);
329 for (i = i - 1; i >= 0; i--)
331 _dbus_platform_rmutex_free (global_locks[i]);
332 global_locks[i] =
NULL;
339_dbus_lock (DBusGlobalLock lock)
348 _dbus_platform_rmutex_lock (global_locks[lock]);
353_dbus_unlock (DBusGlobalLock lock)
358 _dbus_platform_rmutex_unlock (global_locks[lock]);
404 !init_global_locks ())
448#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called,...
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.
void _dbus_rmutex_new_at_location(DBusRMutex **location_p)
Creates a new mutex or creates a no-op mutex if threads are not initialized.
void _dbus_cmutex_free_at_location(DBusCMutex **location_p)
Frees a DBusCMutex; does nothing if passed a NULL pointer.
DBusCondVar * _dbus_condvar_new(void)
Creates a new condition variable using the function supplied to dbus_threads_init(),...
void _dbus_condvar_free_at_location(DBusCondVar **location_p)
Frees a condition variable; does nothing if passed a NULL pointer.
void _dbus_rmutex_unlock(DBusRMutex *mutex)
Unlocks a mutex.
void _dbus_condvar_wait(DBusCondVar *cond, DBusCMutex *mutex)
Atomically unlocks the mutex and waits for the conditions variable to be signalled.
void _dbus_condvar_new_at_location(DBusCondVar **location_p)
This does the same thing as _dbus_condvar_new.
void _dbus_cmutex_new_at_location(DBusCMutex **location_p)
Creates a new mutex or creates a no-op mutex if threads are not initialized.
void _dbus_condvar_wake_one(DBusCondVar *cond)
If there are threads waiting on the condition variable, wake up exactly one.
dbus_bool_t _dbus_condvar_wait_timeout(DBusCondVar *cond, DBusCMutex *mutex, int timeout_milliseconds)
Atomically unlocks the mutex and waits for the conditions variable to be signalled,...
void _dbus_cmutex_lock(DBusCMutex *mutex)
Locks a mutex.
void _dbus_cmutex_unlock(DBusCMutex *mutex)
Unlocks a mutex.
void _dbus_rmutex_free_at_location(DBusRMutex **location_p)
Frees a DBusRMutex; does nothing if passed a NULL pointer.
void _dbus_rmutex_lock(DBusRMutex *mutex)
Locks a mutex.
void _dbus_condvar_free(DBusCondVar *cond)
Frees a conditional variable created with dbus_condvar_new(); does nothing if passed a NULL pointer.
dbus_bool_t dbus_threads_init_default(void)
Initializes threads.
dbus_bool_t dbus_threads_init(const DBusThreadFunctions *functions)
Initializes threads, like dbus_threads_init_default().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Functions that must be implemented to make the D-Bus library thread-aware.