JuliaLang / Compat.jl

Compatibility across Julia versions
Other
144 stars 117 forks source link

Add `Base.@lock` macro, which avoids allocations for locked blocks, introduced in julia v1.3 #762

Open NHDaly opened 2 years ago

NHDaly commented 2 years ago

X-Ref:

Lets add @lock to Compat.jl so everyone can use this

Originally posted by @omus in https://github.com/JuliaTime/TimeZones.jl/pull/356#r711677096

Ref: JuliaLang/julia#36441 and JuliaLang/julia#39588


This would look something like this:

if VERSION >= v"1.3-"
    using Base: @lock
else
    macro lock(l, e)
        quote
            ll = $(esc(l));
            $lock(ll);
            try
                $(esc(e))
            finally
                $unlock(ll)
            end
        end
    end
end