Thread functions
D-Bus secret internal implementation details

_dbus_rmutex_lock(), etc. More...

## Typedefs

typedef struct DBusRMutex | DBusRMutex
| A mutex which is recursive if possible, else non-recursive. More...
typedef struct DBusCMutex | DBusCMutex
| A mutex suitable for use with condition variables. More...

## Functions

void | _dbus_rmutex_new_at_location (DBusRMutex **location_p)
| Creates a new mutex or creates a no-op mutex if threads are not initialized. More...
void | _dbus_cmutex_new_at_location (DBusCMutex **location_p)
| Creates a new mutex or creates a no-op mutex if threads are not initialized. More...
void | _dbus_rmutex_free_at_location (DBusRMutex **location_p)
| Frees a DBusRMutex or removes it from the uninitialized mutex list; does nothing if passed a NULL pointer.
void | _dbus_cmutex_free_at_location (DBusCMutex **location_p)
| Frees a DBusCMutex and removes it from the uninitialized mutex list; does nothing if passed a NULL pointer.
void | _dbus_rmutex_lock (DBusRMutex *mutex)
| Locks a mutex. More...
void | _dbus_cmutex_lock (DBusCMutex *mutex)
| Locks a mutex. More...
void | _dbus_rmutex_unlock (DBusRMutex *mutex)
| Unlocks a mutex. More...
void | _dbus_cmutex_unlock (DBusCMutex *mutex)
| Unlocks a mutex. More...
DBusCondVar * | _dbus_condvar_new (void)
| Creates a new condition variable using the function supplied to dbus_threads_init(), or creates a no-op condition variable if threads are not initialized. More...
void | _dbus_condvar_new_at_location (DBusCondVar **location_p)
| This does the same thing as _dbus_condvar_new. More...
void | _dbus_condvar_free (DBusCondVar *cond)
| Frees a conditional variable created with dbus_condvar_new(); does nothing if passed a NULL pointer.
void | _dbus_condvar_free_at_location (DBusCondVar **location_p)
| Frees a conditional variable and removes it from the uninitialized_condvar_list; does nothing if passed a NULL pointer.
void | _dbus_condvar_wait (DBusCondVar *cond, DBusCMutex *mutex)
| Atomically unlocks the mutex and waits for the conditions variable to be signalled. More...
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, or for a timeout. More...
void | _dbus_condvar_wake_one (DBusCondVar *cond)
| If there are threads waiting on the condition variable, wake up exactly one. More...

## Detailed Description

_dbus_rmutex_lock(), etc.

Functions and macros related to threads and thread locks.

## Typedef Documentation

typedef struct DBusCMutex DBusCMutex

A mutex suitable for use with condition variables.

This is typically non-recursive.

Definition at line 45 of file dbus-threads-internal.h.

typedef struct DBusRMutex DBusRMutex

A mutex which is recursive if possible, else non-recursive.

This is typically recursive, but that cannot be relied upon.

Definition at line 39 of file dbus-threads-internal.h.

## Function Documentation

void _dbus_cmutex_lock | ( | DBusCMutex * | mutex) |  |

Locks a mutex.

Does nothing if passed a NULL pointer. Locks may be recursive if threading implementation initialized recursive locks.

Definition at line 185 of file dbus-threads.c.

References _dbus_current_generation.

void _dbus_cmutex_new_at_location | ( | DBusCMutex ** | location_p) |  |

Creates a new mutex or creates a no-op mutex if threads are not initialized.

May return NULL even if threads are initialized, indicating out-of-memory.

The returned mutex is suitable for use with condition variables.

The extra level of indirection given by allocating a pointer to point to the mutex location allows the threading module to swap out dummy mutexes for a real mutex so libraries can initialize threads even after the D-Bus API has been used.

Parameters

  location_p | the location of the new mutex, can return NULL on OOM

Definition at line 103 of file dbus-threads.c.

References _dbus_assert, _dbus_current_generation, _dbus_list_append(), and NULL.

Referenced by _dbus_connection_new_for_transport().

void _dbus_cmutex_unlock | ( | DBusCMutex * | mutex) |  |

Unlocks a mutex.

Does nothing if passed a NULL pointer.

Returns
  TRUE on success

Definition at line 209 of file dbus-threads.c.

References _dbus_current_generation.

DBusCondVar* _dbus_condvar_new | ( | void | ) |  |

Creates a new condition variable using the function supplied to dbus_threads_init(), or creates a no-op condition variable if threads are not initialized.

May return NULL even if threads are initialized, indicating out-of-memory.

Returns
  new mutex or NULL

Definition at line 224 of file dbus-threads.c.

References _dbus_current_generation.

Referenced by _dbus_condvar_new_at_location().

void _dbus_condvar_new_at_location | ( | DBusCondVar ** | location_p) |  |

This does the same thing as _dbus_condvar_new.

It however gives another level of indirection by allocating a pointer to point to the condvar location. This allows the threading module to swap out dummy condvars for a real condvar so libraries can initialize threads even after the D-Bus API has been used.

Returns
  the location of a new condvar or NULL on OOM

Definition at line 244 of file dbus-threads.c.

References _dbus_assert, _dbus_condvar_new(), _dbus_current_generation, _dbus_list_append(), and NULL.

Referenced by _dbus_connection_new_for_transport().

void _dbus_condvar_wait | ( | DBusCondVar * | cond,
|  | DBusCMutex * | mutex
| ) |  |

Atomically unlocks the mutex and waits for the conditions variable to be signalled.

Locks the mutex again before returning. Does nothing if passed a NULL pointer.

Definition at line 304 of file dbus-threads.c.

References _dbus_current_generation.

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, or for a timeout.

Locks the mutex again before returning. Does nothing if passed a NULL pointer. Return value is FALSE if we timed out, TRUE otherwise.

Parameters

  cond | the condition variable
  mutex | the mutex
  timeout_milliseconds | the maximum time to wait

Returns
  FALSE if the timeout occurred, TRUE if not

Definition at line 323 of file dbus-threads.c.

References _dbus_current_generation, and TRUE.

void _dbus_condvar_wake_one | ( | DBusCondVar * | cond) |  |

If there are threads waiting on the condition variable, wake up exactly one.

Does nothing if passed a NULL pointer.

Definition at line 340 of file dbus-threads.c.

References _dbus_current_generation.

void _dbus_rmutex_lock | ( | DBusRMutex * | mutex) |  |

Locks a mutex.

Does nothing if passed a NULL pointer. Locks may be recursive if threading implementation initialized recursive locks.

Definition at line 173 of file dbus-threads.c.

References _dbus_current_generation.

Referenced by _dbus_data_slot_allocator_alloc(), _dbus_data_slot_allocator_free(), _dbus_data_slot_list_get(), and _dbus_data_slot_list_set().

void _dbus_rmutex_new_at_location | ( | DBusRMutex ** | location_p) |  |

Creates a new mutex or creates a no-op mutex if threads are not initialized.

May return NULL even if threads are initialized, indicating out-of-memory.

If possible, the mutex returned by this function is recursive, to avoid deadlocks. However, that cannot be relied on.

The extra level of indirection given by allocating a pointer to point to the mutex location allows the threading module to swap out dummy mutexes for a real mutex so libraries can initialize threads even after the D-Bus API has been used.

Parameters

  location_p | the location of the new mutex, can return NULL on OOM

Definition at line 70 of file dbus-threads.c.

References _dbus_assert, _dbus_current_generation, _dbus_list_append(), and NULL.

Referenced by _dbus_connection_new_for_transport(), and _dbus_server_init_base().

void _dbus_rmutex_unlock | ( | DBusRMutex * | mutex) |  |

Unlocks a mutex.

Does nothing if passed a NULL pointer.

Returns
  TRUE on success

Definition at line 197 of file dbus-threads.c.

References _dbus_current_generation.

Referenced by _dbus_connection_unlock(), _dbus_data_slot_allocator_alloc(), _dbus_data_slot_allocator_free(), _dbus_data_slot_list_get(), and _dbus_data_slot_list_set().