D-Bus: Thread functions

D-Bus 1.14.10

Typedefs | Functions
Thread functions
D-Bus secret internal implementation details

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

## 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.
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_rmutex_free_at_location (DBusRMutex **location_p)
| Frees a DBusRMutex; does nothing if passed a NULL pointer.
void | _dbus_cmutex_free_at_location (DBusCMutex **location_p)
| Frees a DBusCMutex; does nothing if passed a NULL pointer.
void | _dbus_rmutex_lock (DBusRMutex *mutex)
| Locks a mutex.
void | _dbus_cmutex_lock (DBusCMutex *mutex)
| Locks a mutex.
void | _dbus_rmutex_unlock (DBusRMutex *mutex)
| Unlocks a mutex.
void | _dbus_cmutex_unlock (DBusCMutex *mutex)
| Unlocks a mutex.
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.
void | _dbus_condvar_new_at_location (DBusCondVar **location_p)
| This does the same thing as _dbus_condvar_new.
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 condition variable; 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.
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.
void | _dbus_condvar_wake_one (DBusCondVar *cond)
| If there are threads waiting on the condition variable, wake up exactly one.
dbus_bool_t | _dbus_lock (DBusGlobalLock lock)
void | _dbus_unlock (DBusGlobalLock lock)

## Detailed Description

_dbus_rmutex_lock(), etc.

Functions and macros related to threads and thread locks.

## Typedef Documentation

## ◆ DBusCMutex

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.

## ◆ DBusRMutex

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

## ◆ _dbus_cmutex_free_at_location()

void _dbus_cmutex_free_at_location | ( | DBusCMutex ** | location_p | ) |

Frees a DBusCMutex; does nothing if passed a NULL pointer.

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

References NULL.

Referenced by _dbus_connection_new_for_transport().

## ◆ _dbus_cmutex_lock()

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 137 of file dbus-threads.c.

References NULL.

## ◆ _dbus_cmutex_new_at_location()

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.

Parameters

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

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

References _dbus_assert, dbus_threads_init_default(), and NULL.

Referenced by _dbus_connection_new_for_transport().

## ◆ _dbus_cmutex_unlock()

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

Unlocks a mutex.

Does nothing if passed a NULL pointer.

Returns
  TRUE on success

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

References NULL.

## ◆ _dbus_condvar_free()

void _dbus_condvar_free | ( | DBusCondVar * | cond | ) |

Frees a conditional variable created with dbus_condvar_new(); does nothing if passed a NULL pointer.

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

References NULL.

## ◆ _dbus_condvar_free_at_location()

void _dbus_condvar_free_at_location | ( | DBusCondVar ** | location_p | ) |

Frees a condition variable; does nothing if passed a NULL pointer.

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

References NULL.

Referenced by _dbus_connection_new_for_transport().

## ◆ _dbus_condvar_new()

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 182 of file dbus-threads.c.

References dbus_threads_init_default(), and NULL.

Referenced by _dbus_condvar_new_at_location().

## ◆ _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 used to be useful.

Returns
  the location of a new condvar or NULL on OOM

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

References _dbus_assert, _dbus_condvar_new(), and NULL.

Referenced by _dbus_connection_new_for_transport().

## ◆ _dbus_condvar_wait()

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 241 of file dbus-threads.c.

References NULL.

## ◆ _dbus_condvar_wait_timeout()

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 262 of file dbus-threads.c.

References NULL, and TRUE.

## ◆ _dbus_condvar_wake_one()

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 279 of file dbus-threads.c.

References NULL.

## ◆ _dbus_lock()

dbus_bool_t _dbus_lock | ( | DBusGlobalLock | lock | ) |

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

## ◆ _dbus_rmutex_free_at_location()

void _dbus_rmutex_free_at_location | ( | DBusRMutex ** | location_p | ) |

Frees a DBusRMutex; does nothing if passed a NULL pointer.

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

References NULL.

Referenced by _dbus_connection_new_for_transport(), _dbus_counter_unref(), _dbus_server_finalize_base(), and _dbus_server_init_base().

## ◆ _dbus_rmutex_lock()

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 123 of file dbus-threads.c.

References NULL.

Referenced by _dbus_counter_adjust_size(), _dbus_counter_adjust_unix_fd(), _dbus_counter_get_size_value(), _dbus_counter_get_unix_fd_value(), _dbus_counter_notify(), _dbus_counter_ref(), _dbus_counter_set_notify(), and _dbus_counter_unref().

## ◆ _dbus_rmutex_new_at_location()

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.

Parameters

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

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

References _dbus_assert, dbus_threads_init_default(), and NULL.

Referenced by _dbus_connection_new_for_transport(), _dbus_counter_new(), and _dbus_server_init_base().

## ◆ _dbus_rmutex_unlock()

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

Unlocks a mutex.

Does nothing if passed a NULL pointer.

Returns
  TRUE on success

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

References NULL.

Referenced by _dbus_connection_unlock(), _dbus_counter_adjust_size(), _dbus_counter_adjust_unix_fd(), _dbus_counter_get_size_value(), _dbus_counter_get_unix_fd_value(), _dbus_counter_notify(), _dbus_counter_ref(), _dbus_counter_set_notify(), and _dbus_counter_unref().

## ◆ _dbus_unlock()

void _dbus_unlock | ( | DBusGlobalLock | lock | ) |

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