From: charlesbriere.flatzo@gmail.com (Charles Briere)
Subject: [lttng-dev] [PATCH liburcu 5/5] Added implementation for rand_r()
Date: Wed, 27 Nov 2013 07:48:33 -0800 [thread overview]
Message-ID: <1385567313-8138-5-git-send-email-charlesbriere.flatzo@gmail.com> (raw)
In-Reply-To: <1385567313-8138-1-git-send-email-charlesbriere.flatzo@gmail.com>
From: Pierre-Luc St-Charles <pierre-luc.st-charles@polymtl.ca>
stdlib.h doesn't implement rand_r() on Android.
Signed-off-by: Charles Briere <charlesbriere.flatzo at gmail.com>
---
Makefile.am | 1 +
tests/benchmark/test_urcu_hash.h | 1 +
urcu/rand-compat.h | 63 ++++++++++++++++++++++++++++++++++++++++
urcu/static/urcu.h | 1 +
4 files changed, 66 insertions(+)
create mode 100644 urcu/rand-compat.h
diff --git a/Makefile.am b/Makefile.am
index 64073a1..38ff543 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,6 +23,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h \
urcu/lfstack.h urcu/syscall-compat.h \
$(top_srcdir)/urcu/map/*.h \
$(top_srcdir)/urcu/static/*.h \
+ urcu/rand-compat.h \
urcu/tls-compat.h
nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic.h urcu/config.h
diff --git a/tests/benchmark/test_urcu_hash.h b/tests/benchmark/test_urcu_hash.h
index c0727b7..b35acdb 100644
--- a/tests/benchmark/test_urcu_hash.h
+++ b/tests/benchmark/test_urcu_hash.h
@@ -37,6 +37,7 @@
#include <signal.h>
#include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
#include "cpuset.h"
#include "thread-id.h"
diff --git a/urcu/rand-compat.h b/urcu/rand-compat.h
new file mode 100644
index 0000000..2c57751
--- /dev/null
+++ b/urcu/rand-compat.h
@@ -0,0 +1,63 @@
+#ifndef _URCU_RAND_COMPAT_H
+#define _URCU_RAND_COMPAT_H
+
+/*
+ * urcu/rand-compat.h
+ *
+ * Userspace RCU library - rand/rand_r Compatibility Header
+ *
+ * Copyright 1996 - Ulrich Drepper <drepper at cygnus.com >
+ * Copyright 2013 - Pierre-Luc St-Charles <pierre-luc.st-charles at polymtl.ca>
+ *
+ * Note: this file is only used to simplify the code required to
+ * use the 'rand_r(...)' system function across multiple platforms,
+ * which might not always be referenced the same way.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef __ANDROID__
+/*
+ * Reentrant random function from POSIX.1c.
+ * Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ * This file is part of the GNU C Library.
+ * Contributed by Ulrich Drepper <drepper at cygnus.com <mailto:drepper at cygnus.com>>, 1996.
+ */
+static inline int rand_r(unsigned int *seed)
+{
+ unsigned int next = *seed;
+ int result;
+
+ next *= 1103515245;
+ next += 12345;
+ result = (unsigned int) (next / 65536) % 2048;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ *seed = next;
+
+ return result;
+}
+#endif /* __ANDROID__ */
+
+#endif /* _URCU_RAND_COMPAT_H */
diff --git a/urcu/static/urcu.h b/urcu/static/urcu.h
index 53d2610..33545b7 100644
--- a/urcu/static/urcu.h
+++ b/urcu/static/urcu.h
@@ -41,6 +41,7 @@
#include <urcu/list.h>
#include <urcu/futex.h>
#include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
#ifdef __cplusplus
extern "C" {
--
1.8.4.2
next prev parent reply other threads:[~2013-11-27 15:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-27 15:48 [lttng-dev] [PATCH liburcu 1/5] configure.ac Android check Charles Briere
2013-11-27 15:48 ` [lttng-dev] [PATCH liburcu 2/5] Dont link pthread on Android Charles Briere
2013-11-27 16:10 ` Mathieu Desnoyers
2013-11-28 9:30 ` Thomas Petazzoni
2013-11-29 0:10 ` Charles Brière
2013-11-29 6:01 ` Mathieu Desnoyers
2013-11-27 15:48 ` [lttng-dev] [PATCH liburcu 3/5] Added a compat layer for 'syscall.h' Charles Briere
2013-11-27 16:29 ` Mathieu Desnoyers
2013-11-27 17:20 ` Charles Brière
2013-11-27 17:38 ` Mathieu Desnoyers
2013-11-27 15:48 ` [lttng-dev] [PATCH liburcu 4/5] Fix: Do not redefine gettid on Android Charles Briere
2013-11-27 16:09 ` Mathieu Desnoyers
2013-11-27 15:48 ` Charles Briere [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-11-27 5:08 [lttng-dev] [PATCH liburcu 1/5] configure.ac Android check Charles Briere
2013-11-27 5:08 ` [lttng-dev] [PATCH liburcu 5/5] Added implementation for rand_r() Charles Briere
2013-11-27 9:36 ` Mathieu Desnoyers
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=1385567313-8138-5-git-send-email-charlesbriere.flatzo@gmail.com \
--to=charlesbriere.flatzo@gmail.com \
/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