ソースを参照

add squeue

master
huangyulong 4年前
コミット
c1869401a0
9個のファイルの変更429行の追加0行の削除
  1. 8
    0
      queue/makefile
  2. 294
    0
      queue/se/se.vpj
  3. 6
    0
      queue/se/se.vpw
  4. 6
    0
      queue/se/se.vpwhist
  5. バイナリ
      queue/se/se.vtg
  6. バイナリ
      queue/sqqueue
  7. 96
    0
      queue/sqqueue.c
  8. 19
    0
      queue/sqqueue.h
  9. バイナリ
      queue/sqqueue.o

+ 8
- 0
queue/makefile ファイルの表示

@@ -0,0 +1,8 @@
1
+CFLAGS = -Wall
2
+
3
+sqqueue: sqqueue.o
4
+
5
+.PHONY clean:
6
+clean:
7
+	rm sqqueue sqqueue.o
8
+

+ 294
- 0
queue/se/se.vpj ファイルの表示

@@ -0,0 +1,294 @@
1
+<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
2
+<Project
3
+    Version="10.0"
4
+    VendorName="SlickEdit"
5
+    TemplateName="GNU C/C++"
6
+    WorkingDir="."
7
+    BuildSystem="vsbuild">
8
+    <Config
9
+        Name="Debug"
10
+        Type="gnuc"
11
+        DebugCallbackName="gdb"
12
+        Version="1"
13
+        OutputFile="%bdse.exe"
14
+        CompilerConfigName="Latest Version">
15
+        <Menu>
16
+            <Target
17
+                Name="Compile"
18
+                MenuCaption="&amp;Compile"
19
+                Dialog="_gnuc_options_form Compile"
20
+                CaptureOutputWith="ProcessBuffer"
21
+                Deletable="0"
22
+                OutputExts="*.o"
23
+                SaveOption="SaveCurrent"
24
+                RunFromDir="%rw">
25
+                <Exec CmdLine='gcc -c %xup  %defd -g -o "%bd%n%oe" %i "%f"'/>
26
+            </Target>
27
+            <Target
28
+                Name="Link"
29
+                MenuCaption="&amp;Link"
30
+                ShowOnMenu="Never"
31
+                Dialog="_gnuc_options_form Link"
32
+                CaptureOutputWith="ProcessBuffer"
33
+                Deletable="0"
34
+                SaveOption="SaveCurrent"
35
+                RunFromDir="%rw">
36
+                <Exec CmdLine='gcc %xup -g -o "%o" %f %libs'/>
37
+            </Target>
38
+            <Target
39
+                Name="Build"
40
+                MenuCaption="&amp;Build"
41
+                Dialog="_gnuc_options_form Compile"
42
+                CaptureOutputWith="ProcessBuffer"
43
+                Deletable="0"
44
+                SaveOption="SaveWorkspaceFiles"
45
+                RunFromDir="%rw">
46
+                <Exec CmdLine='"%(VSLICKBIN1)vsbuild" "%w" "%r" -t build'/>
47
+            </Target>
48
+            <Target
49
+                Name="Rebuild"
50
+                MenuCaption="&amp;Rebuild"
51
+                Dialog="_gnuc_options_form Compile"
52
+                CaptureOutputWith="ProcessBuffer"
53
+                Deletable="0"
54
+                SaveOption="SaveWorkspaceFiles"
55
+                RunFromDir="%rw">
56
+                <Exec CmdLine='"%(VSLICKBIN1)vsbuild" "%w" "%r" -t rebuild'/>
57
+            </Target>
58
+            <Target
59
+                Name="Debug"
60
+                MenuCaption="&amp;Debug"
61
+                Dialog="_gnuc_options_form Run/Debug"
62
+                BuildFirst="1"
63
+                CaptureOutputWith="ProcessBuffer"
64
+                Deletable="0"
65
+                SaveOption="SaveNone"
66
+                RunFromDir="%rw">
67
+                <Exec CmdLine='vsdebugio -prog "%o"'/>
68
+            </Target>
69
+            <Target
70
+                Name="Execute"
71
+                MenuCaption="E&amp;xecute"
72
+                Dialog="_gnuc_options_form Run/Debug"
73
+                BuildFirst="1"
74
+                CaptureOutputWith="ProcessBuffer"
75
+                Deletable="0"
76
+                SaveOption="SaveWorkspaceFiles"
77
+                RunFromDir="%rw">
78
+                <Exec CmdLine='"%o"'/>
79
+            </Target>
80
+            <Target
81
+                Name="dash"
82
+                MenuCaption="-"
83
+                Deletable="0">
84
+                <Exec/>
85
+            </Target>
86
+            <Target
87
+                Name="GNU C Options"
88
+                MenuCaption="GNU C &amp;Options..."
89
+                ShowOnMenu="HideIfNoCmdLine"
90
+                Deletable="0"
91
+                SaveOption="SaveNone">
92
+                <Exec
93
+                    CmdLine="gnucoptions"
94
+                    Type="Slick-C"/>
95
+            </Target>
96
+        </Menu>
97
+        <Rules Name="Compile">
98
+            <Rule
99
+                InputExts="*.ada"
100
+                OutputExts="*.o"
101
+                LinkObject="1">
102
+                <Exec CmdLine='gnat -g -c -o "%bd%n.o" "%f"'/>
103
+            </Rule>
104
+            <Rule
105
+                InputExts="*.adb"
106
+                OutputExts="*.o"
107
+                LinkObject="1">
108
+                <Exec CmdLine='gnat -g -c -o "%bd%n.o" "%f"'/>
109
+            </Rule>
110
+            <Rule
111
+                InputExts="*.f"
112
+                OutputExts="*.o"
113
+                LinkObject="1">
114
+                <Exec CmdLine='gfortran -c -g -o "%bd%n.o" "%f"'/>
115
+            </Rule>
116
+            <Rule
117
+                InputExts="*.f90"
118
+                OutputExts="*.o"
119
+                LinkObject="1">
120
+                <Exec CmdLine='gfortran -c -g -o "%bd%n.o" "%f"'/>
121
+            </Rule>
122
+            <Rule
123
+                InputExts="*.d"
124
+                OutputExts="*.o"
125
+                LinkObject="1">
126
+                <Exec CmdLine='gdc -c -g -o "%bd%n.o" "%f"'/>
127
+            </Rule>
128
+        </Rules>
129
+        <List Name="GNUC Options">
130
+            <Item
131
+                Name="LinkerOutputType"
132
+                Value="Executable"/>
133
+        </List>
134
+    </Config>
135
+    <Config
136
+        Name="Release"
137
+        Type="gnuc"
138
+        DebugCallbackName="gdb"
139
+        Version="1"
140
+        OutputFile="%bdse.exe"
141
+        CompilerConfigName="Latest Version">
142
+        <Menu>
143
+            <Target
144
+                Name="Compile"
145
+                MenuCaption="&amp;Compile"
146
+                Dialog="_gnuc_options_form Compile"
147
+                CaptureOutputWith="ProcessBuffer"
148
+                Deletable="0"
149
+                OutputExts="*.o"
150
+                SaveOption="SaveCurrent"
151
+                RunFromDir="%rw">
152
+                <Exec CmdLine='gcc -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
153
+            </Target>
154
+            <Target
155
+                Name="Link"
156
+                MenuCaption="&amp;Link"
157
+                ShowOnMenu="Never"
158
+                Dialog="_gnuc_options_form Link"
159
+                CaptureOutputWith="ProcessBuffer"
160
+                Deletable="0"
161
+                SaveOption="SaveCurrent"
162
+                RunFromDir="%rw">
163
+                <Exec CmdLine='gcc %xup -o "%o" %f %libs'/>
164
+            </Target>
165
+            <Target
166
+                Name="Build"
167
+                MenuCaption="&amp;Build"
168
+                Dialog="_gnuc_options_form Compile"
169
+                CaptureOutputWith="ProcessBuffer"
170
+                Deletable="0"
171
+                SaveOption="SaveWorkspaceFiles"
172
+                RunFromDir="%rw">
173
+                <Exec CmdLine='"%(VSLICKBIN1)vsbuild" "%w" "%r" -t build'/>
174
+            </Target>
175
+            <Target
176
+                Name="Rebuild"
177
+                MenuCaption="&amp;Rebuild"
178
+                Dialog="_gnuc_options_form Compile"
179
+                CaptureOutputWith="ProcessBuffer"
180
+                Deletable="0"
181
+                SaveOption="SaveWorkspaceFiles"
182
+                RunFromDir="%rw">
183
+                <Exec CmdLine='"%(VSLICKBIN1)vsbuild" "%w" "%r" -t rebuild'/>
184
+            </Target>
185
+            <Target
186
+                Name="Debug"
187
+                MenuCaption="&amp;Debug"
188
+                Dialog="_gnuc_options_form Run/Debug"
189
+                BuildFirst="1"
190
+                CaptureOutputWith="ProcessBuffer"
191
+                Deletable="0"
192
+                SaveOption="SaveNone"
193
+                RunFromDir="%rw">
194
+                <Exec CmdLine='vsdebugio -prog "%o"'/>
195
+            </Target>
196
+            <Target
197
+                Name="Execute"
198
+                MenuCaption="E&amp;xecute"
199
+                Dialog="_gnuc_options_form Run/Debug"
200
+                BuildFirst="1"
201
+                CaptureOutputWith="ProcessBuffer"
202
+                Deletable="0"
203
+                SaveOption="SaveWorkspaceFiles"
204
+                RunFromDir="%rw">
205
+                <Exec CmdLine='"%o"'/>
206
+            </Target>
207
+            <Target
208
+                Name="dash"
209
+                MenuCaption="-"
210
+                Deletable="0">
211
+                <Exec/>
212
+            </Target>
213
+            <Target
214
+                Name="GNU C Options"
215
+                MenuCaption="GNU C &amp;Options..."
216
+                ShowOnMenu="HideIfNoCmdLine"
217
+                Deletable="0"
218
+                SaveOption="SaveNone">
219
+                <Exec
220
+                    CmdLine="gnucoptions"
221
+                    Type="Slick-C"/>
222
+            </Target>
223
+        </Menu>
224
+        <Rules Name="Compile">
225
+            <Rule
226
+                InputExts="*.ada"
227
+                OutputExts="*.o"
228
+                LinkObject="1">
229
+                <Exec CmdLine='gnat -O -c -o "%bd%n.o" "%f"'/>
230
+            </Rule>
231
+            <Rule
232
+                InputExts="*.adb"
233
+                OutputExts="*.o"
234
+                LinkObject="1">
235
+                <Exec CmdLine='gnat -O -c -o "%bd%n.o" "%f"'/>
236
+            </Rule>
237
+            <Rule
238
+                InputExts="*.f"
239
+                OutputExts="*.o"
240
+                LinkObject="1">
241
+                <Exec CmdLine='gfortran -O -g -o "%bd%n.o" "%f"'/>
242
+            </Rule>
243
+            <Rule
244
+                InputExts="*.f90"
245
+                OutputExts="*.o"
246
+                LinkObject="1">
247
+                <Exec CmdLine='gfortran -O -g -o "%bd%n.o" "%f"'/>
248
+            </Rule>
249
+            <Rule
250
+                InputExts="*.d"
251
+                OutputExts="*.o"
252
+                LinkObject="1">
253
+                <Exec CmdLine='gdc -c -g -o "%bd%n.o" "%f"'/>
254
+            </Rule>
255
+        </Rules>
256
+        <List Name="GNUC Options">
257
+            <Item
258
+                Name="LinkerOutputType"
259
+                Value="Executable"/>
260
+        </List>
261
+    </Config>
262
+    <Files>
263
+        <Folder
264
+            Name="Source Files"
265
+            Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.scala;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d;*.m;*.mm;*.go;*.groovy;*.gsh"
266
+            GUID="{4E9298DF-FA5E-4598-A436-67CFBE9EF32D}">
267
+            <F N="../sqqueue.c"/>
268
+        </Folder>
269
+        <Folder
270
+            Name="Header Files"
271
+            Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.h++;*.inc;*.sh;*.cpy;*.if"
272
+            GUID="{A52E3A55-5AFC-41D7-A45F-E0D970188D7C}">
273
+            <F N="../sqqueue.h"/>
274
+        </Folder>
275
+        <Folder
276
+            Name="Resource Files"
277
+            Filters="*.ico;*.cur;*.dlg"
278
+            GUID="{2FC284F5-1081-43C3-AF53-299A45F48EA7}"/>
279
+        <Folder
280
+            Name="Bitmaps"
281
+            Filters="*.bmp"
282
+            GUID="{474C3BCB-9894-4A91-8ED6-5D82E277B878}"/>
283
+        <Folder
284
+            Name="Other Files"
285
+            Filters=""
286
+            GUID="{ADBE9752-FE35-4D9B-AC93-C57C214B0FF6}">
287
+            <F
288
+                N="../makefile"
289
+                Type="Makefile"/>
290
+        </Folder>
291
+    </Files>
292
+    <List Name="RTE">
293
+    </List>
294
+</Project>

+ 6
- 0
queue/se/se.vpw ファイルの表示

@@ -0,0 +1,6 @@
1
+<!DOCTYPE Workspace SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpw.dtd">
2
+<Workspace Version="10.0" VendorName="SlickEdit">
3
+    <Projects>
4
+        <Project File="se.vpj"/>
5
+    </Projects>
6
+</Workspace>

+ 6
- 0
queue/se/se.vpwhist ファイルの表示

@@ -0,0 +1,6 @@
1
+[Global]
2
+CurrentProject=se.vpj
3
+[ProjectDates]
4
+se.vpj=20210624114241401
5
+[ActiveConfig]
6
+se.vpj=Debug

バイナリ
queue/se/se.vtg ファイルの表示


バイナリ
queue/sqqueue ファイルの表示


+ 96
- 0
queue/sqqueue.c ファイルの表示

@@ -0,0 +1,96 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include "sqqueue.h"
4
+
5
+queue_t pkt_creat_sqqueue(int len)
6
+{
7
+    queue_t q;
8
+    if ((q = (queue_t)malloc(sizeof(struct queue))) == NULL)
9
+    {
10
+        printf("malloc failed!\n");
11
+        return NULL;
12
+    }
13
+
14
+    if ((q->msg = (message_t)malloc(sizeof(struct message) * len)) == NULL)
15
+    {
16
+        printf("malloc failed!\n");
17
+        return NULL;
18
+    }
19
+
20
+    q->front = q->rear = len - 1;
21
+    q->len = len;
22
+    return q;
23
+}
24
+
25
+int pkt_empty_sqqueue(queue_t q)
26
+{
27
+    return q->front == q->rear;
28
+}
29
+
30
+int pkt_full_sqqueue(queue_t q)
31
+{
32
+    return (q->rear + 1) % q->len == q->front;  /* 空出一个消息位置判断为满,队列最大装len - 1个 */
33
+}
34
+
35
+int pkt_put_message_sqqueue(queue_t q, message_t m)
36
+{
37
+    if (pkt_full_sqqueue(q))
38
+    {
39
+        printf("squeue is full!\n");
40
+        return -1; 
41
+    }
42
+
43
+    q->rear = (q->rear + 1) % q->len; /* first rear++ */
44
+    q->msg[q->rear] = *m;
45
+    return 0;
46
+}
47
+
48
+int pkt_take_message_sqqueue(queue_t q, message_t m)
49
+{
50
+    if (pkt_empty_sqqueue(q))
51
+    {
52
+        printf("squeue is empty!\n");
53
+        return -1;
54
+    }
55
+
56
+    q->front = (q->front + 1) % q->len; /* frist front++ */
57
+    *m = q->msg[q->front];
58
+    return 0;
59
+}
60
+
61
+int pkt_show_sqqueue(queue_t q)
62
+{
63
+    int i;
64
+    for (i = (q->front + 1) % q->len; i != (q->rear + 1) % q->len; i = (i + 1) % q->len)
65
+    {
66
+        printf("queue[%d] = %d\n", i, q->msg[i].data);
67
+    }
68
+
69
+    return 0;
70
+}
71
+
72
+int main(int argc, char **argv)
73
+{
74
+    queue_t q;
75
+
76
+    q = pkt_creat_sqqueue(10);
77
+
78
+    struct message m;
79
+    for (int i = 1; i <= 10; i++)
80
+    {
81
+        m.data = i;
82
+        printf("put %d\n", m.data);
83
+        pkt_put_message_sqqueue(q, &m);
84
+    }
85
+
86
+    while (!pkt_empty_sqqueue(q))
87
+    {
88
+        pkt_take_message_sqqueue(q, &m);
89
+        printf("take = %d\n", m.data);
90
+    }
91
+
92
+    pkt_show_sqqueue(q);
93
+
94
+    return 0;
95
+}
96
+

+ 19
- 0
queue/sqqueue.h ファイルの表示

@@ -0,0 +1,19 @@
1
+#ifndef _SQQUEUE_H_
2
+#define _SQQUEUE_H_
3
+
4
+struct message
5
+{
6
+    int data;
7
+};
8
+typedef struct message * message_t;
9
+
10
+struct queue
11
+{
12
+    message_t  msg;
13
+    int front;
14
+    int rear;
15
+    int len;
16
+};
17
+typedef struct queue * queue_t;
18
+
19
+#endif

バイナリ
queue/sqqueue.o ファイルの表示


読み込み中…
キャンセル
保存