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
3e1af24c
Commit
3e1af24c
authored
Jun 20, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor scheduler.hpp and worker.hpp
parent
234e5684
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
20 deletions
+30
-20
rt/include/typon/core/scheduler.hpp
rt/include/typon/core/scheduler.hpp
+4
-10
rt/include/typon/core/worker.hpp
rt/include/typon/core/worker.hpp
+26
-10
No files found.
rt/include/typon/core/scheduler.hpp
View file @
3e1af24c
...
@@ -43,18 +43,12 @@ namespace typon
...
@@ -43,18 +43,12 @@ namespace typon
static
void
push
(
Continuation
task
)
noexcept
static
void
push
(
Continuation
task
)
noexcept
{
{
get
().
_worker
[
thread_id
].
_deque
.
load
()
->
push
(
task
);
get
().
_worker
[
thread_id
].
push
(
task
);
}
}
static
bool
pop
()
noexcept
static
bool
pop
()
noexcept
{
{
Deque
*
deque
=
get
().
_worker
[
thread_id
].
_deque
.
load
();
return
get
().
_worker
[
thread_id
].
pop
();
bool
result
=
deque
->
pop
();
if
(
auto
garbage
=
deque
->
reclaim
())
{
get
().
_gc
.
retire
(
garbage
);
}
return
result
;
}
}
static
auto
suspend
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
static
auto
suspend
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
...
@@ -145,7 +139,7 @@ namespace typon
...
@@ -145,7 +139,7 @@ namespace typon
for
(
uint
i
=
0
;
i
<
_concurrency
*
2
+
1
;
i
++
)
for
(
uint
i
=
0
;
i
<
_concurrency
*
2
+
1
;
i
++
)
{
{
uint
id
=
fdt
::
random
::
random
()
%
_concurrency
;
uint
id
=
fdt
::
random
::
random
()
%
_concurrency
;
work
=
_worker
[
id
].
try_
steal
();
work
=
_worker
[
id
].
steal
();
if
(
work
)
if
(
work
)
{
{
break
;
break
;
...
@@ -158,7 +152,7 @@ namespace typon
...
@@ -158,7 +152,7 @@ namespace typon
auto
epoch
=
_gc
.
epoch
(
thread_id
);
auto
epoch
=
_gc
.
epoch
(
thread_id
);
for
(
uint
id
=
0
;
id
<
_concurrency
;
id
++
)
for
(
uint
id
=
0
;
id
<
_concurrency
;
id
++
)
{
{
work
=
_worker
[
id
].
try_
steal
();
work
=
_worker
[
id
].
steal
();
if
(
work
)
if
(
work
)
{
{
break
;
break
;
...
...
rt/include/typon/core/worker.hpp
View file @
3e1af24c
...
@@ -61,6 +61,23 @@ namespace typon
...
@@ -61,6 +61,23 @@ namespace typon
}
}
}
}
void
add
(
Deque
*
deque
)
noexcept
{
std
::
lock_guard
lock
(
_mutex
);
_pool
.
push_back
(
deque
);
}
bool
try_add
(
Deque
*
deque
)
noexcept
{
if
(
!
_mutex
.
try_lock
())
{
return
false
;
}
std
::
lock_guard
lock
(
_mutex
,
std
::
adopt_lock
);
_pool
.
push_back
(
deque
);
return
true
;
}
auto
suspend
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
auto
suspend
(
std
::
coroutine_handle
<>
coroutine
)
noexcept
{
{
auto
deque
=
_deque
.
load
();
auto
deque
=
_deque
.
load
();
...
@@ -91,24 +108,23 @@ namespace typon
...
@@ -91,24 +108,23 @@ namespace typon
}
}
}
}
void
add
(
Deque
*
deque
)
noexcept
void
push
(
Continuation
task
)
noexcept
{
{
std
::
lock_guard
lock
(
_mutex
);
_deque
.
load
()
->
push
(
task
);
_pool
.
push_back
(
deque
);
}
}
bool
try_add
(
Deque
*
deque
)
noexcept
bool
pop
(
)
noexcept
{
{
if
(
!
_mutex
.
try_lock
())
Deque
*
deque
=
_deque
.
load
();
bool
result
=
deque
->
pop
();
if
(
auto
garbage
=
deque
->
reclaim
())
{
{
return
false
;
_gc
->
retire
(
garbage
)
;
}
}
std
::
lock_guard
lock
(
_mutex
,
std
::
adopt_lock
);
return
result
;
_pool
.
push_back
(
deque
);
return
true
;
}
}
Work
try_
steal
()
noexcept
Work
steal
()
noexcept
{
{
if
(
!
_mutex
.
try_lock
())
if
(
!
_mutex
.
try_lock
())
{
{
...
...
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