Lumiera  0.pre.03
»edit your freedom«
recmutex.c
Go to the documentation of this file.
1 /*
2  recmutex.c - recursive mutex
3 
4  Copyright (C)
5  2008, 2009, Christian Thaeter <ct@pipapo.org>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 */
12 
13 #include "lib/recmutex.h"
14 
21 static pthread_once_t recmutexattr_once = PTHREAD_ONCE_INIT;
22 static pthread_mutexattr_t recmutexattr;
23 
24 static void recmutexattr_init()
25 {
26  pthread_mutexattr_init (&recmutexattr);
27  pthread_mutexattr_settype (&recmutexattr, PTHREAD_MUTEX_RECURSIVE);
28 }
29 
30 
31 LumieraRecmutex
32 lumiera_recmutex_init (LumieraRecmutex self,
33  const char* purpose,
34  struct nobug_flag* flag,
35  const struct nobug_context ctx)
36 {
37  if (self)
38  {
39  pthread_once (&recmutexattr_once, recmutexattr_init);
40 
41  NOBUG_RESOURCE_HANDLE_INIT (self->rh);
42  NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "recmutex", purpose, self, self->rh, ctx)
43  {
44  pthread_mutex_init (&self->recmutex, &recmutexattr);
45  }
46  }
47 
48  return self;
49 }
50 
51 
52 LumieraRecmutex
53 lumiera_recmutex_destroy (LumieraRecmutex self,
54  struct nobug_flag* flag,
55  const struct nobug_context ctx)
56 {
57  if (self)
58  {
59  NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx)
60  {
61  if (pthread_mutex_destroy (&self->recmutex))
62  LUMIERA_DIE (LOCK_DESTROY);
63  }
64  }
65  return self;
66 }
67 
68 /*
69 // Local Variables:
70 // mode: C
71 // c-file-style: "gnu"
72 // indent-tabs-mode: nil
73 // End:
74 */
LumieraRecmutex lumiera_recmutex_destroy(LumieraRecmutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a recursive mutex variable.
Definition: recmutex.c:53
Mutual exclusion locking, header.
LumieraRecmutex lumiera_recmutex_init(LumieraRecmutex self, const char *purpose, struct nobug_flag *flag, const struct nobug_context ctx)
Initialise a recursive mutex variable Initialises a &#39;recursive&#39; mutex which might be locked by the sa...
Definition: recmutex.c:32
#define LUMIERA_DIE(err)
Abort unconditionally with a &#39;Fatal Error!&#39; message.
Definition: error.h:54