static function load_data($tab_id, $id, $sess)
{
- log_main("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
+ log_load("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
do {
if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
$this->table_idx = $table_idx;
$this->table_token = $table_token;
- Bin5::garbage_time_expire_set(0);
+ Bin5::garbage_time_expire_set($table_idx, 0);
log_wr("Bin5 constructor end");
}
$ismod = FALSE;
$curtime = time();
// externalized if ($force || $this->garbage_timeout < $curtime) {
- if ($force || Bin5::garbage_time_is_expired($curtime)) {
+ if ($force || Bin5::garbage_time_is_expired($this->table_idx, $curtime)) {
for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
$user_cur = $this->user[$i];
if ($user_cur->sess == "" ||
log_rd2($user_cur->sess." GARBAGE UPDATED!");
// externalized $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
- Bin5::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
+ Bin5::garbage_time_expire_set($this->table_idx, $curtime + GARBAGE_TIMEOUT);
$ismod = TRUE;
}
return ($ret);
}
- function lock_data($table_idx)
+ static function lock_data($is_exclusive, $table_idx)
{
- GLOBAL $sess;
-
- log_main("lockinfo: DATA ".FTOK_PATH."/bin5/table".$table_idx."/table");
- // echo "LOCK: ".FTOK_PATH."/main";
- // exit;
- // WARNING monitor this step
- if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
- return (FALSE);
- }
- // WARNING monitor this step
- if (($res = @sem_get($tok)) == FALSE) {
+ if (($res = file_lock(FTOK_PATH."/bin5/table".$table_idx."/table", $is_exclusive)) != FALSE) {
+ self::$delta_t = microtime(TRUE);
+ log_lock("LOCK table [".$table_idx."] [".self::$delta_t[$table_idx]."]");
+
+ return (new Vect(array('res' => $res, 'tab' => $table_idx)));
+ }
+
return (FALSE);
- }
- if (sem_acquire($res)) {
- self::$delta_t[$table_idx] = microtime(TRUE);
- log_lock("LOCK table [".$table_idx."] [".self::$delta_t[$table_idx]."]");
-
- return (new Vect(array('res' => $res, 'tab' => $table_idx)));
- }
- else {
- log_lock("LOCK table ".$table_idx.":FAILED");
- return (FALSE);
- }
}
+
- function unlock_data($res_vect)
+ static function unlock_data($res_vect)
{
GLOBAL $sess;
log_lock("UNLOCK table [".$tab."] [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
- return (sem_release($res));
+ file_unlock($res);
}
}
- static function garbage_time_is_expired($tm)
+ static function garbage_time_is_expired($tab_id, $tm)
{
$ret = TRUE;
$fp = FALSE;
do {
if (file_exists(BIN5_PROXY_PATH) == FALSE)
mkdir(BIN5_PROXY_PATH, 0775, TRUE);
- if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
+ if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'rb')) == FALSE)
break;
if (($s = fread($fp, 4)) == FALSE)
break;
return ($ret);
}
- static function garbage_time_expire_set($tm)
+ static function garbage_time_expire_set($tab_id, $tm)
{
do {
if (file_exists(BIN5_PROXY_PATH) == FALSE)
mkdir(BIN5_PROXY_PATH, 0775, TRUE);
- if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
+ if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'wb')) == FALSE)
break;
fwrite($fp, pack("L",$tm));
fclose($fp);