-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement apcu_inc/dec using atomic operations
This also changes apcu_inc/dec to wrap around on overflow, instead of saturating to a float value.
- Loading branch information
Showing
3 changed files
with
33 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
--TEST-- | ||
APC: integer overflow consistency | ||
APC: Atomic inc + dec wrap around on overflow | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--INI-- | ||
apc.enabled=1 | ||
apc.enable_cli=1 | ||
--FILE-- | ||
<?php | ||
$key="testkey"; | ||
$i=PHP_INT_MAX; | ||
apcu_store($key, $i); | ||
var_dump($j=apcu_fetch($key)); | ||
var_dump($i==$j); | ||
$key = "testkey"; | ||
|
||
apcu_inc($key, 1); | ||
$i++; | ||
var_dump($j=apcu_fetch($key)); | ||
var_dump($i==$j); | ||
apcu_store($key, PHP_INT_MAX); | ||
var_dump($i = apcu_inc($key, 1)); | ||
var_dump($j = apcu_fetch($key)); | ||
var_dump($i == $j); | ||
var_dump($j == PHP_INT_MIN); | ||
|
||
apcu_store($key, PHP_INT_MIN); | ||
var_dump($i = apcu_dec($key, 1)); | ||
var_dump($j = apcu_fetch($key)); | ||
var_dump($i == $j); | ||
var_dump($j == PHP_INT_MAX); | ||
|
||
$i=PHP_INT_MIN; | ||
apcu_store($key, $i); | ||
apcu_dec($key, 1); | ||
$i--; | ||
var_dump($j=apcu_fetch($key)); | ||
var_dump($i==$j); | ||
?> | ||
===DONE=== | ||
--EXPECTF-- | ||
int(%d) | ||
int(%i) | ||
int(%i) | ||
bool(true) | ||
bool(true) | ||
float(%s) | ||
int(%i) | ||
int(%i) | ||
bool(true) | ||
float(%s) | ||
bool(true) | ||
===DONE=== |