Lumiera  0.pre.03
»edit your freedom«
sectionlock.h
Go to the documentation of this file.
1 /*
2  sectionlock.h - mutex state handle
3 
4  Copyright (C) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (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 of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 
22 
27 #ifndef LUMIERA_SECTIONLOCK_H
28 #define LUMIERA_SECTIONLOCK_H
29 
30 #include <pthread.h>
31 #include <nobug.h>
32 
33 
34 typedef void
35 (*lumiera_sectionlock_unlock_fn)(void*, struct nobug_flag* flag,
36  struct nobug_resource_user** handle,
37  const struct nobug_context ctx);
38 
43 {
44  void* lock;
45  lumiera_sectionlock_unlock_fn unlock;
46  NOBUG_IF_ALPHA(struct nobug_flag* flag);
47  RESOURCE_USER (rh);
48 };
49 typedef struct lumiera_sectionlock_struct lumiera_sectionlock;
50 typedef struct lumiera_sectionlock_struct* LumieraSectionlock;
51 
52 /* helper function for nobug */
53 static inline void
54 lumiera_sectionlock_ensureunlocked (LumieraSectionlock self)
55 {
56  ENSURE (!self->lock, "forgot to unlock");
57 }
58 
59 
66 #define LUMIERA_SECTION_UNLOCK_(section) \
67  do if ((section)->lock) \
68  { \
69  (section)->unlock((section)->lock, (section)->flag, \
70  &(section)->rh, NOBUG_CONTEXT); \
71  (section)->lock = NULL; \
72  } while (0)
73 
74 
75 #endif
76 /*
77 // Local Variables:
78 // mode: C
79 // c-file-style: "gnu"
80 // indent-tabs-mode: nil
81 // End:
82 */
sectionlock used to manage the state of mutexes.
Definition: sectionlock.h:42