Path: blob/master/thirdparty/linuxbsd_headers/dbus/dbus-threads.h
9898 views
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */1/* dbus-threads.h D-Bus threads handling2*3* Copyright (C) 2002 Red Hat Inc.4*5* Licensed under the Academic Free License version 2.16*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*21*/22#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)23#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."24#endif2526#ifndef DBUS_THREADS_H27#define DBUS_THREADS_H2829#include <dbus/dbus-macros.h>30#include <dbus/dbus-types.h>3132DBUS_BEGIN_DECLS3334/**35* @addtogroup DBusThreads36* @{37*/3839/** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */40typedef struct DBusMutex DBusMutex;41/** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */42typedef struct DBusCondVar DBusCondVar;4344/** Deprecated, provide DBusRecursiveMutexNewFunction instead. */45typedef DBusMutex* (* DBusMutexNewFunction) (void);46/** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */47typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);48/** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */49typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);50/** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */51typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);5253/** Creates a new recursively-lockable mutex, or returns #NULL if not54* enough memory. Can only fail due to lack of memory. Found in55* #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for56* this, because it does not save/restore the recursion count when57* waiting on a condition. libdbus requires the Java-style behavior58* where the mutex is fully unlocked to wait on a condition.59*/60typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);61/** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions.62*/63typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);64/** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions.65* Can only fail due to lack of memory.66*/67typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);68/** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions.69* Can only fail due to lack of memory.70*/71typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);7273/** Creates a new condition variable. Found in #DBusThreadFunctions.74* Can only fail (returning #NULL) due to lack of memory.75*/76typedef DBusCondVar* (* DBusCondVarNewFunction) (void);77/** Frees a condition variable. Found in #DBusThreadFunctions.78*/79typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);8081/** Waits on a condition variable. Found in82* #DBusThreadFunctions. Must work with either a recursive or83* nonrecursive mutex, whichever the thread implementation84* provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with85* condition variables (does not save/restore the recursion count) so86* don't try using simply pthread_cond_wait() and a87* PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right.88*89* Has no error conditions. Must succeed if it returns.90*/91typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,92DBusMutex *mutex);9394/** Waits on a condition variable with a timeout. Found in95* #DBusThreadFunctions. Returns #TRUE if the wait did not96* time out, and #FALSE if it did.97*98* Has no error conditions. Must succeed if it returns.99*/100typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,101DBusMutex *mutex,102int timeout_milliseconds);103/** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions.104*105* Has no error conditions. Must succeed if it returns.106*/107typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);108109/** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions.110*111* Has no error conditions. Must succeed if it returns.112*/113typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);114115/**116* Flags indicating which functions are present in #DBusThreadFunctions. Used to allow117* the library to detect older callers of dbus_threads_init() if new possible functions118* are added to #DBusThreadFunctions.119*/120typedef enum121{122DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,123DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,124DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,125DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,126DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,127DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,128DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,129DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,130DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,131DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,132DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,133DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,134DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,135DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,136DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1137} DBusThreadFunctionsMask;138139/**140* Functions that must be implemented to make the D-Bus library141* thread-aware.142*143* If you supply both recursive and non-recursive mutexes,144* libdbus will use the non-recursive version for condition variables,145* and the recursive version in other contexts.146*147* The condition variable functions have to work with nonrecursive148* mutexes if you provide those, or with recursive mutexes if you149* don't.150*/151typedef struct152{153unsigned int mask; /**< Mask indicating which functions are present. */154155DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */156DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */157DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */158DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */159160DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */161DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */162DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */163DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */164DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */165DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */166167DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */168DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */169DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */170DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */171172void (* padding1) (void); /**< Reserved for future expansion */173void (* padding2) (void); /**< Reserved for future expansion */174void (* padding3) (void); /**< Reserved for future expansion */175void (* padding4) (void); /**< Reserved for future expansion */176177} DBusThreadFunctions;178179DBUS_EXPORT180dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);181DBUS_EXPORT182dbus_bool_t dbus_threads_init_default (void);183184/** @} */185186DBUS_END_DECLS187188#endif /* DBUS_THREADS_H */189190191