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:
@@ -39,6 +39,7 @@ class Channel : public love::Object
|
||||
// FOR WRAPPER USE ONLY
|
||||
friend void retainVariant(Channel *, Variant *);
|
||||
friend void releaseVariant(Channel *, Variant *);
|
||||
friend int w_Channel_performAtomic(lua_State *);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user