diff --git a/src/Augustus.jl b/src/Augustus.jl index 675fdb2..c59a979 100644 --- a/src/Augustus.jl +++ b/src/Augustus.jl @@ -1,3 +1,6 @@ module Augustus +include("types.jl") +include("macros.jl") + end # module Augustus diff --git a/src/macros.jl b/src/macros.jl new file mode 100644 index 0000000..ee551c7 --- /dev/null +++ b/src/macros.jl @@ -0,0 +1,20 @@ +# Some of the code in this file is taken from Gaius.jl (license: MIT) +# https://github.com/MasonProtter/Gaius.jl + +# Note this does not support changing the number of threads at runtime + +macro _spawn(ex) + if Threads.nthreads() > 1 + esc(Expr(:macrocall, Expr(:(.), :Threads, QuoteNode(Symbol("@spawn"))), __source__, ex)) + else + esc(ex) + end +end + +macro _sync(ex) + if Threads.nthreads() > 1 + esc(Expr(:macrocall, Symbol("@sync"), __source__, ex)) + else + esc(ex) + end +end diff --git a/src/types.jl b/src/types.jl new file mode 100644 index 0000000..e69de29 diff --git a/test/macros.jl b/test/macros.jl new file mode 100644 index 0000000..f2206c7 --- /dev/null +++ b/test/macros.jl @@ -0,0 +1,12 @@ +@testset "Macros" begin + a = Augustus.@_sync begin + Augustus.@_spawn begin + 1 + 1 + end + end + if Threads.nthreads() > 1 + @test fetch(a) == 2 + else + @test a == 2 + end +end diff --git a/test/runtests.jl b/test/runtests.jl index aea7d48..da89adc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,5 +11,4 @@ versioninfo() @info("Running tests with $(Threads.nthreads()) threads") -@testset "Augustus.jl" begin -end +include("macros.jl")