Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
core
tarantool
Commits
5f1a391e
Commit
5f1a391e
authored
10 years ago
by
Konstantin Osipov
Browse files
Options
Downloads
Patches
Plain Diff
A few style fixes in an unused fifo implementation.
parent
17fa5be4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/salad/fifo.h
+19
-13
19 additions, 13 deletions
src/lib/salad/fifo.h
with
19 additions
and
13 deletions
src/lib/salad/
qbuf
.h
→
src/lib/salad/
fifo
.h
+
19
−
13
View file @
5f1a391e
#ifndef TARANTOOL_
QBUF
_H_INCLUDED
#define TARANTOOL_
QBUF
_H_INCLUDED
#ifndef TARANTOOL_
FIFO
_H_INCLUDED
#define TARANTOOL_
FIFO
_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
...
...
@@ -28,12 +28,13 @@
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include
<stdlib.h>
#define QBUF_WATERMARK (512 * sizeof(void*))
#define FIFO_WATERMARK (512 * sizeof(void*))
/** A simple FIFO made using a ring buffer */
struct
qbuf
{
struct
fifo
{
char
*
buf
;
size_t
bottom
;
/* advanced by batch free */
size_t
top
;
...
...
@@ -41,7 +42,8 @@ struct qbuf {
};
static
inline
int
qbuf_init
(
struct
qbuf
*
q
,
size_t
size
)
{
fifo_create
(
struct
fifo
*
q
,
size_t
size
)
{
q
->
size
=
size
;
q
->
bottom
=
0
;
q
->
top
=
0
;
...
...
@@ -50,7 +52,8 @@ qbuf_init(struct qbuf *q, size_t size) {
}
static
inline
void
qbuf_free
(
struct
qbuf
*
q
)
{
fifo_destroy
(
struct
fifo
*
q
)
{
if
(
q
->
buf
)
{
free
(
q
->
buf
);
q
->
buf
=
NULL
;
...
...
@@ -58,7 +61,8 @@ qbuf_free(struct qbuf *q) {
}
static
inline
int
qbuf_n
(
struct
qbuf
*
q
)
{
fifo_size
(
struct
fifo
*
q
)
{
return
(
q
->
top
-
q
->
bottom
)
/
sizeof
(
void
*
);
}
...
...
@@ -67,12 +71,12 @@ qbuf_n(struct qbuf *q) {
#endif
static
inline
int
qbuf
_push
(
struct
qbuf
*
q
,
void
*
ptr
)
fifo
_push
(
struct
fifo
*
q
,
void
*
ptr
)
{
/* reduce memory allocation and memmove
* effect by reusing free pointers buffer space only after the
* watermark frees reached. */
if
(
unlikely
(
q
->
bottom
>=
QBUF
_WATERMARK
))
{
if
(
unlikely
(
q
->
bottom
>=
FIFO
_WATERMARK
))
{
memmove
(
q
->
buf
,
q
->
buf
+
q
->
bottom
,
q
->
bottom
);
q
->
top
-=
q
->
bottom
;
q
->
bottom
=
0
;
...
...
@@ -90,8 +94,8 @@ qbuf_push(struct qbuf *q, void *ptr)
return
0
;
}
static
inline
void
*
qbuf
_pop
(
struct
qbuf
*
q
)
{
static
inline
void
*
fifo
_pop
(
struct
fifo
*
q
)
{
if
(
unlikely
(
q
->
bottom
==
q
->
top
))
return
NULL
;
void
*
ret
=
*
(
void
**
)(
q
->
buf
+
q
->
bottom
);
...
...
@@ -99,4 +103,6 @@ qbuf_pop(struct qbuf *q) {
return
ret
;
}
#endif
#undef FIFO_WATERMARK
#endif
/* TARANTOOL_FIFO_H_INCLUDED */
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