flush wrapped to be able to do flush and ob_flush
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index fffd692..881bfa4 100644 (file)
@@ -527,8 +527,8 @@ class Bin5_user extends User {
             if (validate_sess($sess) == FALSE)
                 break;
             
-            if (file_exists(BIN5_PROXY_PATH) == FALSE)
-                mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+            if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
+                mkdir(BIN5_PROXY_PATH."/table".$tab_id, 0775, TRUE);
             if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step", 'rb')) == FALSE)
                 break;
             if (($s = fread($fp, 8)) == FALSE)
@@ -555,8 +555,8 @@ class Bin5_user extends User {
         do {
             if (validate_sess($this->sess) == FALSE)
                 break;
-            if (file_exists(BIN5_PROXY_PATH) == FALSE)
-                mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+            if (file_exists(BIN5_PROXY_PATH."/table".$this->table_orig) == FALSE)
+                mkdir(BIN5_PROXY_PATH."/table".$this->table_orig, 0775, TRUE);
             if (($fp = @fopen(BIN5_PROXY_PATH."/table".$this->table_orig."/".$this->sess.".step", 'w')) == FALSE)
                 break;
             fwrite($fp, pack("LL",$this->step, $this->idx));
@@ -992,34 +992,20 @@ class Bin5 {
     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; 
 
@@ -1028,7 +1014,7 @@ class Bin5 {
 
     log_lock("UNLOCK table [".$tab."]         [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
 
-    return (sem_release($res));
+    file_unlock($res);
   }
 
 
@@ -1208,8 +1194,8 @@ class Bin5 {
       $ret = TRUE;
       $fp = FALSE;
       do {
-          if (file_exists(BIN5_PROXY_PATH) == FALSE)
-              mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+          if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
+              mkdir(BIN5_PROXY_PATH."/table".$tab_id, 0775, TRUE);
           if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'rb')) == FALSE)
               break;
           if (($s = fread($fp, 4)) == FALSE)
@@ -1232,8 +1218,8 @@ class Bin5 {
   static function garbage_time_expire_set($tab_id, $tm) 
   {
       do {
-          if (file_exists(BIN5_PROXY_PATH) == FALSE)
-              mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+          if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
+              mkdir(BIN5_PROXY_PATH."/table".$tab_id, 0775, TRUE);
           if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'wb')) == FALSE)
               break;
           fwrite($fp, pack("L",$tm));