Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [PATCH liburcu 5/5] Added implementation for rand_r()
Date: Wed, 27 Nov 2013 09:36:35 +0000 (UTC)	[thread overview]
Message-ID: <734300697.76533.1385544995507.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <1385528902-4797-5-git-send-email-charlesbriere.flatzo@gmail.com>

----- Original Message -----
> From: "Charles Briere" <charlesbriere.flatzo@gmail.com>
> To: "mathieu desnoyers" <mathieu.desnoyers at efficios.com>
> Cc: lttng-dev at lists.lttng.org, "Pierre-Luc St-Charles" <pierre-luc.st-charles at polymtl.ca>, "Charles Briere"
> <charlesbriere.flatzo at gmail.com>
> Sent: Wednesday, November 27, 2013 12:08:22 AM
> Subject: [PATCH liburcu 5/5] Added implementation for rand_r()
> 
> 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               | 60
>  ++++++++++++++++++++++++++++++++++++++++
>  urcu/static/urcu.h               |  1 +
>  4 files changed, 63 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..b9545c8
> --- /dev/null
> +++ b/urcu/rand-compat.h
> @@ -0,0 +1,60 @@
> +#ifndef _URCU_RAND_COMPAT_H
> +#define _URCU_RAND_COMPAT_H
> +
> +/*
> + * urcu/rand-compat.h
> + *
> + * Userspace RCU library - rand/rand_r Compatibility Header
> + *

Also missing copyright line. You probably want to put both your own
copyright, and the copyright from Ulrich Drepper here.

Thanks,

Mathieu

> + * 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
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



  reply	other threads:[~2013-11-27  9:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 2/5] Dont link pthread on Android Charles Briere
2013-11-27  5:08 ` [lttng-dev] [PATCH liburcu 3/5] Added a compat layer for 'syscall.h' Charles Briere
2013-11-27  9:35   ` Mathieu Desnoyers
2013-11-27  5:08 ` [lttng-dev] [PATCH liburcu 4/5] Fix: Do not redefine gettid on Android Charles Briere
2013-11-27  9:34   ` Mathieu Desnoyers
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 [this message]
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 5/5] Added implementation for rand_r() Charles Briere

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=734300697.76533.1385544995507.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.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