uatomic/x86: Remove redundant memory barriers
[urcu.git] / src / compat-rand.h
1 // SPDX-FileCopyrightText: 1996 Ulrich Drepper <drepper@cygnus.com>
2 // SPDX-FileCopyrightText: 2013 Pierre-Luc St-Charles <pierre-luc.st-charles@polymtl.ca>
3 //
4 // SPDX-License-Identifier: LGPL-2.1-or-later
5
6 #ifndef _COMPAT_RAND_H
7 #define _COMPAT_RAND_H
8
9 /*
10 * Userspace RCU library - rand/rand_r Compatibility Header
11 *
12 * Note: this file is only used to simplify the code required to
13 * use the 'rand_r(...)' system function across multiple platforms,
14 * which might not always be referenced the same way.
15 */
16
17 #ifndef HAVE_RAND_R
18 /*
19 * Reentrant random function from POSIX.1c.
20 * Copyright (C) 1996, 1999 Free Software Foundation, Inc.
21 * This file is part of the GNU C Library.
22 * Contributed by Ulrich Drepper <drepper@cygnus.com <mailto:drepper@cygnus.com>>, 1996.
23 */
24 static inline int rand_r(unsigned int *seed)
25 {
26 unsigned int next = *seed;
27 int result;
28
29 next *= 1103515245;
30 next += 12345;
31 result = (unsigned int) (next / 65536) % 2048;
32
33 next *= 1103515245;
34 next += 12345;
35 result <<= 10;
36 result ^= (unsigned int) (next / 65536) % 1024;
37
38 next *= 1103515245;
39 next += 12345;
40 result <<= 10;
41 result ^= (unsigned int) (next / 65536) % 1024;
42
43 *seed = next;
44
45 return result;
46 }
47 #endif /* HAVE_RAND_R */
48
49 #endif /* _COMPAT_RAND_H */
This page took 0.029238 seconds and 4 git commands to generate.