Skip to content

Commit 170627b

Browse files
authored
Allow globally managing a default allocator to coordinate downstream … (#12)
* Allow globally managing a default allocator to coordinate downstream packages * more work
1 parent 3fd0380 commit 170627b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/LibAwsCommon.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,28 @@ for name in names(@__MODULE__; all=true)
4343
@eval export $name
4444
end
4545

46-
function init(allocator=aws_default_allocator())
46+
const DEFAULT_AWS_ALLOCATOR = Ref{Ptr{aws_allocator}}(C_NULL)
47+
const DEFAULT_AWS_ALLOCATOR_LOCK = ReentrantLock()
48+
49+
function set_default_aws_allocator!(allocator)
50+
@lock DEFAULT_AWS_ALLOCATOR_LOCK begin
51+
DEFAULT_AWS_ALLOCATOR[] = allocator
52+
return
53+
end
54+
end
55+
56+
function default_aws_allocator()
57+
@lock DEFAULT_AWS_ALLOCATOR_LOCK begin
58+
if DEFAULT_AWS_ALLOCATOR[] == C_NULL
59+
set_default_aws_allocator!(aws_default_allocator())
60+
end
61+
return DEFAULT_AWS_ALLOCATOR[]
62+
end
63+
end
64+
65+
export default_aws_allocator, set_default_aws_allocator!
66+
67+
function init(allocator=default_aws_allocator())
4768
aws_common_library_init(allocator)
4869
return
4970
end

0 commit comments

Comments
 (0)