1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*
* Copyright (C) 2008-2009 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup condvar condvar
* @{ @ingroup threading
*/
#ifndef THREADING_CONDVAR_H_
#define THREADING_CONDVAR_H_
typedef struct condvar_t condvar_t;
typedef enum condvar_type_t condvar_type_t;
#include "mutex.h"
/**
* Type of condvar.
*/
enum condvar_type_t {
/** default condvar */
CONDVAR_TYPE_DEFAULT = 0,
};
/**
* Condvar wrapper to use in conjunction with mutex_t.
*/
struct condvar_t {
/**
* Wait on a condvar until it gets signalized.
*
* @param mutex mutex to release while waiting
*/
void (*wait)(condvar_t *this, mutex_t *mutex);
/**
* Wait on a condvar until it gets signalized, or times out.
*
* @param mutex mutex to release while waiting
* @param timeout timeout im ms
* @return TRUE if timed out, FALSE otherwise
*/
bool (*timed_wait)(condvar_t *this, mutex_t *mutex, u_int timeout);
/**
* Wait on a condvar until it gets signalized, or times out.
*
* The passed timeval should be calculated based on the time_monotonic()
* function.
*
* @param mutex mutex to release while waiting
* @param tv absolute time until timeout
* @return TRUE if timed out, FALSE otherwise
*/
bool (*timed_wait_abs)(condvar_t *this, mutex_t *mutex, timeval_t tv);
/**
* Wake up a single thread in a condvar.
*/
void (*signal)(condvar_t *this);
/**
* Wake up all threads in a condvar.
*/
void (*broadcast)(condvar_t *this);
/**
* Destroy a condvar and free its resources.
*/
void (*destroy)(condvar_t *this);
};
/**
* Create a condvar instance.
*
* @param type type of condvar to create
* @return condvar instance
*/
condvar_t *condvar_create(condvar_type_t type);
#endif /** THREADING_CONDVAR_H_ @} */
|