Threading primitives separated.
[strongswan.git] / src / libstrongswan / threading / mutex.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #ifndef THREADING_MUTEX_H_
18 #define THREADING_MUTEX_H_
19
20 #include "lock_profiler.h"
21
22 typedef struct private_mutex_t private_mutex_t;
23 typedef struct private_r_mutex_t private_r_mutex_t;
24
25 /**
26 * private data of mutex
27 */
28 struct private_mutex_t {
29
30 /**
31 * public functions
32 */
33 mutex_t public;
34
35 /**
36 * wrapped pthread mutex
37 */
38 pthread_mutex_t mutex;
39
40 /**
41 * is this a recursiv emutex, implementing private_r_mutex_t?
42 */
43 bool recursive;
44
45 /**
46 * profiling info, if enabled
47 */
48 lock_profile_t profile;
49 };
50
51 /**
52 * private data of mutex, extended by recursive locking information
53 */
54 struct private_r_mutex_t {
55
56 /**
57 * Extends private_mutex_t
58 */
59 private_mutex_t generic;
60
61 /**
62 * thread which currently owns mutex
63 */
64 pthread_t thread;
65
66 /**
67 * times we have locked the lock, stored per thread
68 */
69 pthread_key_t times;
70 };
71
72 #endif /* THREADING_MUTEX_H_ */
73