Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7f904252
authored
Mar 26, 2015
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mtapi_network_c: use single buffer for sending instead of allocating new ones
parent
73903a72
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
mtapi_network_c/src/embb_mtapi_network.c
+24
-13
No files found.
mtapi_network_c/src/embb_mtapi_network.c
View file @
7f904252
...
...
@@ -81,6 +81,9 @@ struct embb_mtapi_network_plugin_struct {
int
socket_count
;
embb_atomic_int
run
;
mtapi_size_t
buffer_size
;
embb_mutex_t
send_mutex
;
embb_mtapi_network_buffer_t
send_buffer
;
};
typedef
struct
embb_mtapi_network_plugin_struct
embb_mtapi_network_plugin_t
;
...
...
@@ -132,40 +135,41 @@ static void embb_mtapi_network_task_complete(
embb_mtapi_network_plugin_t
*
plugin
=
&
embb_mtapi_network_plugin
;
embb_mtapi_network_task_t
*
network_task
=
(
embb_mtapi_network_task_t
*
)
local_task
->
attributes
.
user_data
;
embb_mtapi_network_buffer_t
send_buf
;
embb_mtapi_network_buffer_t
*
send_buf
=
&
plugin
->
send_buffer
;
// init buffer for sending
embb_mtapi_network_buffer_initialize
(
&
send_buf
,
plugin
->
buffer_size
);
// serialize sending of results
embb_mutex_lock
(
&
plugin
->
send_mutex
);
embb_mtapi_network_buffer_clear
(
send_buf
);
// operation is "return result"
err
=
embb_mtapi_network_buffer_push_back_int8
(
&
send_buf
,
EMBB_MTAPI_NETWORK_RETURN_RESULT
);
send_buf
,
EMBB_MTAPI_NETWORK_RETURN_RESULT
);
assert
(
err
==
1
);
// remote task id
err
=
embb_mtapi_network_buffer_push_back_int32
(
&
send_buf
,
network_task
->
remote_task_id
);
send_buf
,
network_task
->
remote_task_id
);
assert
(
err
==
4
);
err
=
embb_mtapi_network_buffer_push_back_int32
(
&
send_buf
,
network_task
->
remote_task_tag
);
send_buf
,
network_task
->
remote_task_tag
);
assert
(
err
==
4
);
// status
err
=
embb_mtapi_network_buffer_push_back_int32
(
&
send_buf
,
local_task
->
error_code
);
send_buf
,
local_task
->
error_code
);
assert
(
err
==
4
);
// result size
err
=
embb_mtapi_network_buffer_push_back_int32
(
&
send_buf
,
local_task
->
result_size
);
send_buf
,
local_task
->
result_size
);
assert
(
err
==
4
);
err
=
embb_mtapi_network_buffer_push_back_rawdata
(
&
send_buf
,
local_task
->
result_size
,
local_task
->
result_buffer
);
send_buf
,
local_task
->
result_size
,
local_task
->
result_buffer
);
assert
(
err
==
(
int
)
local_task
->
result_size
);
err
=
embb_mtapi_network_socket_sendbuffer
(
&
network_task
->
socket
,
&
send_buf
);
assert
(
err
==
send_buf
.
size
);
&
network_task
->
socket
,
send_buf
);
assert
(
err
==
send_buf
->
size
);
// sending done
, free the buffer
embb_m
tapi_network_buffer_finalize
(
&
send_buf
);
// sending done
embb_m
utex_unlock
(
&
plugin
->
send_mutex
);
// we allocated arguments and results on receive, so free them here
embb_free
((
void
*
)
local_task
->
arguments
);
...
...
@@ -416,6 +420,10 @@ void mtapi_network_plugin_initialize(
plugin
->
sockets
=
(
embb_mtapi_network_socket_t
*
)
embb_alloc
(
sizeof
(
embb_mtapi_network_socket_t
)
*
(
1
+
max_connections
*
2
));
embb_mtapi_network_buffer_initialize
(
&
plugin
->
send_buffer
,
plugin
->
buffer_size
);
embb_mutex_init
(
&
plugin
->
send_mutex
,
0
);
if
(
NULL
!=
plugin
->
sockets
)
{
err
=
embb_mtapi_network_socket_initialize
(
&
plugin
->
sockets
[
0
]);
if
(
err
)
{
...
...
@@ -444,6 +452,9 @@ void mtapi_network_plugin_finalize(
embb_atomic_store_int
(
&
plugin
->
run
,
0
);
embb_thread_join
(
&
plugin
->
thread
,
&
err
);
embb_mutex_destroy
(
&
plugin
->
send_mutex
);
embb_mtapi_network_buffer_finalize
(
&
plugin
->
send_buffer
);
embb_mtapi_network_socket_finalize
(
&
plugin
->
sockets
[
0
]);
embb_free
(
plugin
->
sockets
);
embb_mtapi_network_finalize
();
...
...
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