Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lehrstuhl für Informatik 4 (Systemsoftware)
manycore
emper
Commits
99ace7e5
Commit
99ace7e5
authored
3 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[Actor] allow multiple Ts to be told to an Actor
parent
fd5cfe5e
No related branches found
No related tags found
1 merge request
!230
[IO] Implement configurable "simple architecture"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
emper/Actor.hpp
+12
-3
12 additions, 3 deletions
emper/Actor.hpp
emper/UnboundedBlockingMpscQueue.hpp
+21
-0
21 additions, 0 deletions
emper/UnboundedBlockingMpscQueue.hpp
tests/TellActorFromAnywhereTest.cpp
+2
-1
2 additions, 1 deletion
tests/TellActorFromAnywhereTest.cpp
with
35 additions
and
4 deletions
emper/Actor.hpp
+
12
−
3
View file @
99ace7e5
...
...
@@ -9,6 +9,7 @@
#include
"Fiber.hpp"
#include
"UnboundedBlockingMpscQueue.hpp"
#include
"emper.hpp"
#include
"io/Future.hpp"
template
<
typename
T
>
class
Actor
{
...
...
@@ -19,8 +20,10 @@ class Actor {
Running
,
};
protected
:
Runtime
&
runtime
;
private
:
std
::
atomic
<
State
>
state
=
{
Stopped
};
UnboundedBlockingMpscQueue
<
T
>
queue
;
...
...
@@ -73,9 +76,15 @@ class Actor {
void
startFromAnywhere
()
{
start
<
CallerEnvironment
::
ANYWHERE
>
();
}
void
tell
(
T
t
)
{
queue
.
put
(
t
);
}
template
<
CallerEnvironment
callerEnvironment
=
CallerEnvironment
::
EMPER
>
void
tell
(
T
t
)
{
queue
.
template
put
<
callerEnvironment
>(
t
);
}
void
tellFromAnywhere
(
T
t
)
{
queue
.
putFromAnywhere
(
t
);
}
template
<
CallerEnvironment
callerEnvironment
=
CallerEnvironment
::
EMPER
,
typename
InputIt
>
void
tell
(
InputIt
begin
,
InputIt
end
)
{
queue
.
template
put
<
callerEnvironment
>(
begin
,
end
);
}
auto
pendingMailboxItems
()
->
size_t
{
return
queue
.
size
();
}
...
...
@@ -86,7 +95,7 @@ class Actor {
if
constexpr
(
emper
::
IO
)
{
emper
::
sleep
(
1
);
}
else
{
emper
::
yield
();
runtime
.
yield
();
}
// TODO: The suppressed linter error below may be a false positive
// reported by clang-tidy.
...
...
This diff is collapsed.
Click to expand it.
emper/UnboundedBlockingMpscQueue.hpp
+
21
−
0
View file @
99ace7e5
...
...
@@ -60,8 +60,29 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> {
}
}
template
<
CallerEnvironment
callerEnvironment
=
CallerEnvironment
::
EMPER
,
typename
InputIt
>
void
put
(
InputIt
begin
,
InputIt
end
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
queueMutex
);
for
(
InputIt
cur
=
begin
;
cur
!=
end
;
++
cur
)
{
mpscQueue
.
push
(
*
cur
);
}
}
// Micro optimization, see if there is a blocked context
// before performing the atomic exchange operation.
if
(
blockedContext
!=
nullptr
)
{
tryToWakeupBlockedContext
<
callerEnvironment
>
();
}
}
void
putFromAnywhere
(
T
t
)
{
put
<
CallerEnvironment
::
ANYWHERE
>
(
t
);
}
template
<
typename
InputIt
>
void
putFromAnywhere
(
InputIt
begin
,
InputIt
end
)
{
put
<
CallerEnvironment
::
ANYWHERE
>
(
begin
,
end
);
}
auto
get
(
const
std
::
function
<
void
(
void
)
>&
postRetrieve
)
->
T
{
tPopped
=
false
;
tryToGetElement
(
postRetrieve
);
...
...
This diff is collapsed.
Click to expand it.
tests/TellActorFromAnywhereTest.cpp
+
2
−
1
View file @
99ace7e5
...
...
@@ -4,6 +4,7 @@
#include
"Actor.hpp"
#include
"BinaryPrivateSemaphore.hpp"
#include
"CallerEnvironment.hpp"
#include
"emper-common.h"
class
SignallingActor
:
public
Actor
<
unsigned
int
>
{
...
...
@@ -25,7 +26,7 @@ void emperTest() {
signallingActor
->
start
();
// TODO: Use std::jthread once EMPER uses C++20.
std
::
thread
signallingThread
([
&
]
{
signallingActor
->
tell
FromAnywhere
(
1
);
});
std
::
thread
signallingThread
([
&
]
{
signallingActor
->
tell
<
CallerEnvironment
::
ANYWHERE
>
(
1
);
});
bps
->
wait
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment