-
Notifications
You must be signed in to change notification settings - Fork 1
/
queuex_123.c
180 lines (143 loc) · 2.84 KB
/
queuex_123.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
* Copyright (C) 2017 - 2020, Lanka Hsu, <lankahsu@gmail.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include <signal.h>
#include <getopt.h>
#include "utilx9.h"
#define TAG "queuex_123"
#define MAX_OF_QTEST 30
QueueX_t *test_q;
typedef struct TestX_Struct
{
int idx;
} TestX_t;
int idx = 0;
static int test_q_exec_cb(void *arg)
{
TestX_t *data_pop = (TestX_t *)arg;
if ( (data_pop) )
{
DBG_IF_LN("(data_pop->idx: %d)", data_pop->idx);
idx--;
}
return 0;
}
static int test_q_free_cb(void *arg)
{
TestX_t *data_pop = (TestX_t *)arg;
if (data_pop)
{
}
return 0;
}
void test_push(int idx)
{
TestX_t data_new = { .idx = 0 };
data_new.idx = idx;
DBG_IF_LN("(idx: %d)", idx);
queuex_push(test_q, (void*)&data_new);
}
// ** app **
static int is_quit = 0;
static int app_quit(void)
{
return is_quit;
}
static void app_set_quit(int mode)
{
is_quit = mode;
}
static void app_stop(void)
{
if (app_quit()==0)
{
app_set_quit(1);
}
}
static void app_loop(void)
{
test_q = queuex_thread_init("test", MAX_OF_QTEST, sizeof(TestX_t), test_q_exec_cb, test_q_free_cb);
test_q->dbg_more = DBG_LVL_INFO;
queuex_isready(test_q, 5);
while ( ( idx < 5 ) && (is_quit==0) )
{
#if (0)
idx++;
DBG_IF_LN("(idx: %d)", idx);
sleep(1);
#else
test_push(idx++);
#endif
}
while (idx>0)
{
sleep(1);
}
{
queuex_thread_stop(test_q);
queuex_thread_close(test_q);
}
exit(0);
}
static int app_init(void)
{
int ret = 0;
return ret;
}
static void app_exit(void)
{
app_stop();
}
static void app_signal_handler(int signum)
{
DBG_ER_LN("(signum: %d)", signum);
switch (signum)
{
case SIGINT:
case SIGTERM:
case SIGHUP:
app_stop();
break;
case SIGPIPE:
break;
case SIGUSR1:
break;
case SIGUSR2:
dbg_lvl_round();
DBG_ER_LN("dbg_lvl_get(): %d", dbg_lvl_get());
DBG_ER_LN("(Version: %s)", version_show());
break;
}
}
static void app_signal_register(void)
{
signal(SIGINT, app_signal_handler);
signal(SIGTERM, app_signal_handler);
signal(SIGHUP, app_signal_handler);
signal(SIGUSR1, app_signal_handler);
signal(SIGUSR2, app_signal_handler);
signal(SIGPIPE, SIG_IGN);
}
int main(int argc, char* argv[])
{
app_signal_register();
atexit(app_exit);
if ( app_init() == -1 )
{
return -1;
}
app_loop();
DBG_WN_LN(DBG_TXT_BYE_BYE);
return 0;
}