projects
/
brisk.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
disabled comm flush optimization
[brisk.git]
/
web
/
briskin5
/
Obj
/
briskin5.phh
diff --git
a/web/briskin5/Obj/briskin5.phh
b/web/briskin5/Obj/briskin5.phh
index
11c7df3
..
1ad1937
100644
(file)
--- a/
web/briskin5/Obj/briskin5.phh
+++ b/
web/briskin5/Obj/briskin5.phh
@@
-1,7
+1,10
@@
<?php
define(BRISKIN5_PLAYERS_N, 3);
define(BRISKIN5_MAX_PLAYERS, BRISKIN5_PLAYERS_N);
<?php
define(BRISKIN5_PLAYERS_N, 3);
define(BRISKIN5_MAX_PLAYERS, BRISKIN5_PLAYERS_N);
-define(BRISKIN5_SHM_DIMS, (50000 * BRISKIN5_MAX_PLAYERS));
+// define(BRISKIN5_SHM_MIN, (50000 * BRISKIN5_MAX_PLAYERS));
+define(BRISKIN5_SHM_MIN, 32768);
+define(BRISKIN5_SHM_MAX, (BRISKIN5_SHM_MIN + 1048576));
+define(BRISKIN5_SHM_DLT, 32768);
class Briskin5 {
var $user;
class Briskin5 {
var $user;
@@
-14,16
+17,17
@@
class Briskin5 {
var $garbage_timeout;
var $the_end;
var $garbage_timeout;
var $the_end;
-
+
var $tok;
var $tok;
+ var $shm_sz;
function Briskin5 (&$room, $table_idx, $table_token) {
$this->user = array();
$this->table = array();
$this->the_end = FALSE;
function Briskin5 (&$room, $table_idx, $table_token) {
$this->user = array();
$this->table = array();
$this->the_end = FALSE;
-
- if (($this->tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
+ $this->shm_sz = BRISKIN5_SHM_MIN;
+ if (($this->tok =
@
ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
echo "FTOK FAILED";
exit;
}
echo "FTOK FAILED";
exit;
}
@@
-123,20
+127,24
@@
class Briskin5 {
function &load_data($table_idx, $table_token = "")
{
GLOBAL $G_false, $sess;
function &load_data($table_idx, $table_token = "")
{
GLOBAL $G_false, $sess;
+ $doexit = FALSE;
$shm = FALSE;
log_wr("TABLE_IDX ".FTOK_PATH."/table".$table_idx);
$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 {
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;
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)
break;
if (($bri = @shm_get_var($shm, $tok)) == FALSE)
@@
-159,72
+167,71
@@
class Briskin5 {
shm_detach($shm);
log_wr("briskin5 load_data failed");
shm_detach($shm);
log_wr("briskin5 load_data failed");
+ if ($doexit)
+ exit();
return ($G_false);
}
return ($G_false);
}
+
function save_data(&$bri)
{
GLOBAL $sess;
$ret = FALSE;
$shm = FALSE;
function save_data(&$bri)
{
GLOBAL $sess;
$ret = FALSE;
$shm = FALSE;
- $isacq = FALSE;
log_main("SAVE BRISKIN5 DATA");
log_main("SAVE BRISKIN5 DATA");
- // var_dump($bri);
if (!isset($bri->tok))
return (FALSE);
if (!isset($bri->tok))
return (FALSE);
- do {
- $isacq = TRUE;
-
- if (($shm = shm_attach($bri->tok, BRISKIN5_SHM_DIMS)) == FALSE)
+ while ($bri->shm_sz < BRISKIN5_SHM_MAX) {
+ if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE)
break;
break;
- // log_only("PUT_VAR DI ".strlen(serialize($bri)));
- if (shm_put_var($shm, $bri->tok, $bri) == FALSE) {
- log_only("PUT_VAR FALLITA ".strlen(serialize($bri)));
- log_only(serialize($bri));
+ if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) {
+ shm_detach($shm);
+ return (TRUE);
+ }
+ if (shm_remove($shm) === FALSE) {
+ log_only("REMOVE FALLITA");
break;
}
break;
}
- // log_main("QUI CI ARRIVA [".$bri->user[0]->name."]");
- $ret = TRUE;
- } while (0);
-
+ shm_detach($shm);
+ $bri->shm_sz += BRISKIN5_SHM_DLT;
+ }
+
+ log_crit("save data failed!");
+
if ($shm)
shm_detach($shm);
return ($ret);
}
if ($shm)
shm_detach($shm);
return ($ret);
}
+
+
function destroy_data($table_idx)
{
GLOBAL $sess;
$ret = FALSE;
$shm = FALSE;
function destroy_data($table_idx)
{
GLOBAL $sess;
$ret = FALSE;
$shm = FALSE;
- $isacq = FALSE;
-
log_main("DESTROY BRISKIN5 DATA");
log_main("DESTROY BRISKIN5 DATA");
-
do {
do {
- $isacq = TRUE;
-
log_main("DESTROY2 BRISKIN5 DATA");
log_main("DESTROY2 BRISKIN5 DATA");
- if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1)
+ if (($tok =
@
ftok(FTOK_PATH."/table".$table_idx, "B")) == -1)
break;
break;
- if (($shm =
shm_attach($tok, BRISKIN5_SHM_DIMS)) =
== FALSE)
+ if (($shm =
@shmop_open($tok, 'a', 0, 0))
== FALSE)
break;
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;
}
break;
}
@@
-248,12
+255,13
@@
class Briskin5 {
log_wr("LOCK_DATA ".FTOK_PATH."/table".$table_idx);
// echo "LOCK: ".FTOK_PATH."/main";
// exit;
log_wr("LOCK_DATA ".FTOK_PATH."/table".$table_idx);
// echo "LOCK: ".FTOK_PATH."/main";
// exit;
- if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
+ // FIXME monitor this step
+ if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
echo "FTOK FAILED";
exit;
}
echo "FTOK FAILED";
exit;
}
- //
echo "FTOK ".$tok."<br>";
- if (($res = sem_get($tok)) == FALSE) {
+ //
FIXME monitor this step
+ if (($res =
@
sem_get($tok)) == FALSE) {
echo "SEM_GET FAILED";
exit;
}
echo "SEM_GET FAILED";
exit;
}
@@
-452,4
+460,4
@@
function locshm_exists($tok)
}
}
-?>
\ No newline at end of file
+?>