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:
Alex Szpakowski
2015-04-24 23:53:28 -03:00
parent 97806f87c0
commit 289eeb4fe0
3 changed files with 34 additions and 2 deletions
+1
View File
@@ -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: