From:             
Operating system: all
PHP version:      5.3.8
Package:          Unknown/Other Function
Bug Type:         Feature/Change Request
Bug description:(shmop,) compare-and-swap functionality

Description:
------------
hi,

think it would be a good idea to have some kind of atomic functions in php
otherwise having any kind of shared memory is pointless imo

so the patch adds a shmop-cas function

current version is gcc specific
i could also provide an x86 asm version (in gcc syntax)
that should at least be adaptable to other compilers

tested and working on 32bit linux, php built using gcc 4.5.2


bj

Test script:
---------------
if ($shm = shmop_open(0, 'c', 0640, 4096))
{
        $val1 = rand();
        $val2 = rand();
        echo("random values: $val1, $val2\n");

        $wr = shmop_write($shm, pack('V', $val1), 0);
        echo("$wr bytes written\n");

        $ov = shmop_cas($shm, 0, 0, $val2);
        echo("old val = $ov, should be $val1\n");

        $tv = shmop_cas($shm, 0, $ov, $val2);
        echo("temp = $tv, should still be $val1\n");

        $cv = shmop_cas($shm, 0, $ov, $val1);
        echo("current val = $cv, should be $val2\n");

        $rstr = shmop_read($shm, 0, 4);
        $rarr = unpack("Vval", $rstr);
        $rval = $rarr['val'];
        echo("value read: $rval, should still be $val2\n");

        if (! shmop_delete($shm))
                echo("delete shm failed\n");
        shmop_close($shm);
}



-- 
Edit bug report at https://bugs.php.net/bug.php?id=55846&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55846&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55846&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55846&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55846&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55846&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55846&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55846&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55846&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55846&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55846&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55846&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55846&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55846&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55846&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55846&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55846&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55846&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55846&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55846&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55846&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55846&r=mysqlcfg

Reply via email to