Skip to content

Commit

Permalink
Merge pull request JuliaGPU#190 from JuliaGPU/tb/atapicall
Browse files Browse the repository at this point in the history
Use a more flexible API call hook.
  • Loading branch information
maleadt committed Dec 18, 2019
2 parents 4ddda79 + 36d1388 commit 05280c4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ end

## API call wrapper

const apicall_hook = Ref{Union{Nothing,Function}}(nothing)

# TODO: for the next breaking version
# const call_hooks = Set{Function}()
# @noinline do_call_hooks(fun) = filter!(hook->hook(fun), call_hooks)
const api_hooks = []
@noinline _call_api_hooks(fun::Symbol) = foreach(hook->hook(fun), api_hooks)
atapicall(f::Function) = (pushfirst!(api_hooks, f); nothing)

macro check(ex)
# check is used in front of `ccall` or `@runtime_ccall`s that work on a tuple (fun, lib)
Expand All @@ -115,8 +113,7 @@ macro check(ex)
end

quote
# NOTE: this hook is used by CUDAnative.jl to initialize upon the first API call
apicall_hook[] !== nothing && apicall_hook[]($(QuoteNode(Symbol(fun))))
_call_api_hooks($(QuoteNode(Symbol(fun))))

res::CUresult = $(esc(ex))
if res != CUDA_SUCCESS
Expand Down

0 comments on commit 05280c4

Please sign in to comment.