Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
trx-ecpri
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
trx-ecpri
Commits
41a95732
Commit
41a95732
authored
Jan 15, 2025
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: go back to fixed blocked size in rbufs
TODO: modify trx_ecpri_read and trx_ecpri_write (then all the rest)
parent
5b846e30
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
60 deletions
+28
-60
ring_buffer.c
ring_buffer.c
+28
-60
No files found.
ring_buffer.c
View file @
41a95732
...
...
@@ -37,95 +37,63 @@
typedef
struct
{
volatile
char
*
buffer
;
volatile
size_t
*
block_buffer
;
char
name
[
64
];
size_t
len
;
size_t
block_buf_len
;
size_t
min_block_size
;
size_t
buf_len
;
size_t
block_len
;
volatile
int
write_index
;
volatile
int
read_index
;
volatile
int
block_write_index
;
volatile
int
block_read_index
;
}
ring_buffer_t
;
static
void
init_rbuf
(
ring_buffer_t
*
rbuf
,
char
*
name
,
size_t
len
,
size_t
min_block_size
)
{
static
void
init_rbuf
(
ring_buffer_t
*
rbuf
,
char
*
name
,
size_t
buf_len
,
size_t
block_len
)
{
//log_debug("TRX_ECPRI", "Allocating %s with %d bytes\n", _name, len);
rbuf
->
len
=
len
;
rbuf
->
block_buf_len
=
len
/
min_block_size
;
rbuf
->
buf
fer
=
(
char
*
)
malloc
(
len
)
;
rbuf
->
block_
buffer
=
(
size_t
*
)
malloc
(
rbuf
->
block_buf_len
*
sizeof
(
size_t
))
;
rbuf
->
min_block_size
=
min_block_size
;
if
(
!
(
buf_len
%
block_len
))
log_exit
(
"buf_len needs to be a multiple of block_len"
)
;
rbuf
->
buf
_len
=
buf_len
;
rbuf
->
block_
len
=
block_len
;
rbuf
->
buffer
=
(
char
*
)
malloc
(
buf_len
)
;
rbuf
->
write_index
=
0
;
rbuf
->
read_index
=
0
;
rbuf
->
block_write_index
=
0
;
rbuf
->
block_read_index
=
0
;
strcpy
(
rbuf
->
name
,
name
);
}
static
int
rbuf_read_amount
(
ring_buffer_t
*
rbuf
)
{
return
(
rbuf
->
write_index
+
rbuf
->
len
-
rbuf
->
read_index
)
%
rbuf
->
len
;
return
(
rbuf
->
write_index
+
rbuf
->
buf_len
-
rbuf
->
read_index
)
%
rbuf
->
buf_
len
;
}
static
int
rbuf_write_amount
(
ring_buffer_t
*
rbuf
)
{
// Don't write everything to avoid write index catching up to read index
// That we way we don't have to use locks
return
((
rbuf
->
read_index
+
rbuf
->
len
-
rbuf
->
write_index
-
1
)
%
rbuf
->
len
);
return
((
rbuf
->
read_index
+
rbuf
->
buf_len
-
rbuf
->
write_index
-
1
)
%
rbuf
->
buf_
len
);
}
static
volatile
char
*
rbuf_write
(
ring_buffer_t
*
rbuf
)
{
return
rbuf
->
buffer
+
rbuf
->
write_index
;
}
static
void
rbuf_increment_write
(
ring_buffer_t
*
rbuf
,
size_t
size
,
int
block
)
{
rbuf
->
write_index
=
(
rbuf
->
write_index
+
size
)
%
rbuf
->
len
;
if
(
!
block
)
return
;
rbuf
->
block_buffer
[
rbuf
->
block_write_index
]
=
size
;
rbuf
->
block_write_index
=
(
rbuf
->
block_write_index
+
1
)
%
rbuf
->
block_buf_len
;
static
void
rbuf_increment_write
(
ring_buffer_t
*
rbuf
,
size_t
size
)
{
if
(
!
(
size
%
rbuf
->
block_len
))
log_exit
(
"size needs to be a multiple of buffer block length"
);
rbuf
->
write_index
=
(
rbuf
->
write_index
+
size
)
%
rbuf
->
buf_len
;
}
static
void
rbuf_increment_read
(
ring_buffer_t
*
rbuf
,
size_t
size
)
{
rbuf
->
read_index
=
(
rbuf
->
read_index
+
size
)
%
rbuf
->
len
;
if
(
!
(
size
%
rbuf
->
block_len
))
log_exit
(
"size needs to be a multiple of buffer block length"
);
rbuf
->
read_index
=
(
rbuf
->
read_index
+
size
)
%
rbuf
->
buf_len
;
}
static
volatile
char
*
rbuf_read
(
ring_buffer_t
*
rbuf
,
size_t
*
size
)
{
volatile
char
*
data
=
rbuf
->
buffer
+
rbuf
->
read_index
;
*
size
=
rbuf
->
block_buffer
[
rbuf
->
block_read_index
];
rbuf
->
read_index
=
(
rbuf
->
read_index
+
*
size
)
%
rbuf
->
len
;
rbuf
->
block_read_index
=
(
rbuf
->
block_read_index
+
1
)
%
rbuf
->
block_buf_len
;
return
data
;
}
static
size_t
rbuf_contiguous_copy_single
(
ring_buffer_t
*
rbuf
,
size_t
block_size
,
size_t
max_blocks
)
{
size_t
n_blocks
;
if
(
!
rbuf
)
return
0
;
n_blocks
=
(
rbuf
->
len
-
rbuf
->
read_index
)
/
block_size
;
if
(
!
n_blocks
)
{
if
(
n_blocks
>
max_blocks
)
return
max_blocks
;
return
n_blocks
;
if
(
!
(
size
%
rbuf
->
block_len
))
log_exit
(
"size needs to be a multiple of buffer block length"
);
return
rbuf
->
buffer
+
rbuf
->
read_index
;
}
/* Returns maximum contiguous size on which rbuf_src can be copied to rbuf_dst */
static
size_t
rbuf_contiguous_copy
(
ring_buffer_t
*
rbuf_src
,
ring_buffer_t
*
rbuf_dst
,
size_t
block_size
,
size_t
max_blocks
)
{
size_t
n_blocks
;
if
(
rbuf_src
)
{
max_size
=
rbuf_src
->
len
-
rbuf_src
->
read_index
;
if
(
size
>
max_size
)
{
size
=
max_size
;
}
else
if
(
size
<
min_size
)
{
index
=
0
;
size
=
static
int
rbuf_contiguous_copy
(
ring_buffer_t
*
rbuf1
,
ring_buffer_t
*
rbuf2
,
int
n
)
{
int
ret
=
n
;
if
(
rbuf1
)
{
n
=
rbuf1
->
buf_len
-
rbuf1
->
read_index
;
ret
=
n
<
ret
?
n
:
ret
;
}
size
=
max_size
<
size
?
max_size
:
size
;
}
if
(
rbuf_dst
)
n
=
rbuf_dst
->
len
-
rbuf_dst
->
write_index
;
if
(
rbuf2
)
n
=
rbuf2
->
buf_len
-
rbuf2
->
write_index
;
return
n
<
ret
?
n
:
ret
;
}
#ifdef TEST
static
ring_buffer_t
test_rbuf
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment