Try to make configure.ac a bit smaller.
[gpgme.git] / src / sema.h
1 /* sema.h - Definitions for semaphores.
2    Copyright (C) 2000 Werner Koch (dd9jn)
3    Copyright (C) 2001, 2003, 2004, 2007 g10 Code GmbH
4
5    This file is part of GPGME.
6  
7    GPGME is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 2.1 of
10    the License, or (at your option) any later version.
11    
12    GPGME is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16    
17    You should have received a copy of the GNU Lesser General Public
18    License along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20    02111-1307, USA.  */
21
22 #ifndef SEMA_H
23 #define SEMA_H
24
25 struct critsect_s
26 {
27   const char *name;
28   void *priv;
29 };
30
31 #define DEFINE_GLOBAL_LOCK(name) \
32   struct critsect_s name = { #name, NULL }
33 #define DEFINE_STATIC_LOCK(name) \
34   static struct critsect_s name  = { #name, NULL }
35
36 #define DECLARE_LOCK(name) \
37   struct critsect_s name
38 #define INIT_LOCK(a)                    \
39   do                                    \
40     {                                   \
41       (a).name = #a;                    \
42       (a).priv = NULL;                  \
43     }                                   \
44   while (0)
45 #define DESTROY_LOCK(name) _gpgme_sema_cs_destroy (&(name))
46                        
47
48 #define LOCK(name)                      \
49   do                                    \
50     {                                   \
51       _gpgme_sema_cs_enter (&(name));   \
52     }                                   \
53   while (0)
54
55 #define UNLOCK(name)                    \
56   do                                    \
57     {                                   \
58       _gpgme_sema_cs_leave (&(name));   \
59     }                                   \
60   while (0)
61
62 void _gpgme_sema_subsystem_init (void);
63 void _gpgme_sema_cs_enter (struct critsect_s *s);
64 void _gpgme_sema_cs_leave (struct critsect_s *s);
65 void _gpgme_sema_cs_destroy (struct critsect_s *s);
66
67 #endif /* SEMA_H */