Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rdma-mwe
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
Titouan Soulard
rdma-mwe
Commits
cda3078f
Commit
cda3078f
authored
Feb 12, 2024
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: automatically resize circular buffer
parent
9eb5b337
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
common/circular_buffer.c
common/circular_buffer.c
+10
-2
libtrx/trx_rdma.c
libtrx/trx_rdma.c
+1
-1
No files found.
common/circular_buffer.c
View file @
cda3078f
...
...
@@ -3,13 +3,15 @@
struct
CommonCBBuffer
*
common_circular_buffer_create
(
uint32_t
len
,
bool
is_infinite
)
{
struct
CommonCBBuffer
*
buffer
=
(
struct
CommonCBBuffer
*
)
malloc
(
sizeof
(
struct
CommonCBBuffer
));
if
(
!
buffer
)
return
NULL
;
buffer
->
base_addr
=
malloc
(
len
);
buffer
->
read_counter
=
0
;
buffer
->
write_counter
=
0
;
buffer
->
total_len
=
len
;
buffer
->
readable_len
=
is_infinite
?
-
1
:
0
;
return
buffer
;
return
buffer
->
base_addr
?
buffer
:
NULL
;
}
void
common_circular_buffer_write
(
struct
CommonCBBuffer
*
buffer
,
void
*
bytes
,
uint32_t
byte_count
)
{
...
...
@@ -37,8 +39,14 @@ void common_circular_buffer_write(struct CommonCBBuffer *buffer, void *bytes, ui
buffer
->
readable_len
+=
byte_count
;
if
(
buffer
->
readable_len
>
buffer
->
total_len
)
{
printf
(
"circular_buffer: overflow, increase buffer size
\n
"
);
buffer
->
total_len
*=
2
;
printf
(
"circular_buffer: overflow, increasing buffer size to %u
\n
"
,
buffer
->
total_len
);
buffer
->
base_addr
=
realloc
(
buffer
->
base_addr
,
buffer
->
total_len
);
// Reset the buffer completely to avoid garbage
buffer
->
readable_len
=
0
;
buffer
->
read_counter
=
0
;
buffer
->
write_counter
=
0
;
}
}
}
...
...
libtrx/trx_rdma.c
View file @
cda3078f
...
...
@@ -123,9 +123,9 @@ int trx_rdma_start(TRXState *s, const TRXDriverParams2 *p) {
// Samples will be received (and sent) using a separate thread which manipulates a finite circular
// buffer. The size of the buffer depends on the latency of the network.
// XXX: this function should definitely return an error on failure
sdr_context
->
recv_buffer
=
common_circular_buffer_create
(
TRX_RDMA_BUFFER_SAMPLES
*
sizeof
(
TRXComplex
),
false
);
sdr_context
->
send_buffer
=
common_circular_buffer_create
(
TRX_RDMA_BUFFER_SAMPLES
*
sizeof
(
TRXComplex
),
false
);
if
(
!
sdr_context
->
recv_buffer
||
!
sdr_context
->
send_buffer
)
return
-
1
;
pthread_mutex_init
(
&
sdr_context
->
recv_buffer_mutex
,
NULL
);
pthread_mutex_init
(
&
sdr_context
->
send_buffer_mutex
,
NULL
);
...
...
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