1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-threads.h D-Bus threads handling
4 * Copyright (C) 2002 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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."
27 #ifndef DBUS_THREADS_H
28 #define DBUS_THREADS_H
30 #include <dbus/dbus-macros.h>
31 #include <dbus/dbus-types.h>
36 * @addtogroup DBusThreads
40 typedef struct DBusMutex DBusMutex;
41 typedef struct DBusCondVar DBusCondVar;
43 typedef DBusMutex* (* DBusMutexNewFunction) (void);
44 typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);
45 typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);
46 typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
48 typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);
49 typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);
50 typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);
51 typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);
53 typedef DBusCondVar* (* DBusCondVarNewFunction) (void);
54 typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);
55 typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,
57 typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,
59 int timeout_milliseconds);
60 typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);
61 typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);
65 DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,
66 DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,
67 DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,
68 DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,
69 DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,
70 DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,
71 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,
72 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,
73 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,
74 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,
75 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,
76 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,
77 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,
78 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,
79 DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 13) - 1
80 } DBusThreadFunctionsMask;
83 * Functions that must be implemented to make the D-Bus
84 * library thread-aware.
88 unsigned int mask; /**< Mask indicating which functions are present. */
90 DBusMutexNewFunction mutex_new; /**< Function to create a mutex */
91 DBusMutexFreeFunction mutex_free; /**< Function to free a mutex */
92 DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex */
93 DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex */
95 DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */
96 DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */
97 DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */
98 DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */
99 DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */
100 DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */
102 DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */
103 DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */
104 DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */
105 DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */
107 void (* padding1) (void); /**< Reserved for future expansion */
108 void (* padding2) (void); /**< Reserved for future expansion */
109 void (* padding3) (void); /**< Reserved for future expansion */
110 void (* padding4) (void); /**< Reserved for future expansion */
112 } DBusThreadFunctions;
114 dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
115 dbus_bool_t dbus_threads_init_default (void);
121 #endif /* DBUS_THREADS_H */