1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/dbus-1.0/dbus/dbus-threads.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,202 @@
1.4 +/* -*- mode: C; c-file-style: "gnu" -*- */
1.5 +/* dbus-threads.h D-Bus threads handling
1.6 + *
1.7 + * Copyright (C) 2002 Red Hat Inc.
1.8 + * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.9 + * Licensed under the Academic Free License version 2.1
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + *
1.21 + * You should have received a copy of the GNU General Public License
1.22 + * along with this program; if not, write to the Free Software
1.23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.24 + *
1.25 + */
1.26 +#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
1.27 +#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
1.28 +#endif
1.29 +
1.30 +#ifndef DBUS_THREADS_H
1.31 +#define DBUS_THREADS_H
1.32 +
1.33 +#include <dbus/dbus-macros.h>
1.34 +#include <dbus/dbus-types.h>
1.35 +
1.36 +DBUS_BEGIN_DECLS
1.37 +
1.38 +/**
1.39 + * @addtogroup DBusThreads
1.40 + * @{
1.41 + */
1.42 +
1.43 +/** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */
1.44 +typedef struct DBusMutex DBusMutex;
1.45 +/** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */
1.46 +typedef struct DBusCondVar DBusCondVar;
1.47 +
1.48 +/** Deprecated, provide DBusRecursiveMutexNewFunction instead. */
1.49 +typedef DBusMutex* (* DBusMutexNewFunction) (void);
1.50 +/** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */
1.51 +typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);
1.52 +/** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */
1.53 +typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);
1.54 +/** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */
1.55 +typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
1.56 +
1.57 +/** Creates a new recursively-lockable mutex, or returns #NULL if not
1.58 + * enough memory. Can only fail due to lack of memory. Found in
1.59 + * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for
1.60 + * this, because it does not save/restore the recursion count when
1.61 + * waiting on a condition. libdbus requires the Java-style behavior
1.62 + * where the mutex is fully unlocked to wait on a condition.
1.63 + */
1.64 +typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);
1.65 +/** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions.
1.66 + */
1.67 +typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);
1.68 +/** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions.
1.69 + * Can only fail due to lack of memory.
1.70 + */
1.71 +typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);
1.72 +/** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions.
1.73 + * Can only fail due to lack of memory.
1.74 + */
1.75 +typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);
1.76 +
1.77 +/** Creates a new condition variable. Found in #DBusThreadFunctions.
1.78 + * Can only fail (returning #NULL) due to lack of memory.
1.79 + */
1.80 +typedef DBusCondVar* (* DBusCondVarNewFunction) (void);
1.81 +/** Frees a condition variable. Found in #DBusThreadFunctions.
1.82 + */
1.83 +typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);
1.84 +
1.85 +/** Waits on a condition variable. Found in
1.86 + * #DBusThreadFunctions. Must work with either a recursive or
1.87 + * nonrecursive mutex, whichever the thread implementation
1.88 + * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with
1.89 + * condition variables (does not save/restore the recursion count) so
1.90 + * don't try using simply pthread_cond_wait() and a
1.91 + * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right.
1.92 + *
1.93 + * Has no error conditions. Must succeed if it returns.
1.94 + */
1.95 +typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,
1.96 + DBusMutex *mutex);
1.97 +
1.98 +/** Waits on a condition variable with a timeout. Found in
1.99 + * #DBusThreadFunctions. Returns #TRUE if the wait did not
1.100 + * time out, and #FALSE if it did.
1.101 + *
1.102 + * Has no error conditions. Must succeed if it returns.
1.103 + */
1.104 +typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,
1.105 + DBusMutex *mutex,
1.106 + int timeout_milliseconds);
1.107 +/** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions.
1.108 + *
1.109 + * Has no error conditions. Must succeed if it returns.
1.110 + */
1.111 +typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);
1.112 +
1.113 +/** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions.
1.114 + *
1.115 + * Has no error conditions. Must succeed if it returns.
1.116 + */
1.117 +typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);
1.118 +
1.119 +/**
1.120 + * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow
1.121 + * the library to detect older callers of dbus_threads_init() if new possible functions
1.122 + * are added to #DBusThreadFunctions.
1.123 + */
1.124 +typedef enum
1.125 +{
1.126 + DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,
1.127 + DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,
1.128 + DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,
1.129 + DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,
1.130 + DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,
1.131 + DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,
1.132 + DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,
1.133 + DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,
1.134 + DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,
1.135 + DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,
1.136 + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,
1.137 + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,
1.138 + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,
1.139 + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,
1.140 + DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1
1.141 +} DBusThreadFunctionsMask;
1.142 +
1.143 +/**
1.144 + * Functions that must be implemented to make the D-Bus library
1.145 + * thread-aware. The recursive mutex functions should be specified
1.146 + * rather than the old, deprecated nonrecursive ones.
1.147 + *
1.148 + * The condition variable functions have to work with recursive
1.149 + * mutexes if you provide those, or with nonrecursive mutexes if you
1.150 + * provide those.
1.151 + *
1.152 + * If implementing threads using pthreads, be aware that
1.153 + * PTHREAD_MUTEX_RECURSIVE is broken in combination with condition
1.154 + * variables. libdbus relies on the Java-style behavior that when
1.155 + * waiting on a condition, the recursion count is saved and restored,
1.156 + * and the mutex is completely unlocked, not just decremented one
1.157 + * level of recursion.
1.158 + *
1.159 + * Thus with pthreads you probably have to roll your own emulated
1.160 + * recursive mutexes, you can't use PTHREAD_MUTEX_RECURSIVE. This is
1.161 + * what dbus_threads_init_default() does on platforms that use
1.162 + * pthreads.
1.163 + */
1.164 +typedef struct
1.165 +{
1.166 + unsigned int mask; /**< Mask indicating which functions are present. */
1.167 +
1.168 + DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */
1.169 + DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */
1.170 + DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */
1.171 + DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */
1.172 +
1.173 + DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */
1.174 + DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */
1.175 + DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */
1.176 + DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */
1.177 + DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */
1.178 + DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */
1.179 +
1.180 + DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */
1.181 + DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */
1.182 + DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */
1.183 + DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */
1.184 +
1.185 + void (* padding1) (void); /**< Reserved for future expansion */
1.186 + void (* padding2) (void); /**< Reserved for future expansion */
1.187 + void (* padding3) (void); /**< Reserved for future expansion */
1.188 + void (* padding4) (void); /**< Reserved for future expansion */
1.189 +
1.190 +} DBusThreadFunctions;
1.191 +
1.192 +#ifdef __SYMBIAN32__
1.193 +IMPORT_C
1.194 +#endif
1.195 +dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
1.196 +#ifdef __SYMBIAN32__
1.197 +IMPORT_C
1.198 +#endif
1.199 +dbus_bool_t dbus_threads_init_default (void);
1.200 +
1.201 +/** @} */
1.202 +
1.203 +DBUS_END_DECLS
1.204 +
1.205 +#endif /* DBUS_THREADS_H */