Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-concurrency
Commits
085ba7a2
Commit
085ba7a2
authored
Jun 03, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve worker.hpp
parent
71d69433
Changes
1
Show 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 @
085ba7a2
...
...
@@ -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
active
=
_active
.
load
();
auto
total
=
_pool
.
size
()
+
bool
(
active
);
if
(
total
==
0
)
{
auto
index
=
fdt
::
random
::
random64
()
%
(
_pool
.
size
()
+
1
);
return
{};
}
auto
index
=
fdt
::
random
::
random64
()
%
(
_pool
.
size
()
+
bool
(
active
));
if
(
index
==
_pool
.
size
())
{
if
(
auto
active
=
_active
.
load
())
{
if
(
auto
task
=
active
->
steal
())
{
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