Mercurial > projects > dbus-d
comparison dbus-d/dsrc/org/freedesktop/dbus/c/Threads.d @ 0:a5576806d36d
recreate repository without any libs for lightweight repository
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 20 Oct 2007 18:07:18 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5576806d36d |
---|---|
1 /* -*- mode: C; c-file-style: "gnu" -*- */ | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 module org.freedesktop.dbus.c.Threads; | |
24 | |
25 import org.freedesktop.dbus.c.Types; | |
26 | |
27 extern(C): | |
28 /** | |
29 * @addtogroup DBusThreads | |
30 * @{ | |
31 */ | |
32 | |
33 /** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ | |
34 struct DBusMutex {}; | |
35 /** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ | |
36 struct DBusCondVar {}; | |
37 | |
38 /** Deprecated, provide DBusRecursiveMutexNewFunction instead. */ | |
39 alias DBusMutex* (* DBusMutexNewFunction) (); | |
40 /** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */ | |
41 alias void (* DBusMutexFreeFunction) (DBusMutex *mutex); | |
42 /** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */ | |
43 alias dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex); | |
44 /** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */ | |
45 alias dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex); | |
46 | |
47 /** Creates a new recursively-lockable mutex, or returns #NULL if not | |
48 * enough memory. Can only fail due to lack of memory. Found in | |
49 * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for | |
50 * this, because it does not save/restore the recursion count when | |
51 * waiting on a condition. libdbus requires the Java-style behavior | |
52 * where the mutex is fully unlocked to wait on a condition. | |
53 */ | |
54 alias DBusMutex* (* DBusRecursiveMutexNewFunction) (); | |
55 /** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions. | |
56 */ | |
57 alias void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex); | |
58 /** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions. | |
59 * Can only fail due to lack of memory. | |
60 */ | |
61 alias void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex); | |
62 /** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions. | |
63 * Can only fail due to lack of memory. | |
64 */ | |
65 alias void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex); | |
66 | |
67 /** Creates a new condition variable. Found in #DBusThreadFunctions. | |
68 * Can only fail (returning #NULL) due to lack of memory. | |
69 */ | |
70 alias DBusCondVar* (* DBusCondVarNewFunction) (); | |
71 /** Frees a condition variable. Found in #DBusThreadFunctions. | |
72 */ | |
73 alias void (* DBusCondVarFreeFunction) (DBusCondVar *cond); | |
74 | |
75 /** Waits on a condition variable. Found in | |
76 * #DBusThreadFunctions. Must work with either a recursive or | |
77 * nonrecursive mutex, whichever the thread implementation | |
78 * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with | |
79 * condition variables (does not save/restore the recursion count) so | |
80 * don't try using simply pthread_cond_wait() and a | |
81 * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right. | |
82 * | |
83 * Has no error conditions. Must succeed if it returns. | |
84 */ | |
85 alias void (* DBusCondVarWaitFunction) (DBusCondVar *cond, | |
86 DBusMutex *mutex); | |
87 | |
88 /** Waits on a condition variable with a timeout. Found in | |
89 * #DBusThreadFunctions. Returns #TRUE if the wait did not | |
90 * time out, and #FALSE if it did. | |
91 * | |
92 * Has no error conditions. Must succeed if it returns. | |
93 */ | |
94 alias dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond, | |
95 DBusMutex *mutex, | |
96 int timeout_milliseconds); | |
97 /** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions. | |
98 * | |
99 * Has no error conditions. Must succeed if it returns. | |
100 */ | |
101 alias void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond); | |
102 | |
103 /** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions. | |
104 * | |
105 * Has no error conditions. Must succeed if it returns. | |
106 */ | |
107 alias void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond); | |
108 | |
109 /** | |
110 * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow | |
111 * the library to detect older callers of dbus_threads_init() if new possible functions | |
112 * are added to #DBusThreadFunctions. | |
113 */ | |
114 enum DBusThreadFunctionsMask{ | |
115 DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0, | |
116 DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1, | |
117 DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2, | |
118 DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3, | |
119 DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4, | |
120 DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5, | |
121 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6, | |
122 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7, | |
123 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8, | |
124 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9, | |
125 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10, | |
126 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11, | |
127 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12, | |
128 DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13, | |
129 DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1 | |
130 } ; | |
131 | |
132 /** | |
133 * Functions that must be implemented to make the D-Bus library | |
134 * thread-aware. The recursive mutex functions should be specified | |
135 * rather than the old, deprecated nonrecursive ones. | |
136 * | |
137 * The condition variable functions have to work with recursive | |
138 * mutexes if you provide those, or with nonrecursive mutexes if you | |
139 * provide those. | |
140 * | |
141 * If implementing threads using pthreads, be aware that | |
142 * PTHREAD_MUTEX_RECURSIVE is broken in combination with condition | |
143 * variables. libdbus relies on the Java-style behavior that when | |
144 * waiting on a condition, the recursion count is saved and restored, | |
145 * and the mutex is completely unlocked, not just decremented one | |
146 * level of recursion. | |
147 * | |
148 * Thus with pthreads you probably have to roll your own emulated | |
149 * recursive mutexes, you can't use PTHREAD_MUTEX_RECURSIVE. This is | |
150 * what dbus_threads_init_default() does on platforms that use | |
151 * pthreads. | |
152 */ | |
153 struct DBusThreadFunctions{ | |
154 uint mask; /**< Mask indicating which functions are present. */ | |
155 | |
156 DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */ | |
157 DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */ | |
158 DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */ | |
159 DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */ | |
160 | |
161 DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */ | |
162 DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */ | |
163 DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */ | |
164 DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */ | |
165 DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */ | |
166 DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */ | |
167 | |
168 DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */ | |
169 DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */ | |
170 DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */ | |
171 DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */ | |
172 | |
173 void (* padding1) (); /**< Reserved for future expansion */ | |
174 void (* padding2) (); /**< Reserved for future expansion */ | |
175 void (* padding3) (); /**< Reserved for future expansion */ | |
176 void (* padding4) (); /**< Reserved for future expansion */ | |
177 | |
178 } ; | |
179 | |
180 dbus_bool_t dbus_threads_init (DBusThreadFunctions *functions); | |
181 dbus_bool_t dbus_threads_init_default (); | |
182 | |
183 /** @} */ | |
184 |