2003-01-05 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / dbus / dbus-threads.h
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 1.2
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 #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."
25 #endif
26
27 #ifndef DBUS_THREADS_H
28 #define DBUS_THREADS_H
29
30 #include <dbus/dbus-macros.h>
31 #include <dbus/dbus-types.h>
32
33 DBUS_BEGIN_DECLS;
34
35 typedef struct DBusMutex DBusMutex;
36
37 typedef DBusMutex*  (* DBusMutexNewFunction)    (void);
38 typedef void        (* DBusMutexFreeFunction)   (DBusMutex *mutex);
39 typedef dbus_bool_t (* DBusMutexLockFunction)   (DBusMutex *mutex);
40 typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
41
42 typedef enum 
43 {
44   DBUS_THREAD_FUNCTIONS_NEW_MASK     = 1 << 0,
45   DBUS_THREAD_FUNCTIONS_FREE_MASK    = 1 << 1,
46   DBUS_THREAD_FUNCTIONS_LOCK_MASK    = 1 << 2,
47   DBUS_THREAD_FUNCTIONS_UNLOCK_MASK  = 1 << 3,
48
49   DBUS_THREAD_FUNCTIONS_ALL_MASK     = 0xf
50 } DBusThreadFunctionsMask;
51
52 typedef struct
53 {
54   unsigned int mask;
55
56   DBusMutexNewFunction mutex_new;
57   DBusMutexFreeFunction mutex_free;
58   DBusMutexLockFunction mutex_lock;
59   DBusMutexUnlockFunction mutex_unlock;
60
61   void (* padding1) (void);
62   void (* padding2) (void);
63   void (* padding3) (void);
64   void (* padding4) (void);
65   void (* padding5) (void);
66   void (* padding6) (void);
67   void (* padding7) (void);
68   void (* padding8) (void);
69   
70 } DBusThreadFunctions;
71
72
73 DBusMutex*  dbus_mutex_new    (void);
74 void        dbus_mutex_free   (DBusMutex *mutex);
75 dbus_bool_t dbus_mutex_lock   (DBusMutex *mutex);
76 dbus_bool_t dbus_mutex_unlock (DBusMutex *mutex);
77
78 dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
79
80 typedef struct DBusStaticMutex DBusStaticMutex;
81
82 struct DBusStaticMutex
83 {
84   void *pad1;
85   void *pad2;
86   void *pad3;
87   void *pad4;
88 };
89
90 #define DBUS_STATIC_MUTEX_INIT { NULL, NULL, NULL, NULL }
91
92 dbus_bool_t dbus_static_mutex_lock   (DBusStaticMutex *mutex);
93 dbus_bool_t dbus_static_mutex_unlock (DBusStaticMutex *mutex);
94
95 DBUS_END_DECLS;
96
97 #endif /* DBUS_THREADS_H */