Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
ced15288
Commit
ced15288
authored
8 years ago
by
bbartels
Browse files
Options
Downloads
Patches
Plain Diff
quad: fix queue implementation so usage meets expectations
parent
5e430fa0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
quad/src/queue/queue.c
+9
-9
9 additions, 9 deletions
quad/src/queue/queue.c
quad/src/queue/queue.h
+2
-2
2 additions, 2 deletions
quad/src/queue/queue.h
with
11 additions
and
11 deletions
quad/src/queue/queue.c
+
9
−
9
View file @
ced15288
#include
"queue.h"
int
queue_init
(
struct
Queue
*
q
,
volatile
unsigned
char
*
buff
,
unsigned
int
max_size
)
{
int
queue_init
(
struct
Queue
*
q
,
volatile
unsigned
char
*
buff
,
unsigned
int
max_size
_plus1
)
{
q
->
buff
=
buff
;
q
->
max_size
=
max_size
+
1
;
q
->
start
=
max_size
;
q
->
max_size
_plus1
=
max_size
_plus
1
;
q
->
start
=
max_size
_plus1
-
1
;
q
->
end
=
0
;
return
0
;
}
...
...
@@ -13,7 +13,7 @@ struct Queue * queue_malloc(unsigned int max_size) {
if
(
buff
==
NULL
)
return
NULL
;
struct
Queue
*
q
=
malloc
(
sizeof
(
struct
Queue
));
if
(
q
==
NULL
)
return
NULL
;
queue_init
(
q
,
buff
,
max_size
);
queue_init
(
q
,
buff
,
max_size
+
1
);
return
q
;
}
...
...
@@ -28,7 +28,7 @@ int queue_add(struct Queue *q, unsigned char c) {
}
q
->
buff
[
q
->
end
]
=
c
;
q
->
end
+=
1
;
q
->
end
%=
q
->
max_size
;
q
->
end
%=
q
->
max_size
_plus1
;
return
0
;
}
...
...
@@ -37,17 +37,17 @@ int queue_remove(struct Queue *q, unsigned char *c) {
return
-
1
;
}
q
->
start
+=
1
;
q
->
start
%=
q
->
max_size
;
q
->
start
%=
q
->
max_size
_plus1
;
*
c
=
q
->
buff
[
q
->
start
];
return
0
;
}
int
queue_size
(
struct
Queue
*
q
)
{
return
(
q
->
max_size
+
q
->
end
-
q
->
start
-
1
)
%
q
->
max_size
;
return
(
q
->
max_size
_plus1
+
q
->
end
-
q
->
start
-
1
)
%
q
->
max_size
_plus1
;
}
int
queue_full
(
struct
Queue
*
q
)
{
return
q
->
start
==
q
->
end
;
;
return
q
->
start
==
q
->
end
;
}
int
queue_empty
(
struct
Queue
*
q
)
{
...
...
@@ -57,7 +57,7 @@ int queue_empty(struct Queue *q) {
void
queue_print
(
struct
Queue
*
q
)
{
int
i
;
printf
(
"buffer: (size: %d, full: %d, empty: %d)
\n
"
,
queue_size
(
q
),
queue_full
(
q
),
queue_empty
(
q
));
for
(
i
=
0
;
i
<
q
->
max_size
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
q
->
max_size
_plus1
;
i
+=
1
)
{
char
c
=
(
char
)
q
->
buff
[
i
];
if
(
c
==
0
)
c
=
'-'
;
printf
(
"%c"
,
c
);;
...
...
This diff is collapsed.
Click to expand it.
quad/src/queue/queue.h
+
2
−
2
View file @
ced15288
...
...
@@ -6,13 +6,13 @@
struct
Queue
{
volatile
unsigned
char
*
buff
;
unsigned
int
max_size
;
unsigned
int
max_size
_plus1
;
unsigned
int
start
;
unsigned
int
end
;
};
int
queue_init
(
struct
Queue
*
q
,
volatile
unsigned
char
*
buff
,
unsigned
int
max_size
);
int
queue_init
(
struct
Queue
*
q
,
volatile
unsigned
char
*
buff
,
unsigned
int
max_size
_plus1
);
struct
Queue
*
queue_malloc
(
unsigned
int
max_size
);
void
queue_free
(
struct
Queue
*
q
);
int
queue_add
(
struct
Queue
*
q
,
unsigned
char
c
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment