Reindent server/core/random_jkiss.c

This commit is contained in:
Johan Wikman
2015-11-30 16:04:18 +02:00
parent 72dd159f98
commit 233f50f3e6
2 changed files with 66 additions and 27 deletions

View File

@ -25,8 +25,8 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 26/08/15 Martin Brampton Initial implementation * 26/08/15 Martin Brampton Initial implementation
* *
* @endverbatim * @endverbatim
*/ */
@ -99,7 +99,12 @@ random_jkiss_devrand(void)
{ {
int fn; int fn;
unsigned int r; unsigned int r;
if ((fn = open("/dev/urandom", O_RDONLY)) == -1) return 0;
if ((fn = open("/dev/urandom", O_RDONLY)) == -1)
{
return 0;
}
if (read(fn, &r, sizeof(r)) != sizeof(r)) if (read(fn, &r, sizeof(r)) != sizeof(r))
{ {
r = 0; r = 0;
@ -118,14 +123,32 @@ static void
random_init_jkiss(void) random_init_jkiss(void)
{ {
int newrand, i; int newrand, i;
spinlock_acquire(&random_jkiss_spinlock); spinlock_acquire(&random_jkiss_spinlock);
if ((newrand = random_jkiss_devrand()) != 0) x = newrand;
if ((newrand = random_jkiss_devrand()) != 0) y = newrand;
if ((newrand = random_jkiss_devrand()) != 0) z = newrand;
if ((newrand = random_jkiss_devrand()) != 0) if ((newrand = random_jkiss_devrand()) != 0)
{
x = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
y = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
z = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
c = newrand % 698769068 + 1; /* Should be less than 698769069 */ c = newrand % 698769068 + 1; /* Should be less than 698769069 */
}
spinlock_release(&random_jkiss_spinlock); spinlock_release(&random_jkiss_spinlock);
/* "Warm up" our random number generator */ /* "Warm up" our random number generator */
for (i = 0; i < 100; i++) random_jkiss(); for (i = 0; i < 100; i++)
{
random_jkiss();
}
} }

View File

@ -1,3 +1,23 @@
#ifndef RANDOM_JKISS_H
#define RANDOM_JKISS_H
/*
* This file is distributed as part of the MariaDB Corporation MaxScale. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program 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 General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright MariaDB Corporation Ab 2013-2014
*/
/* /*
* File: random_jkiss.h * File: random_jkiss.h
* Author: mbrampton * Author: mbrampton
@ -5,9 +25,6 @@
* Created on 26 August 2015, 15:34 * Created on 26 August 2015, 15:34
*/ */
#ifndef RANDOM_JKISS_H
#define RANDOM_JKISS_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -19,4 +36,3 @@ extern unsigned int random_jkiss(void);
#endif #endif
#endif /* RANDOM_H */ #endif /* RANDOM_H */