Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
cython-plus
typon
Commits
3e8aa002
Commit
3e8aa002
authored
May 19, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc.hpp: Count threads to allow immediate free
parent
38b60673
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
rt/include/typon/fundamental/gc.hpp
rt/include/typon/fundamental/gc.hpp
+17
-6
No files found.
rt/include/typon/fundamental/gc.hpp
View file @
3e8aa002
...
...
@@ -48,13 +48,15 @@ namespace typon::fdt::lock_free
};
const
uint
_concurrency
;
const
uint
_bits
;
std
::
atomic
<
u64
>
*
const
_stamps
;
std
::
atomic
<
u64
>
_sta
mp
{
0
};
std
::
atomic
<
u64
>
_sta
te
{
0
};
std
::
atomic
<
node
*>
_head
;
std
::
atomic
<
node
*>
_tail
;
gc
(
uint
concurrency
)
noexcept
:
_concurrency
(
concurrency
)
,
_bits
(
std
::
bit_width
(
concurrency
))
,
_stamps
(
new
std
::
atomic
<
u64
>
[
concurrency
])
{
auto
first
=
new
node
(
0
);
...
...
@@ -68,20 +70,29 @@ namespace typon::fdt::lock_free
void
enter
(
uint
id
)
noexcept
{
_stamps
[
id
].
store
(
_stamp
.
fetch_add
(
1
));
auto
state
=
_state
.
fetch_add
((
1
<<
_bits
)
+
1
);
_stamps
[
id
].
store
(
state
>>
_bits
);
}
template
<
typename
T
>
void
retire
(
T
*
ptr
)
noexcept
{
auto
stamp
=
_stamp
.
load
();
auto
node
=
new
garbage
<
T
>
{
ptr
,
stamp
};
auto
head
=
_head
.
exchange
(
node
);
head
->
_next
.
store
(
node
);
auto
state
=
_state
.
load
();
if
((
state
&
((
1
<<
_bits
)
-
1
))
==
0
)
{
delete
ptr
;
}
else
{
auto
node
=
new
garbage
<
T
>
{
ptr
,
state
>>
_bits
};
auto
head
=
_head
.
exchange
(
node
);
head
->
_next
.
store
(
node
);
}
}
void
leave
(
uint
id
)
noexcept
{
_state
.
fetch_sub
(
1
);
_stamps
[
id
].
store
(
u64
(
-
1
));
if
(
_tail
.
load
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment