D-Bus: dbus-threads.h Source File

D-Bus 1.12.20

dbus-threads.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-threads.h D-Bus threads handling
3 *
4 * Copyright (C) 2002 Red Hat Inc.
5 *
6 * Licensed under the Academic Free License version 2.1
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23 #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 #error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
25 #endif
26
27 #ifndef DBUS_THREADS_H
28 #define DBUS_THREADS_H
29
30 #include <dbus/dbus-macros.h>
31 #include <dbus/dbus-types.h>
32
33 DBUS_BEGIN_DECLS
34
41 typedef struct DBusMutex DBusMutex;
43 typedef struct DBusCondVar DBusCondVar;
44
46 typedef DBusMutex* (* DBusMutexNewFunction) (void);
48 typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);
50 typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);
52 typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
53
61 typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);
64 typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);
68 typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);
72 typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);
73
77 typedef DBusCondVar* (* DBusCondVarNewFunction) (void);
80 typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);
81
92 typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,
93 DBusMutex *mutex);
94
101 typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,
102 DBusMutex *mutex,
103 int timeout_milliseconds);
108 typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);
109
114 typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);
115
121 typedef enum
122 {
123 DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,
124 DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,
125 DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,
126 DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,
127 DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,
128 DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,
129 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,
130 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,
131 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,
132 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,
133 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,
134 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,
135 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,
136 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,
137 DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1
138 } DBusThreadFunctionsMask;
139
152 typedef struct
153 {
154 unsigned int mask;
156 DBusMutexNewFunction mutex_new;
157 DBusMutexFreeFunction mutex_free;
158 DBusMutexLockFunction mutex_lock;
159 DBusMutexUnlockFunction mutex_unlock;
161 DBusCondVarNewFunction condvar_new;
162 DBusCondVarFreeFunction condvar_free;
163 DBusCondVarWaitFunction condvar_wait;
164 DBusCondVarWaitTimeoutFunction condvar_wait_timeout;
165 DBusCondVarWakeOneFunction condvar_wake_one;
166 DBusCondVarWakeAllFunction condvar_wake_all;
168 DBusRecursiveMutexNewFunction recursive_mutex_new;
169 DBusRecursiveMutexFreeFunction recursive_mutex_free;
170 DBusRecursiveMutexLockFunction recursive_mutex_lock;
171 DBusRecursiveMutexUnlockFunction recursive_mutex_unlock;
173 void (* padding1) (void);
174 void (* padding2) (void);
175 void (* padding3) (void);
176 void (* padding4) (void);
178 } DBusThreadFunctions;
179
180 DBUS_EXPORT
181 dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
182 DBUS_EXPORT
183 dbus_bool_t dbus_threads_init_default (void);
184
187 DBUS_END_DECLS
188
189 #endif /* DBUS_THREADS_H */
DBusThreadFunctions::condvar_wake_one
DBusCondVarWakeOneFunction condvar_wake_one
Function to wake one thread waiting on the condition.
Definition: dbus-threads.h:165
DBusThreadFunctions::mutex_lock
DBusMutexLockFunction mutex_lock
Function to lock a mutex; optional and deprecated.
Definition: dbus-threads.h:158
DBusThreadFunctions::mask
unsigned int mask
Mask indicating which functions are present.
Definition: dbus-threads.h:154
DBusThreadFunctions::recursive_mutex_unlock
DBusRecursiveMutexUnlockFunction recursive_mutex_unlock
Function to unlock a recursive mutex.
Definition: dbus-threads.h:171
DBusThreadFunctions
Functions that must be implemented to make the D-Bus library thread-aware.
Definition: dbus-threads.h:153
DBusCondVar
Definition: dbus-sysdeps-pthread.c:57
DBUS_END_DECLS
#define DBUS_END_DECLS
DBusThreadFunctions::recursive_mutex_new
DBusRecursiveMutexNewFunction recursive_mutex_new
Function to create a recursive mutex.
Definition: dbus-threads.h:168
DBusCondVarWakeOneFunction
void(* DBusCondVarWakeOneFunction)(DBusCondVar *cond)
Wakes one waiting thread on a condition variable.
Definition: dbus-threads.h:108
DBusThreadFunctions::mutex_free
DBusMutexFreeFunction mutex_free
Function to free a mutex; optional and deprecated.
Definition: dbus-threads.h:157
DBusCondVarWaitTimeoutFunction
dbus_bool_t(* DBusCondVarWaitTimeoutFunction)(DBusCondVar *cond, DBusMutex *mutex, int timeout_milliseconds)
Waits on a condition variable with a timeout.
Definition: dbus-threads.h:101
DBUS_BEGIN_DECLS
#define DBUS_BEGIN_DECLS
DBusRecursiveMutexLockFunction
void(* DBusRecursiveMutexLockFunction)(DBusMutex *mutex)
Locks a recursively-lockable mutex.
Definition: dbus-threads.h:68
DBusThreadFunctionsMask
DBusThreadFunctionsMask
Flags indicating which functions are present in DBusThreadFunctions.
Definition: dbus-threads.h:122
DBusCondVar::cond
pthread_cond_t cond
the condition
Definition: dbus-sysdeps-pthread.c:58
DBusThreadFunctions::mutex_unlock
DBusMutexUnlockFunction mutex_unlock
Function to unlock a mutex; optional and deprecated.
Definition: dbus-threads.h:159
DBusRecursiveMutexFreeFunction
void(* DBusRecursiveMutexFreeFunction)(DBusMutex *mutex)
Frees a recursively-lockable mutex.
Definition: dbus-threads.h:64
DBusMutexUnlockFunction
dbus_bool_t(* DBusMutexUnlockFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexUnlockFunction instead.
Definition: dbus-threads.h:52
DBusThreadFunctions::recursive_mutex_free
DBusRecursiveMutexFreeFunction recursive_mutex_free
Function to free a recursive mutex.
Definition: dbus-threads.h:169
DBusThreadFunctions::condvar_wait_timeout
DBusCondVarWaitTimeoutFunction condvar_wait_timeout
Function to wait on a condition with a timeout.
Definition: dbus-threads.h:164
DBusRecursiveMutexUnlockFunction
void(* DBusRecursiveMutexUnlockFunction)(DBusMutex *mutex)
Unlocks a recursively-lockable mutex.
Definition: dbus-threads.h:72
DBusMutexFreeFunction
void(* DBusMutexFreeFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexFreeFunction instead.
Definition: dbus-threads.h:48
DBusCondVarFreeFunction
void(* DBusCondVarFreeFunction)(DBusCondVar *cond)
Frees a condition variable.
Definition: dbus-threads.h:80
dbus_threads_init_default
dbus_bool_t dbus_threads_init_default(void)
Initializes threads.
Definition: dbus-threads.c:438
DBusThreadFunctions::condvar_free
DBusCondVarFreeFunction condvar_free
Function to free a condition variable.
Definition: dbus-threads.h:162
DBusCondVarNewFunction
DBusCondVar *(* DBusCondVarNewFunction)(void)
Creates a new condition variable.
Definition: dbus-threads.h:77
DBusCondVarWaitFunction
void(* DBusCondVarWaitFunction)(DBusCondVar *cond, DBusMutex *mutex)
Waits on a condition variable.
Definition: dbus-threads.h:92
DBusMutexLockFunction
dbus_bool_t(* DBusMutexLockFunction)(DBusMutex *mutex)
Deprecated, provide DBusRecursiveMutexLockFunction instead.
Definition: dbus-threads.h:50
DBusThreadFunctions::condvar_new
DBusCondVarNewFunction condvar_new
Function to create a condition variable.
Definition: dbus-threads.h:161
dbus_threads_init
dbus_bool_t dbus_threads_init(const DBusThreadFunctions *functions)
Initializes threads, like dbus_threads_init_default().
Definition: dbus-threads.c:391
DBusMutexNewFunction
DBusMutex *(* DBusMutexNewFunction)(void)
Deprecated, provide DBusRecursiveMutexNewFunction instead.
Definition: dbus-threads.h:46
DBusThreadFunctions::condvar_wait
DBusCondVarWaitFunction condvar_wait
Function to wait on a condition.
Definition: dbus-threads.h:163
DBusRecursiveMutexNewFunction
DBusMutex *(* DBusRecursiveMutexNewFunction)(void)
Creates a new recursively-lockable mutex, or returns NULL if not enough memory.
Definition: dbus-threads.h:61
DBusMutex
struct DBusMutex DBusMutex
An opaque mutex type provided by the DBusThreadFunctions implementation installed by dbus_threads_ini...
Definition: dbus-threads.h:41
DBusThreadFunctions::recursive_mutex_lock
DBusRecursiveMutexLockFunction recursive_mutex_lock
Function to lock a recursive mutex.
Definition: dbus-threads.h:170
DBusCondVarWakeAllFunction
void(* DBusCondVarWakeAllFunction)(DBusCondVar *cond)
Wakes all waiting threads on a condition variable.
Definition: dbus-threads.h:114
DBusThreadFunctions::mutex_new
DBusMutexNewFunction mutex_new
Function to create a mutex; optional and deprecated.
Definition: dbus-threads.h:156
DBusThreadFunctions::condvar_wake_all
DBusCondVarWakeAllFunction condvar_wake_all
Function to wake all threads waiting on the condition.
Definition: dbus-threads.h:166
dbus_bool_t
dbus_uint32_t dbus_bool_t
Definition: dbus-types.h:35