A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
move parts of the kernel to the right subdir
[simgrid.git]
/
src
/
s4u
/
s4u_actor.cpp
diff --git
a/src/s4u/s4u_actor.cpp
b/src/s4u/s4u_actor.cpp
index
35b65f6
..
24a6bb8
100644
(file)
--- a/
src/s4u/s4u_actor.cpp
+++ b/
src/s4u/s4u_actor.cpp
@@
-7,7
+7,7
@@
#include "xbt/log.h"
#include "src/msg/msg_private.h"
#include "xbt/log.h"
#include "src/msg/msg_private.h"
-#include "simgrid/s4u/
a
ctor.hpp"
+#include "simgrid/s4u/
A
ctor.hpp"
#include "simgrid/s4u/comm.hpp"
#include "simgrid/s4u/host.hpp"
#include "simgrid/s4u/mailbox.hpp"
#include "simgrid/s4u/comm.hpp"
#include "simgrid/s4u/host.hpp"
#include "simgrid/s4u/mailbox.hpp"
@@
-19,25
+19,31
@@
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor,"S4U actors");
namespace simgrid {
namespace s4u {
namespace simgrid {
namespace s4u {
-Actor::Actor(const char* name, s4u::Host *host, double killTime, std::function<void()> code)
+// ***** Actor creation *****
+
+ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code)
{
// TODO, when autorestart is used, the std::function is copied so the new
// instance will get a fresh (reinitialized) state. Is this what we want?
{
// TODO, when autorestart is used, the std::function is copied so the new
// instance will get a fresh (reinitialized) state. Is this what we want?
-
this->pimpl_ = SIMIX_process_ref(
simcall_process_create(
+
smx_process_t process =
simcall_process_create(
name, std::move(code), nullptr, host->name().c_str(),
name, std::move(code), nullptr, host->name().c_str(),
- killTime, nullptr, 0));
+ killTime, nullptr, 0);
+ return Ptr(&process->actor());
}
}
-Actor
::
Actor(const char* name, s4u::Host *host, double killTime,
+Actor
Ptr Actor::create
Actor(const char* name, s4u::Host *host, double killTime,
const char* function, std::vector<std::string> args)
{
simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function);
simgrid::simix::ActorCode code = factory(std::move(args));
const char* function, std::vector<std::string> args)
{
simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function);
simgrid::simix::ActorCode code = factory(std::move(args));
-
this->pimpl_ = SIMIX_process_ref(
simcall_process_create(
+
smx_process_t process =
simcall_process_create(
name, std::move(code), nullptr, host->name().c_str(),
name, std::move(code), nullptr, host->name().c_str(),
- killTime, nullptr, 0));
+ killTime, nullptr, 0);
+ return ActorPtr(&process->actor());
}
}
+// ***** Actor methods *****
+
void Actor::join() {
simcall_process_join(pimpl_, -1);
}
void Actor::join() {
simcall_process_join(pimpl_, -1);
}
@@
-77,32
+83,44
@@
void Actor::kill(int pid) {
}
}
}
}
-smx_process_t Actor::getI
nferior
() {
+smx_process_t Actor::getI
mpl
() {
return pimpl_;
}
return pimpl_;
}
-
void Actor::kill() {
simcall_process_kill(pimpl_);
}
void Actor::kill() {
simcall_process_kill(pimpl_);
}
-simgrid::s4u::Actor Actor::forPid(int pid)
+// ***** Static functions *****
+
+ActorPtr Actor::forPid(int pid)
{
{
- // Should we throw if we did not find it?
smx_process_t process = SIMIX_process_from_PID(pid);
smx_process_t process = SIMIX_process_from_PID(pid);
- return simgrid::s4u::Actor(process);
+ if (process != nullptr)
+ return ActorPtr(&process->actor());
+ else
+ return nullptr;
}
}
-// static stuff:
-
void Actor::killAll() {
simcall_process_killall(1);
}
void Actor::killAll() {
simcall_process_killall(1);
}
+// ***** this_actor *****
+
namespace this_actor {
namespace this_actor {
-void sleep(double duration) {
- simcall_process_sleep(duration);
+void sleep_for(double duration)
+{
+ if (duration > 0)
+ simcall_process_sleep(duration);
+}
+
+XBT_PUBLIC(void) sleep_until(double timeout)
+{
+ double now = SIMIX_get_clock();
+ if (timeout > now)
+ simcall_process_sleep(timeout - now);
}
e_smx_state_t execute(double flops) {
}
e_smx_state_t execute(double flops) {
@@
-112,14
+130,14
@@
e_smx_state_t execute(double flops) {
void* recv(Mailbox &chan) {
void *res = nullptr;
void* recv(Mailbox &chan) {
void *res = nullptr;
- Comm c = Comm::recv_init(chan);
+ Comm
&
c = Comm::recv_init(chan);
c.setDstData(&res,sizeof(res));
c.wait();
return res;
}
void send(Mailbox &chan, void *payload, size_t simulatedSize) {
c.setDstData(&res,sizeof(res));
c.wait();
return res;
}
void send(Mailbox &chan, void *payload, size_t simulatedSize) {
- Comm c = Comm::send_init(chan);
+ Comm
&
c = Comm::send_init(chan);
c.setRemains(simulatedSize);
c.setSrcData(payload);
// c.start() is optional.
c.setRemains(simulatedSize);
c.setSrcData(payload);
// c.start() is optional.