From: Matteo Nastasi (mop) Date: Fri, 20 May 2011 06:11:42 +0000 (+0200) Subject: is_exclusive argument added to all lock_data() functions, (exclusivity is always... X-Git-Tag: 3.5.6~11 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=6a7088b090b78123ccfaa3ba00e1ea81647b173c;p=brisk.git is_exclusive argument added to all lock_data() functions, (exclusivity is always TRUE for backcompatibility) --- diff --git a/web/Obj/auth.phh b/web/Obj/auth.phh index 00add0c..36b75ca 100644 --- a/web/Obj/auth.phh +++ b/web/Obj/auth.phh @@ -244,13 +244,13 @@ class Challenges { return (FALSE); } - static function lock_data() + static function lock_data($is_exclusive) { if (($tok = @ftok(FTOK_PATH."/challenges", "B")) == -1) { return (FALSE); } // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 8b12641..8663ca2 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -57,6 +57,7 @@ define(BAN_TIME, 3600); define(GARBAGE_TIMEOUT, 10); define(NICKSERV, "BriskServ"); +define(LOCK_SHARE_MAX, 10000); define(DBG_ONL2, 0x0001); define(DBG_ONLY, 0x0002); @@ -1094,7 +1095,7 @@ class Room { if ($table_cur->player_n == PLAYERS_N) { log_main("PLAYERS == N TABLE ".$table_idx); - if (($sem = Bin5::lock_data($table_idx)) != FALSE) { + if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { log_main("bin5 lock data success"); $no_recovery = FALSE; @@ -1933,7 +1934,7 @@ class Room { if ($table_cur->player_n == PLAYERS_N) { log_main("PLAYERS == N TABLE ".$table_idx); - if (($sem = Bin5::lock_data($table_idx)) != FALSE) { + if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { log_main("bin5 lock data success"); $no_recovery = FALSE; @@ -2112,7 +2113,7 @@ class Room { if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) { // FIXME BRISK4: include for each kind of table require_once("${G_base}briskin5/Obj/briskin5.phh"); - if (($brisem = Bin5::lock_data($table_idx)) != FALSE) { + if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { if (($bri = Bin5::load_data($table_idx)) != FALSE) { if ($bri->the_end != TRUE) { $bri->user[$ghost_user->table_pos]->step_inc(); @@ -2403,7 +2404,7 @@ class Room { return ($ret); } - static function lock_data() + static function lock_data($is_exclusive) { GLOBAL $sess; @@ -2413,7 +2414,7 @@ class Room { return (FALSE); } // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { @@ -3047,7 +3048,7 @@ function sharedmem_sz($tok) class Warrant { static $delta_t; - static function lock_data() + static function lock_data($is_exclusive) { GLOBAL $sess; @@ -3055,7 +3056,7 @@ class Warrant { return (FALSE); } // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { @@ -3080,7 +3081,7 @@ class Warrant { class Poll { static $delta_t; - static function lock_data() + static function lock_data($is_exclusive) { GLOBAL $sess; @@ -3088,7 +3089,7 @@ class Poll { return (FALSE); } // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { diff --git a/web/Obj/dbase_file.phh b/web/Obj/dbase_file.phh index 13dce47..d6d7b5b 100644 --- a/web/Obj/dbase_file.phh +++ b/web/Obj/dbase_file.phh @@ -145,7 +145,7 @@ class BriskDB { log_main("login[".$i."]: ".$this->item[$i]->login); /* if it exists check for a valid challenge */ - if (($a_sem = Challenges::lock_data()) != FALSE) { + if (($a_sem = Challenges::lock_data(TRUE)) != FALSE) { if (($chals = &Challenges::load_data()) != FALSE) { for ($e = 0 ; $e < $chals->item_n ; $e++) { diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index 8dbdfb6..1a05b70 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -150,7 +150,7 @@ class BriskDB log_main("login[".$user_obj->code."]: ".$user_obj->login); /* if it exists check for a valid challenge */ - if (($a_sem = Challenges::lock_data()) != FALSE) { + if (($a_sem = Challenges::lock_data(TRUE)) != FALSE) { if (($chals = &Challenges::load_data()) != FALSE) { for ($e = 0 ; $e < $chals->item_n ; $e++) { log_main("challenge[".$e."]: ".$chals->item[$e]->login); diff --git a/web/Obj/hardban.phh b/web/Obj/hardban.phh index e2eeaba..477a410 100644 --- a/web/Obj/hardban.phh +++ b/web/Obj/hardban.phh @@ -238,13 +238,13 @@ class Hardbans { return (FALSE); } - static function lock_data() + static function lock_data($is_exclusive) { if (($tok = @ftok(FTOK_PATH."/hardbans", "B")) == -1) { return (FALSE); } // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { @@ -270,7 +270,7 @@ class Hardbans { { $bantime = -1; /* if it exists check for a valid challenge */ - if (($a_sem = Hardbans::lock_data()) != FALSE) { + if (($a_sem = Hardbans::lock_data(TRUE)) != FALSE) { if (($hban = &Hardbans::load_data()) != FALSE) { for ($e = 0 ; $e < $hban->item_n ; $e++) { @@ -304,7 +304,7 @@ class Hardbans { { $found = FALSE; /* if it exists check for a valid challenge */ - if (($a_sem = Hardbans::lock_data()) != FALSE) { + if (($a_sem = Hardbans::lock_data(TRUE)) != FALSE) { if (($hban = &Hardbans::load_data()) != FALSE) { diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 99bdc1e..9484067 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -992,7 +992,7 @@ class Bin5 { return ($ret); } - static function lock_data($table_idx) + static function lock_data($is_exclusive, $table_idx) { GLOBAL $sess; @@ -1004,7 +1004,7 @@ class Bin5 { return (FALSE); } // WARNING monitor this step - if (($res = @sem_get($tok)) == FALSE) { + if (($res = @sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) { return (FALSE); } if (sem_acquire($res)) { diff --git a/web/briskin5/index_rd.php b/web/briskin5/index_rd.php index 0dab464..2da54a8 100644 --- a/web/briskin5/index_rd.php +++ b/web/briskin5/index_rd.php @@ -95,7 +95,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su ignore_user_abort(TRUE); if ($first_loop == TRUE) { - if (($sem = Bin5::lock_data($table_idx)) != FALSE) { + if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { // Aggiorna l'expire time lato server $S_load_stat['U_first_loop']++; @@ -126,7 +126,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su log_main("infolock: U"); Bin5::unlock_data($sem); ignore_user_abort(FALSE); - } // if (($sem = Bin5::lock_data($table ... + } // if (($sem = Bin5::lock_data(TRUE, $table ... else { ignore_user_abort(FALSE); @@ -147,7 +147,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if ($user == FALSE) { do { ignore_user_abort(TRUE); - if (($sem = Bin5::lock_data($table_idx)) == FALSE) + if (($sem = Bin5::lock_data(TRUE, $table_idx)) == FALSE) break; log_main("infolock: P"); @@ -176,7 +176,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su * if $cur_step == -1 load the current state from the main struct */ ignore_user_abort(TRUE); - $sem = Bin5::lock_data($table_idx); + $sem = Bin5::lock_data(TRUE, $table_idx); if (($bri = Bin5::load_data($table_idx, $table_token)) == FALSE) { Bin5::unlock_data($sem); ignore_user_abort(FALSE); @@ -239,7 +239,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su } else { ignore_user_abort(TRUE); - $sem = Bin5::lock_data($table_idx); + $sem = Bin5::lock_data(TRUE, $table_idx); // if (($user = &$bri->get_user($sess, $idx)) == FALSE) { if (($user = Bin5_user::load_data($table_idx, $proxy_step['i'], $sess)) == FALSE) { Bin5::unlock_data($sem); diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index ab6878c..1eabe2c 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -52,7 +52,7 @@ if ($table_idx < 0 || $table_idx >= TABLE_N) log_mop(0, 'bin::index_wr.php: COMM: '.xcapemesg($mesg)); -$sem = Bin5::lock_data($table_idx); +$sem = Bin5::lock_data(TRUE, $table_idx); if (($bri = Bin5::load_data($table_idx,$table_token)) == FALSE) { echo "Bin5 Load data error"; diff --git a/web/index.php b/web/index.php index 90191d5..f3b8229 100644 --- a/web/index.php +++ b/web/index.php @@ -236,7 +236,7 @@ function main() if (isset($BRISK_SHOWHTML) == FALSE) { $is_table = FALSE; - $sem = Room::lock_data(); + $sem = Room::lock_data(TRUE); log_main("lock Room"); if (($room = Room::load_data()) == FALSE) { log_crit("load_data failed"); diff --git a/web/index_rd.php b/web/index_rd.php index ebb28d3..a8a4126 100644 --- a/web/index_rd.php +++ b/web/index_rd.php @@ -116,7 +116,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su /* Sync check (read only without modifications */ ignore_user_abort(TRUE); if ($first_loop == TRUE) { - if (($sem = Room::lock_data()) != FALSE) { + if (($sem = Room::lock_data(TRUE)) != FALSE) { // Aggiorna l'expire time lato server $S_load_stat['U_first_loop']++; if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { @@ -144,7 +144,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su log_main("infolock: U"); Room::unlock_data($sem); ignore_user_abort(FALSE); - } // if (($sem = Room::lock_data()) != FALSE) { + } // if (($sem = Room::lock_data(TRUE)) != FALSE) { else { // wait 20 secs, then restart the xhr ignore_user_abort(FALSE); @@ -166,7 +166,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if ($user == FALSE) { do { ignore_user_abort(TRUE); - if (($sem = Room::lock_data()) == FALSE) + if (($sem = Room::lock_data(TRUE)) == FALSE) break; log_main("infolock: P"); @@ -196,7 +196,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su * if $cur_step == -1 load the current state from the main struct */ ignore_user_abort(TRUE); - $sem = Room::lock_data(); + $sem = Room::lock_data(TRUE); if (($room = Room::load_data()) == FALSE) { Room::unlock_data($sem); ignore_user_abort(FALSE); @@ -284,7 +284,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su else { // TODO: verify if we can use only $user struct ignore_user_abort(TRUE); - $sem = Room::lock_data(); + $sem = Room::lock_data(TRUE); $S_load_stat['U_heavy']++; if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { Room::unlock_data($sem); diff --git a/web/index_wr.php b/web/index_wr.php index c2deba8..c1fbcff 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -106,7 +106,7 @@ log_wr('COMM: '.xcapemesg($mesg)); $curtime = time(); $dt = date("H:i ", $curtime); -$sem = Room::lock_data(); +$sem = Room::lock_data(TRUE); if (($room = &Room::load_data()) == FALSE) { echo "Load data error"; log_wr("Load data error"); @@ -119,7 +119,7 @@ if (($user = $room->get_user($sess, &$idx)) == FALSE) { if ($argz[0] == 'getchallenge') { GLOBAL $cli_name; - if (($a_sem = Challenges::lock_data()) != FALSE) { + if (($a_sem = Challenges::lock_data(TRUE)) != FALSE) { log_main("chal lock data success"); if (($chals = &Challenges::load_data()) != FALSE) { @@ -209,7 +209,7 @@ else if ($argz[0] == 'warranty') { log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); if ($user->flags & USER_FLAG_AUTH) { - if (($wa_lock = Warrant::lock_data()) != FALSE) { + if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) { /* Unix time | session | nickname | IP | where was | mesg */ fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, $user->name, xcapelt(urldecode($cli_name)), xcapelt(urldecode($cli_email)))); @@ -247,7 +247,7 @@ else if ($argz[0] == 'mesgtoadm') { log_wr("INFO:SKIP:argz == mesgtoadm name: [".$user->name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); if ($user->flags & USER_FLAG_AUTH) { - if (($wa_lock = Warrant::lock_data()) != FALSE) { + if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { if (($bdb = BriskDB::create()) != FALSE) { $bdb->users_load(); @@ -339,7 +339,7 @@ else if ($argz[0] == 'poll') { break; } - if (($poll_lock = Poll::lock_data()) == FALSE) { + if (($poll_lock = Poll::lock_data(TRUE)) == FALSE) { /* MLANG: "E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore." */ $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['commerr'][$G_lang]); log_wr("break3"); @@ -571,7 +571,7 @@ else if ($user->stat == 'room') { // // Create new spawned table - $bri_sem = Bin5::lock_data($table_idx); + $bri_sem = Bin5::lock_data(TRUE, $table_idx); $table_token = uniqid(""); $room->table[$table_idx]->table_token = $table_token; $room->table[$table_idx]->table_start = $curtime;