Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
21static pthread_once_t recmutexattr_once = PTHREAD_ONCE_INIT;
22static pthread_mutexattr_t recmutexattr;
23
24static void recmutexattr_init()
25{
26 pthread_mutexattr_init (&recmutexattr);
27 pthread_mutexattr_settype (&recmutexattr, PTHREAD_MUTEX_RECURSIVE);
28}
29
30
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
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*/
#define LUMIERA_DIE(err)
Abort unconditionally with a 'Fatal Error!' message.
Definition error.h:54
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 'recursive' mutex which might be locked by the sa...
Definition recmutex.c:32
static pthread_mutexattr_t recmutexattr
Definition recmutex.c:22
LumieraRecmutex lumiera_recmutex_destroy(LumieraRecmutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a recursive mutex variable.
Definition recmutex.c:53
static void recmutexattr_init()
Definition recmutex.c:24
static pthread_once_t recmutexattr_once
Definition recmutex.c:21
Mutual exclusion locking, header.
lumiera_recmutex * LumieraRecmutex
Definition recmutex.h:85