Embedded Multicore Building Blocks V1.0.0
counter.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_BASE_C_COUNTER_H_
28 #define EMBB_BASE_C_COUNTER_H_
29 
30 #include <embb/base/c/atomic.h>
31 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
46 #ifdef DOXYGEN
47 typedef opaque_type embb_counter_t;
48 #else
49 typedef struct embb_counter_t {
50  embb_atomic_unsigned_int value;
52 #endif /* else defined(DOXYGEN) */
53 
63  embb_counter_t* counter
65  );
66 
76 unsigned int embb_counter_get(
77  embb_counter_t* counter
79  );
80 
89 unsigned int embb_counter_increment(
90  embb_counter_t* counter
92  );
93 
102 unsigned int embb_counter_decrement(
103  embb_counter_t* counter
105  );
106 
113 void embb_counter_reset(
114  embb_counter_t* counter
116  );
117 
126  embb_counter_t* counter
128  );
129 
130 #ifdef __cplusplus
131 } /* Close extern "C" { */
132 #endif
133 
138 #endif /* EMBB_BASE_C_COUNTER_H_ */
opaque_type embb_counter_t
Opaque type representing a thread-safe counter.
Definition: counter.h:47
int embb_counter_init(embb_counter_t *counter)
Initializes counter and sets it to zero.
unsigned int embb_counter_decrement(embb_counter_t *counter)
Decrements counter and returns the old value.
void embb_counter_destroy(embb_counter_t *counter)
Destroys an initialized counter.
void embb_counter_reset(embb_counter_t *counter)
Resets an initialized counter to 0.
unsigned int embb_counter_increment(embb_counter_t *counter)
Increments counter and returns the old value.
unsigned int embb_counter_get(embb_counter_t *counter)
Returns the current value of counter.