dbus-threads.h
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-threads.h D-Bus threads handling
*
* Copyright (C) 2002 Red Hat Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef DBUS_THREADS_H
#define DBUS_THREADS_H
#include <dbus/dbus-macros.h>
#include <dbus/dbus-types.h>
DBUS_BEGIN_DECLS
typedef struct DBusMutex DBusMutex;
typedef struct DBusCondVar DBusCondVar;
typedef DBusMutex* (* DBusMutexNewFunction) (void);
typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);
typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);
typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);
typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);
typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);
typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);
typedef DBusCondVar* (* DBusCondVarNewFunction) (void);
typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);
typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,
DBusMutex *mutex);
typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,
DBusMutex *mutex,
int timeout_milliseconds);
typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);
typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);
typedef enum
{
DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,
DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,
DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,
DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,
DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,
DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,
DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,
DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,
DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,
DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,
DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,
DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,
DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,
DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,
DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1
} DBusThreadFunctionsMask;
typedef struct
{
unsigned int mask;
DBusMutexNewFunction mutex_new;
DBusMutexFreeFunction mutex_free;
DBusMutexLockFunction mutex_lock;
DBusMutexUnlockFunction mutex_unlock;
DBusCondVarNewFunction condvar_new;
DBusCondVarFreeFunction condvar_free;
DBusCondVarWaitFunction condvar_wait;
DBusCondVarWaitTimeoutFunction condvar_wait_timeout;
DBusCondVarWakeOneFunction condvar_wake_one;
DBusCondVarWakeAllFunction condvar_wake_all;
DBusRecursiveMutexNewFunction recursive_mutex_new;
DBusRecursiveMutexFreeFunction recursive_mutex_free;
DBusRecursiveMutexLockFunction recursive_mutex_lock;
DBusRecursiveMutexUnlockFunction recursive_mutex_unlock;
void (* padding1) (void);
void (* padding2) (void);
void (* padding3) (void);
void (* padding4) (void);
} DBusThreadFunctions;
DBUS_EXPORT
dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
DBUS_EXPORT
dbus_bool_t dbus_threads_init_default (void);
DBUS_END_DECLS
#endif /* DBUS_THREADS_H */
DBUS_BEGIN_DECLS
#define DBUS_BEGIN_DECLS
Macro used prior to declaring functions in the D-Bus header files.
Definition dbus-macros.h:36
DBUS_END_DECLS
#define DBUS_END_DECLS
Macro used after declaring functions in the D-Bus header files.
Definition dbus-macros.h:37
DBusCondVarWaitTimeoutFunction
dbus_bool_t(* DBusCondVarWaitTimeoutFunction)(DBusCondVar *cond, DBusMutex *mutex, int timeout_milliseconds)
Waits on a condition variable with a timeout.
Definition dbus-threads.h:103
DBusCondVarWakeOneFunction
void(* DBusCondVarWakeOneFunction)(DBusCondVar *cond)
Wakes one waiting thread on a condition variable.
Definition dbus-threads.h:110
DBusMutexNewFunction
DBusMutex *(* DBusMutexNewFunction)(void)
Deprecated, provide DBusRecursiveMutexNewFunction instead.
Definition dbus-threads.h:48
DBusMutexLockFunction
dbus_bool_t(* DBusMutexLockFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexLockFunction instead.
Definition dbus-threads.h:52
DBusRecursiveMutexNewFunction
DBusMutex *(* DBusRecursiveMutexNewFunction)(void)
Creates a new recursively-lockable mutex, or returns NULL if not enough memory.
Definition dbus-threads.h:63
dbus_threads_init_default
dbus_bool_t dbus_threads_init_default(void)
Initializes threads.
Definition dbus-threads.c:442
DBusMutexUnlockFunction
dbus_bool_t(* DBusMutexUnlockFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexUnlockFunction instead.
Definition dbus-threads.h:54
DBusMutex
struct DBusMutex DBusMutex
An opaque mutex type provided by the DBusThreadFunctions implementation installed by dbus_threads_ini...
Definition dbus-threads.h:43
DBusRecursiveMutexFreeFunction
void(* DBusRecursiveMutexFreeFunction)(DBusMutex *mutex)
Frees a recursively-lockable mutex.
Definition dbus-threads.h:66
DBusCondVarWakeAllFunction
void(* DBusCondVarWakeAllFunction)(DBusCondVar *cond)
Wakes all waiting threads on a condition variable.
Definition dbus-threads.h:116
DBusRecursiveMutexUnlockFunction
void(* DBusRecursiveMutexUnlockFunction)(DBusMutex *mutex)
Unlocks a recursively-lockable mutex.
Definition dbus-threads.h:74
DBusCondVarWaitFunction
void(* DBusCondVarWaitFunction)(DBusCondVar *cond, DBusMutex *mutex)
Waits on a condition variable.
Definition dbus-threads.h:94
DBusCondVarNewFunction
DBusCondVar *(* DBusCondVarNewFunction)(void)
Creates a new condition variable.
Definition dbus-threads.h:79
DBusCondVarFreeFunction
void(* DBusCondVarFreeFunction)(DBusCondVar *cond)
Frees a condition variable.
Definition dbus-threads.h:82
DBusRecursiveMutexLockFunction
void(* DBusRecursiveMutexLockFunction)(DBusMutex *mutex)
Locks a recursively-lockable mutex.
Definition dbus-threads.h:70
dbus_threads_init
dbus_bool_t dbus_threads_init(const DBusThreadFunctions *functions)
Initializes threads, like dbus_threads_init_default().
Definition dbus-threads.c:395
DBusMutexFreeFunction
void(* DBusMutexFreeFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexFreeFunction instead.
Definition dbus-threads.h:50
DBusThreadFunctionsMask
DBusThreadFunctionsMask
Flags indicating which functions are present in DBusThreadFunctions.
Definition dbus-threads.h:124
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
DBusCondVar
Definition dbus-sysdeps-pthread.c:59
DBusCondVar::cond
pthread_cond_t cond
the condition
Definition dbus-sysdeps-pthread.c:60
DBusThreadFunctions
Functions that must be implemented to make the D-Bus library thread-aware.
Definition dbus-threads.h:155
DBusThreadFunctions::mutex_free
DBusMutexFreeFunction mutex_free
Function to free a mutex; optional and deprecated.
Definition dbus-threads.h:159
DBusThreadFunctions::recursive_mutex_unlock
DBusRecursiveMutexUnlockFunction recursive_mutex_unlock
Function to unlock a recursive mutex.
Definition dbus-threads.h:173
DBusThreadFunctions::condvar_wake_all
DBusCondVarWakeAllFunction condvar_wake_all
Function to wake all threads waiting on the condition.
Definition dbus-threads.h:168
DBusThreadFunctions::condvar_new
DBusCondVarNewFunction condvar_new
Function to create a condition variable.
Definition dbus-threads.h:163
DBusThreadFunctions::mutex_lock
DBusMutexLockFunction mutex_lock
Function to lock a mutex; optional and deprecated.
Definition dbus-threads.h:160
DBusThreadFunctions::padding4
void(* padding4)(void)
Reserved for future expansion.
Definition dbus-threads.h:178
DBusThreadFunctions::mutex_unlock
DBusMutexUnlockFunction mutex_unlock
Function to unlock a mutex; optional and deprecated.
Definition dbus-threads.h:161
DBusThreadFunctions::mutex_new
DBusMutexNewFunction mutex_new
Function to create a mutex; optional and deprecated.
Definition dbus-threads.h:158
DBusThreadFunctions::condvar_wake_one
DBusCondVarWakeOneFunction condvar_wake_one
Function to wake one thread waiting on the condition.
Definition dbus-threads.h:167
DBusThreadFunctions::condvar_wait_timeout
DBusCondVarWaitTimeoutFunction condvar_wait_timeout
Function to wait on a condition with a timeout.
Definition dbus-threads.h:166
DBusThreadFunctions::recursive_mutex_free
DBusRecursiveMutexFreeFunction recursive_mutex_free
Function to free a recursive mutex.
Definition dbus-threads.h:171
DBusThreadFunctions::mask
unsigned int mask
Mask indicating which functions are present.
Definition dbus-threads.h:156
DBusThreadFunctions::padding2
void(* padding2)(void)
Reserved for future expansion.
Definition dbus-threads.h:176
DBusThreadFunctions::padding3
void(* padding3)(void)
Reserved for future expansion.
Definition dbus-threads.h:177
DBusThreadFunctions::padding1
void(* padding1)(void)
Reserved for future expansion.
Definition dbus-threads.h:175
DBusThreadFunctions::condvar_free
DBusCondVarFreeFunction condvar_free
Function to free a condition variable.
Definition dbus-threads.h:164
DBusThreadFunctions::condvar_wait
DBusCondVarWaitFunction condvar_wait
Function to wait on a condition.
Definition dbus-threads.h:165
DBusThreadFunctions::recursive_mutex_lock
DBusRecursiveMutexLockFunction recursive_mutex_lock
Function to lock a recursive mutex.
Definition dbus-threads.h:172
DBusThreadFunctions::recursive_mutex_new
DBusRecursiveMutexNewFunction recursive_mutex_new
Function to create a recursive mutex.
Definition dbus-threads.h:170