Skip to content

Commit

Permalink
Fix naming for redbean shared memory atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Oct 6, 2022
1 parent a5b483f commit 60b68d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/tool/net/futex_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions test/tool/net/mapshared_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions third_party/lua/lunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2882,10 +2882,10 @@ static const luaL_Reg kLuaUnixMemoryMeth[] = {
{"store", LuaUnixMemoryStore}, //
{"xchg", LuaUnixMemoryXchg}, //
{"cmpxchg", LuaUnixMemoryCmpxchg}, //
{"add", LuaUnixMemoryAdd}, //
{"and", LuaUnixMemoryAnd}, //
{"or", LuaUnixMemoryOr}, //
{"xor", LuaUnixMemoryXor}, //
{"fetch_add", LuaUnixMemoryAdd}, //
{"fetch_and", LuaUnixMemoryAnd}, //
{"fetch_or", LuaUnixMemoryOr}, //
{"fetch_xor", LuaUnixMemoryXor}, //
{"wait", LuaUnixMemoryWait}, //
{"wake", LuaUnixMemoryWake}, //
{0}, //
Expand Down
8 changes: 4 additions & 4 deletions tool/net/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4620,7 +4620,7 @@ UNIX MODULE
This operation happens atomically and provides the same memory
barrier semantics as the aligned x86 LOCK CMPXCHG instruction.

unix.Memory:add(word_index:int, value:int)
unix.Memory:fetch_add(word_index:int, value:int)
└─→ old:int

Fetches then adds value.
Expand All @@ -4632,23 +4632,23 @@ UNIX MODULE
This operation is atomic and provides the same memory barrier
semantics as the aligned x86 LOCK XADD instruction.

unix.Memory:and(word_index:int, value:int)
unix.Memory:fetch_and(word_index:int, value:int)
└─→ int

Fetches and bitwise ands value.

This operation happens atomically and provides the same memory
barrier ordering semantics as its x86 implementation.

unix.Memory:or(word_index:int, value:int)
unix.Memory:fetch_or(word_index:int, value:int)
└─→ int

Fetches and bitwise ors value.

This operation happens atomically and provides the same memory
barrier ordering semantics as its x86 implementation.

unix.Memory:xor(word_index:int, value:int)
unix.Memory:fetch_xor(word_index:int, value:int)
└─→ int

Fetches and bitwise xors value.
Expand Down

0 comments on commit 60b68d7

Please sign in to comment.