From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: b.a.t.m.a.n@open-mesh.net
Subject: [B.A.T.M.A.N.] [PATCH] Make batman timer functions thread safe
Date: Sat, 13 Sep 2008 01:24:20 +0200 [thread overview]
Message-ID: <20080912232420.GA9669@sven-desktop.lazhur.ath.cx> (raw)
The calculation inside of update_internal_clock aren't atomic and can lead to
bogus time informations when many threads calling get_time_msec64 or
get_time_msec.
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
batman/posix/posix.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/batman/posix/posix.c b/batman/posix/posix.c
index dd24a65..042a2b9 100644
--- a/batman/posix/posix.c
+++ b/batman/posix/posix.c
@@ -49,6 +49,7 @@ static float system_tick;
uint8_t tunnel_running = 0;
+static pthread_mutex_t batman_clock_mutex = PTHREAD_MUTEX_INITIALIZER;
void update_internal_clock()
{
@@ -61,14 +62,26 @@ void update_internal_clock()
uint32_t get_time_msec()
{
+ uint32_t time;
+
+ pthread_mutex_lock(&batman_clock_mutex);
update_internal_clock();
- return (uint32_t)(((float)(batman_clock_ticks) * 1000) / system_tick);
+ time = (uint32_t)(((float)(batman_clock_ticks) * 1000) / system_tick);
+ pthread_mutex_unlock(&batman_clock_mutex);
+
+ return time;
}
uint64_t get_time_msec64()
{
+ uint64_t time;
+
+ pthread_mutex_lock(&batman_clock_mutex);
update_internal_clock();
- return (uint64_t)(((float)(batman_clock_ticks) * 1000) / system_tick);
+ time = (uint64_t)(((float)(batman_clock_ticks) * 1000) / system_tick);
+ pthread_mutex_unlock(&batman_clock_mutex);
+
+ return time;
}
/* batman animation */
--
1.6.0.1
next reply other threads:[~2008-09-12 23:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-12 23:24 Sven Eckelmann [this message]
2008-09-14 4:15 ` [B.A.T.M.A.N.] [PATCH] Make batman timer functions thread safe Marek Lindner
2008-09-15 8:28 ` freifunk
2008-09-16 13:34 ` Marek Lindner
2008-09-17 9:00 ` Axel Neumann
2008-09-18 7:42 ` Stephan Enderlein (Freifunk Dresden)
2008-09-21 13:58 ` [B.A.T.M.A.N.] policy-routing-script issues Axel Neumann
2008-12-18 11:25 ` Stephan Enderlein (Freifunk Dresden)
2008-12-18 13:17 ` Bastian Bittorf
2008-12-19 10:08 ` Stephan Enderlein (Freifunk Dresden)
2008-12-19 12:04 ` Gustavo Lindberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080912232420.GA9669@sven-desktop.lazhur.ath.cx \
--to=sven.eckelmann@gmx.de \
--cc=b.a.t.m.a.n@open-mesh.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).