mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Added Channel:performAtomic(func, ...). Resolves issue #1034.
performAtomic calls the function and passes the Channel as the first argument, plus any additional specified arguments. The called function should do as little work as possible.
To other threads, all methods for that Channel are executed in a single step inside the function. This can prevent a large number of potiential race conditions.
Example:
-- main.lua:
local function set(channel, value)
channel:clear()
channel:push(value)
return "set value"
end
assert(channel:performAtomic(set, 1) == "set value")
-- thread.lua
while true do
assert(channel:peek() == 1)
end
This commit is contained in:
@@ -36,6 +36,7 @@ int w_Channel_demand(lua_State *L);
|
||||
int w_Channel_peek(lua_State *L);
|
||||
int w_Channel_getCount(lua_State *L);
|
||||
int w_Channel_clear(lua_State *L);
|
||||
int w_Channel_performAtomic(lua_State *L);
|
||||
|
||||
extern "C" int luaopen_channel(lua_State *L);
|
||||
} // thread
|
||||
|
||||
Reference in New Issue
Block a user