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
7b88cc0c
Commit
7b88cc0c
authored
Jun 03, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve worker.hpp
parent
10c41b55
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
25 deletions
+27
-25
rt/include/typon/core/worker.hpp
rt/include/typon/core/worker.hpp
+27
-25
No files found.
rt/include/typon/core/worker.hpp
View file @
7b88cc0c
...
...
@@ -82,6 +82,12 @@ namespace typon
}
}
void
add
(
WorkDeque
*
deque
)
noexcept
{
std
::
lock_guard
lock
(
_mutex
);
_pool
.
push_back
(
deque
);
}
bool
try_add
(
WorkDeque
*
deque
)
noexcept
{
if
(
!
_mutex
.
try_lock
())
...
...
@@ -89,19 +95,8 @@ namespace typon
return
false
;
}
std
::
lock_guard
lock
(
_mutex
,
std
::
adopt_lock
);
unsafe_add
(
deque
);
return
true
;
}
void
add
(
WorkDeque
*
deque
)
noexcept
{
std
::
lock_guard
lock
(
_mutex
);
unsafe_add
(
deque
);
}
void
unsafe_add
(
WorkDeque
*
deque
)
noexcept
{
_pool
.
push_back
(
deque
);
return
true
;
}
Work
try_steal
()
noexcept
...
...
@@ -111,28 +106,35 @@ namespace typon
return
{};
}
std
::
lock_guard
lock
(
_mutex
,
std
::
adopt_lock
);
return
unsafe_steal
();
}
Work
unsafe_steal
()
noexcept
{
auto
index
=
fdt
::
random
::
random64
()
%
(
_pool
.
size
()
+
1
);
auto
active
=
_active
.
load
();
auto
total
=
_pool
.
size
()
+
bool
(
active
);
if
(
total
==
0
)
{
return
{};
}
auto
index
=
fdt
::
random
::
random64
()
%
(
_pool
.
size
()
+
bool
(
active
));
if
(
index
==
_pool
.
size
())
{
if
(
auto
active
=
_active
.
load
())
if
(
auto
task
=
active
->
steal
())
{
if
(
auto
task
=
active
->
steal
())
{
task
->
thefts
()
++
;
return
*
task
;
}
task
->
thefts
()
++
;
return
*
task
;
}
return
{};
}
auto
deque
=
_pool
[
index
];
if
(
!
deque
->
_resumable
.
load
())
{
if
(
auto
task
=
deque
->
steal
())
auto
task
=
deque
->
steal
();
if
(
task
.
get_flags
()
==
fdt
::
lock_free
::
deque
<
Continuation
>::
Resize
)
{
if
(
auto
array
=
deque
->
shrink
())
{
delete
array
;
}
delete
deque
;
}
if
(
task
)
{
task
->
thefts
()
++
;
return
*
task
;
...
...
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