Skip to content

Commit

Permalink
Allow globally managing a default allocator to coordinate downstream … (
Browse files Browse the repository at this point in the history
#12)

* Allow globally managing a default allocator to coordinate downstream packages

* more work
  • Loading branch information
quinnj authored Jul 13, 2024
1 parent 3fd0380 commit 170627b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/LibAwsCommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,28 @@ for name in names(@__MODULE__; all=true)
@eval export $name
end

function init(allocator=aws_default_allocator())
const DEFAULT_AWS_ALLOCATOR = Ref{Ptr{aws_allocator}}(C_NULL)
const DEFAULT_AWS_ALLOCATOR_LOCK = ReentrantLock()

function set_default_aws_allocator!(allocator)
@lock DEFAULT_AWS_ALLOCATOR_LOCK begin
DEFAULT_AWS_ALLOCATOR[] = allocator
return
end
end

function default_aws_allocator()
@lock DEFAULT_AWS_ALLOCATOR_LOCK begin
if DEFAULT_AWS_ALLOCATOR[] == C_NULL
set_default_aws_allocator!(aws_default_allocator())
end
return DEFAULT_AWS_ALLOCATOR[]
end
end

export default_aws_allocator, set_default_aws_allocator!

function init(allocator=default_aws_allocator())
aws_common_library_init(allocator)
return
end
Expand Down

0 comments on commit 170627b

Please sign in to comment.