]>
Commit | Line | Data |
---|---|---|
60dc4464 TB |
1 | /* |
2 | * Copyright (C) 2012 Tobias Brunner | |
19ef2aec TB |
3 | * |
4 | * Copyright (C) secunet Security Networks AG | |
60dc4464 TB |
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 | /** | |
18 | * @defgroup rwlock_condvar rwlock_condvar | |
19 | * @{ @ingroup threading | |
20 | */ | |
21 | ||
22 | #ifndef RWLOCK_CONDVAR_H_ | |
23 | #define RWLOCK_CONDVAR_H_ | |
24 | ||
25 | typedef struct rwlock_condvar_t rwlock_condvar_t; | |
26 | ||
27 | #include "rwlock.h" | |
28 | ||
29 | /** | |
30 | * A special condvar implementation that can be used in conjunction | |
31 | * with rwlock_t (the write lock to be precise). | |
32 | * | |
33 | * @note The implementation does not verify that the current thread actually | |
34 | * holds the write lock and not the read lock, so watch out. | |
35 | */ | |
36 | struct rwlock_condvar_t { | |
37 | ||
38 | /** | |
39 | * Wait on a condvar until it gets signalized. | |
40 | * | |
41 | * @param lock lock to release while waiting (write lock) | |
42 | */ | |
43 | void (*wait)(rwlock_condvar_t *this, rwlock_t *lock); | |
44 | ||
45 | /** | |
46 | * Wait on a condvar until it gets signalized, or times out. | |
47 | * | |
48 | * @param lock lock to release while waiting (write lock) | |
49 | * @param timeout timeout im ms | |
50 | * @return TRUE if timed out, FALSE otherwise | |
51 | */ | |
52 | bool (*timed_wait)(rwlock_condvar_t *this, rwlock_t *lock, u_int timeout); | |
53 | ||
54 | /** | |
55 | * Wait on a condvar until it gets signalized, or times out. | |
56 | * | |
57 | * The passed timeval should be calculated based on the time_monotonic() | |
58 | * function. | |
59 | * | |
60 | * @param lock lock to release while waiting (write lock) | |
61 | * @param tv absolute time until timeout | |
62 | * @return TRUE if timed out, FALSE otherwise | |
63 | */ | |
64 | bool (*timed_wait_abs)(rwlock_condvar_t *this, rwlock_t *lock, | |
65 | timeval_t tv); | |
66 | ||
67 | /** | |
68 | * Wake up a single thread in a condvar. | |
69 | */ | |
70 | void (*signal)(rwlock_condvar_t *this); | |
71 | ||
72 | /** | |
73 | * Wake up all threads in a condvar. | |
74 | */ | |
75 | void (*broadcast)(rwlock_condvar_t *this); | |
76 | ||
77 | /** | |
78 | * Destroy a condvar and free its resources. | |
79 | */ | |
80 | void (*destroy)(rwlock_condvar_t *this); | |
81 | }; | |
82 | ||
83 | /** | |
84 | * Create a condvar instance. | |
85 | * | |
86 | * @return condvar instance | |
87 | */ | |
88 | rwlock_condvar_t *rwlock_condvar_create(); | |
89 | ||
90 | #endif /** RWLOCK_CONDVAR_H_ @} */ | |
91 |