-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_controller.c
executable file
·55 lines (48 loc) · 1.08 KB
/
count_controller.c
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
//
// Created by root on 18-8-14.
//
#include "count_controller.h"
static inline int up_cnt(int cnt, int max, bool *is_max)
{
int res = 0;
*is_max = true;
if ( cnt < max )
{
*is_max = false;
res = cnt + 1;
}
return res;
}
//nolock
static bool test_cnt(count_controller_t *controller)
{
bool res = false;
int old = controller->cnt;
while ( !__sync_bool_compare_and_swap(&controller->cnt,
old,
up_cnt(controller->cnt,
controller->max, &res)) )
{
old = controller->cnt;
}
return res;
}
static void clear(count_controller_t *controller)
{
controller->cnt = 0;
}
int count_controller_init(count_controller_t *controller, int interval_cnt)
{
controller->cnt = 0;
controller->max = interval_cnt;
controller->clear = clear;
controller->test_cnt = test_cnt;
return 0;
}
void count_controller_exit(count_controller_t *controller)
{
}
void test_count_controller()
{
//FIXME muto
}