Lumiera  0.pre.03
»edit your freedom«
mutex.c
Go to the documentation of this file.
1 /*
2  mutex.c - mutex
3 
4  Copyright (C) Lumiera.org
5  2008, 2009, 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 #include "lib/mutex.h"
23 
29 LumieraMutex
30 lumiera_mutex_init (LumieraMutex self,
31  const char* purpose,
32  struct nobug_flag* flag,
33  const struct nobug_context ctx)
34 {
35  if (self)
36  {
37  NOBUG_RESOURCE_HANDLE_INIT (self->rh);
38  NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "mutex", purpose, self, self->rh, ctx)
39  {
40  pthread_mutex_init (&self->mutex, NULL);
41  }
42  }
43  return self;
44 }
45 
46 
47 LumieraMutex
48 lumiera_mutex_destroy (LumieraMutex self,
49  struct nobug_flag* flag,
50  const struct nobug_context ctx)
51 {
52  if (self)
53  {
54  NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx)
55  {
56  if (pthread_mutex_destroy (&self->mutex))
57  LUMIERA_DIE (LOCK_DESTROY);
58  }
59  }
60  return self;
61 }
62 
63 
64 
65 /*
66 // Local Variables:
67 // mode: C
68 // c-file-style: "gnu"
69 // indent-tabs-mode: nil
70 // End:
71 */
#define LUMIERA_DIE(err)
Abort unconditionally with a &#39;Fatal Error!&#39; message.
Definition: error.h:63
Mutual exclusion locking, header.
LumieraMutex lumiera_mutex_init(LumieraMutex self, const char *purpose, struct nobug_flag *flag, const struct nobug_context ctx)
Initialise a mutex variable This initialises a &#39;fast&#39; default mutex which must not be locked recursiv...
Definition: mutex.c:30
LumieraMutex lumiera_mutex_destroy(LumieraMutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a mutex variable.
Definition: mutex.c:48