Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
PRRT
Commits
4ae53964
Commit
4ae53964
authored
Mar 15, 2016
by
Andreas Schmidt
Browse files
Locking channel state information.
parent
eaaf1062
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/prrt/channelStateInformation.c
View file @
4ae53964
...
...
@@ -4,13 +4,13 @@
#include
"../util/dbg.h"
#include
"channelStateInformation.h"
// TODO: LOCKS
PrrtChannelStateInformation
*
PrrtChannelStateInformation_create
()
{
PrrtChannelStateInformation
*
csi
=
calloc
(
1
,
sizeof
(
PrrtChannelStateInformation
));
check_mem
(
csi
);
check
(
pthread_mutex_init
(
&
csi
->
lock
,
NULL
)
==
0
,
"Mutex init failed."
);
csi
->
rttMean
=
0
;
csi
->
rttDev
=
0
;
return
csi
;
...
...
@@ -22,16 +22,20 @@ PrrtChannelStateInformation * PrrtChannelStateInformation_create()
void
PrrtChannelStateInformation_update_rtt
(
PrrtChannelStateInformation
*
csi
,
prrtTimedelta_t
rtt
)
{
pthread_mutex_lock
(
&
csi
->
lock
);
int32_t
delta
=
rtt
-
csi
->
rttMean
;
// TODO: ensure that there are no arithemtic problems via rounding etc.
csi
->
rttMean
=
(
prrtTimedelta_t
)
(
csi
->
rttMean
+
RRT_ALPHA
*
delta
);
csi
->
rttDev
=
(
prrtTimedelta_t
)
(
csi
->
rttDev
+
RRT_ALPHA
*
(
labs
(
delta
)
-
csi
->
rttDev
));
pthread_mutex_unlock
(
&
csi
->
lock
);
}
void
PrrtChannelStateInformation_print
(
PrrtChannelStateInformation
*
csi
)
{
pthread_mutex_lock
(
&
csi
->
lock
);
check
(
csi
!=
NULL
,
"Input should not be NULL."
);
printf
(
"RTT [us]: %d +- %d
\n
"
,
csi
->
rttMean
,
csi
->
rttDev
);
pthread_mutex_unlock
(
&
csi
->
lock
);
return
;
error:
...
...
@@ -40,11 +44,17 @@ void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi)
prrtTimedelta_t
PrrtChannelStateInformation_get_rtt
(
PrrtChannelStateInformation
*
csi
)
{
return
csi
->
rttMean
;
pthread_mutex_lock
(
&
csi
->
lock
);
prrtTimedelta_t
res
=
csi
->
rttMean
;
pthread_mutex_unlock
(
&
csi
->
lock
);
return
res
;
}
bool
PrrtChannelStateInformation_destroy
(
PrrtChannelStateInformation
*
csi
)
{
check
(
pthread_mutex_destroy
(
&
csi
->
lock
)
==
EXIT_SUCCESS
,
"Destroy mutex failed."
);
free
(
csi
);
return
true
;
error:
return
false
;
}
src/prrt/channelStateInformation.h
View file @
4ae53964
...
...
@@ -4,6 +4,7 @@
#include
"packet.h"
typedef
struct
prrtChannelStateInformation
{
pthread_mutex_t
lock
;
prrtTimedelta_t
rttMean
;
prrtTimedelta_t
rttDev
;
}
PrrtChannelStateInformation
;
...
...
Write
Preview
Supports
Markdown
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