Annotation of embedaddon/strongswan/src/libstrongswan/threading/condvar.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2008-2009 Tobias Brunner
3: * Copyright (C) 2008 Martin Willi
4: * HSR 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: /**
18: * @defgroup condvar condvar
19: * @{ @ingroup threading
20: */
21:
22: #ifndef THREADING_CONDVAR_H_
23: #define THREADING_CONDVAR_H_
24:
25: typedef struct condvar_t condvar_t;
26: typedef enum condvar_type_t condvar_type_t;
27:
28: #include "mutex.h"
29:
30: /**
31: * Type of condvar.
32: */
33: enum condvar_type_t {
34: /** default condvar */
35: CONDVAR_TYPE_DEFAULT = 0,
36: };
37:
38: /**
39: * Condvar wrapper to use in conjunction with mutex_t.
40: */
41: struct condvar_t {
42:
43: /**
44: * Wait on a condvar until it gets signalized.
45: *
46: * @param mutex mutex to release while waiting
47: */
48: void (*wait)(condvar_t *this, mutex_t *mutex);
49:
50: /**
51: * Wait on a condvar until it gets signalized, or times out.
52: *
53: * @param mutex mutex to release while waiting
54: * @param timeout timeout im ms
55: * @return TRUE if timed out, FALSE otherwise
56: */
57: bool (*timed_wait)(condvar_t *this, mutex_t *mutex, u_int timeout);
58:
59: /**
60: * Wait on a condvar until it gets signalized, or times out.
61: *
62: * The passed timeval should be calculated based on the time_monotonic()
63: * function.
64: *
65: * @param mutex mutex to release while waiting
66: * @param tv absolute time until timeout
67: * @return TRUE if timed out, FALSE otherwise
68: */
69: bool (*timed_wait_abs)(condvar_t *this, mutex_t *mutex, timeval_t tv);
70:
71: /**
72: * Wake up a single thread in a condvar.
73: */
74: void (*signal)(condvar_t *this);
75:
76: /**
77: * Wake up all threads in a condvar.
78: */
79: void (*broadcast)(condvar_t *this);
80:
81: /**
82: * Destroy a condvar and free its resources.
83: */
84: void (*destroy)(condvar_t *this);
85: };
86:
87: /**
88: * Create a condvar instance.
89: *
90: * @param type type of condvar to create
91: * @return condvar instance
92: */
93: condvar_t *condvar_create(condvar_type_t type);
94:
95: #endif /** THREADING_CONDVAR_H_ @} */
96:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>