Skip to content

Commit

Permalink
Destroy CuEvent from the finalizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Nov 17, 2016
1 parent e3df046 commit dc1c5cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ export CuEvent, record, synchronize, elapsed

typealias CuEvent_t Ptr{Void}

immutable CuEvent
type CuEvent
handle::CuEvent_t
ctx::CuContext

function CuEvent()
handle_ref = Ref{CuEvent_t}()
@apicall(:cuEventCreate, (Ptr{CuEvent_t}, Cuint), handle_ref, 0)
return new(handle_ref[])

ctx = CuCurrentContext()
obj = new(handle_ref[], ctx)
gc_track(ctx, obj)
finalizer(obj, finalize)
return obj
end
end

function finalize(e::CuEvent)
trace("Finalizing CuEvent at $(Base.pointer_from_objref(e))")
@apicall(:cuEventDestroy, (CuEvent_t,), e)
gc_untrack(e.ctx, e)
end

Base.unsafe_convert(::Type{CuEvent_t}, e::CuEvent) = e.handle

Base.:(==)(a::CuEvent, b::CuEvent) = a.handle == b.handle
Expand All @@ -31,5 +43,3 @@ function elapsed(start::CuEvent, stop::CuEvent)
time_ref, start, stop)
return time_ref[]
end

destroy(e::CuEvent) = @apicall(:cuEventDestroy, (CuEvent_t,), e)
2 changes: 0 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ let
record(stop)
synchronize(stop)
@test elapsed(start, stop) > 0
destroy(start)
destroy(stop)
end


Expand Down

0 comments on commit dc1c5cc

Please sign in to comment.