mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
Fix naming for redbean shared memory atomics
This commit is contained in:
parent
a5b483f2d4
commit
60b68d7152
4 changed files with 18 additions and 12 deletions
|
@ -54,7 +54,7 @@ function Lock()
|
|||
end
|
||||
end
|
||||
function Unlock()
|
||||
local old = mem:add(LOCK, -1)
|
||||
local old = mem:fetch_add(LOCK, -1)
|
||||
if old == 2 then
|
||||
mem:store(LOCK, 0)
|
||||
mem:wake(LOCK, 1)
|
||||
|
|
|
@ -45,15 +45,21 @@ ok, old = mem:cmpxchg(0, 0, 1)
|
|||
assert(ok and old == 0)
|
||||
ok, old = mem:cmpxchg(0, 666, 777)
|
||||
assert(not ok and old == 1)
|
||||
assert(mem:add(0, 3) == 1)
|
||||
assert(mem:load(0) == 4)
|
||||
assert(mem:fetch_add(0, 3) == 1)
|
||||
assert(mem:load(0) == 0b00000100)
|
||||
assert(mem:fetch_xor(0,0b00000110) == 0b00000100)
|
||||
assert(mem:load(0) == 0b00000010)
|
||||
assert(mem:fetch_and(0,0b00000110) == 0b00000010)
|
||||
assert(mem:load(0) == 0b00000010)
|
||||
assert(mem:fetch_or(0, 0b00000110) == 0b00000010)
|
||||
assert(mem:load(0) == 0b00000110)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- test atomic addition across concurrent processes
|
||||
|
||||
function Worker()
|
||||
for i = 1,iterations do
|
||||
mem:add(0, 1)
|
||||
mem:fetch_add(0, 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue