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
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
8020c3af
Commit
8020c3af
authored
Jun 06, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve garbage_collector.hpp
parent
b8fda6bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
19 deletions
+30
-19
rt/include/typon/core/scheduler.hpp
rt/include/typon/core/scheduler.hpp
+5
-7
rt/include/typon/core/worker.hpp
rt/include/typon/core/worker.hpp
+2
-2
rt/include/typon/fundamental/garbage_collector.hpp
rt/include/typon/fundamental/garbage_collector.hpp
+23
-10
No files found.
rt/include/typon/core/scheduler.hpp
View file @
8020c3af
...
...
@@ -10,7 +10,7 @@
#include <typon/fundamental/deque.hpp>
#include <typon/fundamental/event_count.hpp>
#include <typon/fundamental/g
c
.hpp>
#include <typon/fundamental/g
arbage_collector
.hpp>
#include <typon/fundamental/optional.hpp>
#include <typon/fundamental/random.hpp>
...
...
@@ -27,7 +27,7 @@ namespace typon
using
uint
=
unsigned
int
;
using
Task
=
typename
fdt
::
lock_free
::
deque
<
Continuation
>::
pop_type
;
using
Work
=
Worker
::
Work
;
using
GC
=
fdt
::
lock_free
::
gc
;
using
garbage_collector
=
fdt
::
lock_free
::
garbage_collector
;
static
inline
thread_local
uint
thread_id
;
...
...
@@ -97,7 +97,7 @@ namespace typon
std
::
atomic_bool
_done
{
false
};
fdt
::
lock_free
::
event_count
<>
_notifyer
;
const
uint
_concurrency
;
GC
_gc
;
garbage_collector
_gc
;
Scheduler
(
uint
concurrency
)
noexcept
:
_worker
(
concurrency
)
...
...
@@ -149,7 +149,7 @@ namespace typon
void
explore_work
(
Work
&
work
)
noexcept
{
_gc
.
enter
(
thread_id
);
auto
epoch
=
_gc
.
epoch
(
thread_id
);
for
(
uint
i
=
0
;
i
<
_concurrency
*
2
+
1
;
i
++
)
{
uint
id
=
fdt
::
random
::
random
()
%
_concurrency
;
...
...
@@ -159,12 +159,11 @@ namespace typon
break
;
}
}
_gc
.
leave
(
thread_id
);
}
void
detect_work
(
Work
&
work
)
noexcept
{
_gc
.
enter
(
thread_id
);
auto
epoch
=
_gc
.
epoch
(
thread_id
);
for
(
uint
id
=
0
;
id
<
_concurrency
;
id
++
)
{
work
=
_worker
[
id
].
try_steal
();
...
...
@@ -173,7 +172,6 @@ namespace typon
break
;
}
}
_gc
.
leave
(
thread_id
);
}
bool
wait_for_work
(
Work
&
work
)
noexcept
...
...
rt/include/typon/core/worker.hpp
View file @
8020c3af
...
...
@@ -7,7 +7,7 @@
#include <variant>
#include <vector>
#include <typon/fundamental/g
c
.hpp>
#include <typon/fundamental/g
arbage_collector
.hpp>
#include <typon/fundamental/optional.hpp>
#include <typon/fundamental/random.hpp>
...
...
@@ -60,7 +60,7 @@ namespace typon
}
}
void
resume
(
Work
&
work
,
fdt
::
lock_free
::
g
c
&
gc
)
noexcept
void
resume
(
Work
&
work
,
fdt
::
lock_free
::
g
arbage_collector
&
gc
)
noexcept
{
auto
active
=
_active
.
load
();
if
(
work
.
_state
==
Work
::
Resumable
)
...
...
rt/include/typon/fundamental/g
c
.hpp
→
rt/include/typon/fundamental/g
arbage_collector
.hpp
View file @
8020c3af
#ifndef TYPON_FUNDAMENTAL_G
C
_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_G
C
_HPP_INCLUDED
#ifndef TYPON_FUNDAMENTAL_G
ARBAGE_COLLECTOR
_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_G
ARBAGE_COLLECTOR
_HPP_INCLUDED
#include <atomic>
#include <bit>
#include <cstdint>
#include <deque>
#include <type_traits>
#include <typon/fundamental/meta.hpp>
#include <typon/fundamental/ring_buffer.hpp>
namespace
typon
::
fdt
::
lock_free
{
struct
g
c
struct
g
arbage_collector
{
using
u64
=
std
::
uint_fast64_t
;
using
uint
=
unsigned
int
;
...
...
@@ -54,7 +50,7 @@ namespace typon::fdt::lock_free
std
::
atomic
<
node
*>
_head
;
std
::
atomic
<
node
*>
_tail
;
g
c
(
uint
concurrency
)
noexcept
g
arbage_collector
(
uint
concurrency
)
noexcept
:
_concurrency
(
concurrency
)
,
_bits
(
std
::
bit_width
(
concurrency
))
,
_stamps
(
new
std
::
atomic
<
u64
>
[
concurrency
])
...
...
@@ -68,6 +64,23 @@ namespace typon::fdt::lock_free
}
}
auto
epoch
(
uint
id
)
noexcept
{
struct
epoch
{
garbage_collector
&
_gc
;
uint
_id
;
~
epoch
()
{
_gc
.
leave
(
_id
);
}
};
enter
(
id
);
return
epoch
{
*
this
,
id
};
}
void
enter
(
uint
id
)
noexcept
{
auto
state
=
_state
.
fetch_add
((
1
<<
_bits
)
+
1
);
...
...
@@ -136,7 +149,7 @@ namespace typon::fdt::lock_free
}
}
~
g
c
()
~
g
arbage_collector
()
{
delete
[]
_stamps
;
auto
tail
=
_tail
.
load
();
...
...
@@ -151,4 +164,4 @@ namespace typon::fdt::lock_free
}
#endif // TYPON_FUNDAMENTAL_G
C
_HPP_INCLUDED
#endif // TYPON_FUNDAMENTAL_G
ARBAGE_COLLECTOR
_HPP_INCLUDED
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