static HOST *dict_mysql_find_host(PLMYSQL *PLDB, unsigned stat, unsigned type) { time_t t; int count = 0; int idx; int i; t = time((time_t *) 0); for (i = 0; i < PLDB->len_hosts; i++) { if (dict_mysql_check_stat(PLDB->db_hosts[i], stat, type, t)) count++; } if (count) { /* * Calling myrand() can deplete the random pool. * Don't rely on the optimizer to weed out the call * when count == 1. */ idx = (count > 1) ? 1 + (count - 1) * (double) myrand() / RAND_MAX : 1; for (i = 0; i < PLDB->len_hosts; i++) { if (dict_mysql_check_stat(PLDB->db_hosts[i], stat, type, t) && --idx == 0) return PLDB->db_hosts[i]; } } return 0; }
static HOST *dict_mysql_find_host(PLMYSQL *PLDB, unsigned stat, unsigned type) { time_t t; int count = 0; int idx; int i; t = time((time_t *) 0); for (i = 0; i < PLDB->len_hosts; i++) { if (dict_mysql_check_stat(PLDB->db_hosts[i], stat, type, t)) count++; } if (count) { idx = (count > 1) ? 1 + count * (double) myrand() / (1.0 + RAND_MAX) : 1; for (i = 0; i < PLDB->len_hosts; i++) { if (dict_mysql_check_stat(PLDB->db_hosts[i], stat, type, t) && --idx == 0) return PLDB->db_hosts[i]; } } return 0; }