mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 02:51:44 +01:00
615d51b650
-Change my_rnd() slightly to make it safer if two threads use it at the same time. -Avoid some sprintf and strmov in vio. -Changed thread_count to be automically incremented (instead of under LOCK_thread_count). -Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count. -Moved delete thd out from LOCK_thread_count. -Save some mysql_cond_broadcast(&COND_thread_count) calls. -Removed call to getsockname() during connect. -Initialize random generator without locks. Other things: -Added thread_safe_decrement32() and thread_safe_increment32() -Removed sql_rnd_with_mutex() and get_thread_running() Thanks to Yoshinori Matsunobu for the benchmark of connection speed and to Domas Mituzas for the inspiration for many of the fixes. include/violite.h: Change desc to a string pointer mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysys/my_rnd.c: Change my_rnd() slightly to make it safer if two threads use it at the same time. sql/event_scheduler.cc: Changed thread_count to be automically incremented Moved some safe things out from LOCK_thread_count. Simplify deleting of THD for running thread. sql/mysqld.cc: Changed thread_count to be automically incremented Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count Added delete_running_thd() Moved delete thd out from LOCK_thread_count More DBUG_ENTER Only call mysql_cond_broadcast(&COND_thread_count) if thread_count is 0 Removed call to getsockname() (old not anymore needed check) sql/mysqld.h: Removed sql_rnd_with_mutex() (not needed anymore) Removed not used function get_thread_running() Added thread_safe_decrement32() and thread_safe_increment32() Simplified dec_thread_running() and inc_thread_running() sql/sql_class.cc: Removed thd_lock_thread_count() and thd_unlock_thread_count() Initialize random generator without locks sql/sql_insert.cc: Changed thread_count to be automically incremented sql/sql_parse.cc: Changed thread_count to be automically incremented vio/vio.c: Don't generate 'desc' with sprintf/strmov. Assign a pointer instead. (Good enough as this is just for debugging)
64 lines
2 KiB
C
64 lines
2 KiB
C
/* Copyright (C) 2007 MySQL AB & Michael Widenius
|
|
|
|
This program 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 of the License.
|
|
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#include "mysys_priv.h"
|
|
#include <m_string.h>
|
|
|
|
/*
|
|
Initialize random generator
|
|
|
|
NOTES
|
|
MySQL's password checks depends on this, so don't do any changes
|
|
that changes the random numbers that are generated!
|
|
*/
|
|
|
|
void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2)
|
|
{
|
|
#ifdef HAVE_valgrind
|
|
bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */
|
|
#endif
|
|
rand_st->max_value= 0x3FFFFFFFL;
|
|
rand_st->max_value_dbl=(double) rand_st->max_value;
|
|
rand_st->seed1=seed1%rand_st->max_value ;
|
|
rand_st->seed2=seed2%rand_st->max_value;
|
|
}
|
|
|
|
|
|
/*
|
|
Generate random number.
|
|
|
|
SYNOPSIS
|
|
my_rnd()
|
|
rand_st INOUT Structure used for number generation
|
|
|
|
RETURN VALUE
|
|
generated pseudo random number
|
|
|
|
NOTE:
|
|
This is codes so that it can be called by two threads at the same time
|
|
with minimum impact.
|
|
(As the number is supposed to be random, it doesn't matter much if
|
|
rand->seed1 or rand->seed2 are updated with slightly wrong numbers or
|
|
if two threads gets the same number.
|
|
*/
|
|
|
|
double my_rnd(struct my_rnd_struct *rand_st)
|
|
{
|
|
unsigned long seed1;
|
|
seed1= (rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
|
|
rand_st->seed2=(seed1+rand_st->seed2+33) % rand_st->max_value;
|
|
rand_st->seed1= seed1;
|
|
return (((double) seed1)/rand_st->max_value_dbl);
|
|
}
|