From: Matteo Nastasi (mop) Date: Wed, 19 Mar 2008 06:38:06 +0000 (+0000) Subject: new shared mem management X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=18b16ce1ecd95cc5e8c632c8610f7bd736dc6e9e;p=brisk.git new shared mem management --- diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index f2147d6..024e8cd 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1,7 +1,10 @@ user = array(); $this->table = array(); $this->the_end = FALSE; - + $this->shm_sz = BRISKIN5_SHM_MIN; if (($this->tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { echo "FTOK FAILED"; exit; @@ -123,20 +127,24 @@ class Briskin5 { function &load_data($table_idx, $table_token = "") { GLOBAL $G_false, $sess; + $doexit = FALSE; $shm = FALSE; log_wr("TABLE_IDX ".FTOK_PATH."/table".$table_idx); - if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { - echo "FTOK FAILED"; - exit; - } do { - // if (shmchk_exists($tok) == FALSE) - if (locshm_exists($tok) == FALSE) + if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { + log_main("ftok failed"); + $doexit = TRUE; break; + } - if (($shm = shm_attach($tok, BRISKIN5_SHM_DIMS)) == FALSE) + if (($shm_sz = sharedmem_sz($tok)) == -1) { + log_main("shmop_open failed"); + break; + } + + if (($shm = shm_attach($tok, $shm_sz)) == FALSE) break; if (($bri = @shm_get_var($shm, $tok)) == FALSE) @@ -159,15 +167,55 @@ class Briskin5 { shm_detach($shm); log_wr("briskin5 load_data failed"); + if ($doexit) + exit(); return ($G_false); } + function save_data(&$bri) { GLOBAL $sess; + $ret = FALSE; + $shm = FALSE; + + log_main("SAVE BRISKIN5 DATA"); + + if (!isset($bri->tok)) + return (FALSE); + + while ($bri->shm_sz < BRISKIN5_SHM_MAX) { + if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE) + break; + + // log_only("PUT_VAR DI ".strlen(serialize($room))); + if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) { + shm_detach($shm); + return (TRUE); + } + if (shm_remove($shm) === FALSE) { + log_only("REMOVE FALLITA"); + break; + } + shm_detach($shm); + $bri->shm_sz += BRISKIN5_SHM_DLT; + } + + if ($shm) + shm_detach($shm); + + return ($ret); + } + + + + function save_data_orig(&$bri) + { + GLOBAL $sess; + $ret = FALSE; $shm = FALSE; $isacq = FALSE; @@ -206,25 +254,19 @@ class Briskin5 { $ret = FALSE; $shm = FALSE; - $isacq = FALSE; - log_main("DESTROY BRISKIN5 DATA"); - do { - $isacq = TRUE; - log_main("DESTROY2 BRISKIN5 DATA"); if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) break; - if (($shm = shm_attach($tok, BRISKIN5_SHM_DIMS)) === FALSE) + if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE) break; - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA ".strlen(serialize($bri))); - log_only(serialize($bri)); + if (shmop_delete($shm) == 0) { + log_only("REMOVE FALLITA "); break; }