/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-threads.h D-Bus threads handling * * Copyright (C) 2002 Red Hat Inc. * * 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 /** * @addtogroup DBusThreads * @{ */ /** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ DBusMutex; /** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ DBusCondVar; /** Deprecated, provide DBusRecursiveMutexNewFunction instead. */ DBusMutexNewFunction; /** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */ DBusMutexFreeFunction; /** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */ DBusMutexLockFunction; /** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */ DBusMutexUnlockFunction; /** Creates a new recursively-lockable mutex, or returns #NULL if not * enough memory. Can only fail due to lack of memory. Found in * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for * this, because it does not save/restore the recursion count when * waiting on a condition. libdbus requires the Java-style behavior * where the mutex is fully unlocked to wait on a condition. */ DBusRecursiveMutexNewFunction; /** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions. */ DBusRecursiveMutexFreeFunction; /** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions. * Can only fail due to lack of memory. */ DBusRecursiveMutexLockFunction; /** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions. * Can only fail due to lack of memory. */ DBusRecursiveMutexUnlockFunction; /** Creates a new condition variable. Found in #DBusThreadFunctions. * Can only fail (returning #NULL) due to lack of memory. */ DBusCondVarNewFunction; /** Frees a condition variable. Found in #DBusThreadFunctions. */ DBusCondVarFreeFunction; /** Waits on a condition variable. Found in * #DBusThreadFunctions. Must work with either a recursive or * nonrecursive mutex, whichever the thread implementation * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with * condition variables (does not save/restore the recursion count) so * don't try using simply pthread_cond_wait() and a * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right. * * Has no error conditions. Must succeed if it returns. */ DBusCondVarWaitFunction; /** Waits on a condition variable with a timeout. Found in * #DBusThreadFunctions. Returns #TRUE if the wait did not * time out, and #FALSE if it did. * * Has no error conditions. Must succeed if it returns. */ DBusCondVarWaitTimeoutFunction; /** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions. * * Has no error conditions. Must succeed if it returns. */ DBusCondVarWakeOneFunction; /** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions. * * Has no error conditions. Must succeed if it returns. */ DBusCondVarWakeAllFunction; /** * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow * the library to detect older callers of dbus_threads_init() if new possible functions * are added to #DBusThreadFunctions. */ DBusThreadFunctionsMask; /** * Functions that must be implemented to make the D-Bus library * thread-aware. * * If you supply both recursive and non-recursive mutexes, * libdbus will use the non-recursive version for condition variables, * and the recursive version in other contexts. * * The condition variable functions have to work with nonrecursive * mutexes if you provide those, or with recursive mutexes if you * don't. */ 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 */