Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanups after introduction of Exec::wait_for(timeout)
[simgrid.git] / src / s4u / s4u_Actor.cpp
1 /* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/Exception.hpp"
7 #include "simgrid/actor.h"
8 #include "simgrid/modelchecker.h"
9 #include "simgrid/s4u/Actor.hpp"
10 #include "simgrid/s4u/Exec.hpp"
11 #include "simgrid/s4u/Host.hpp"
12 #include "simgrid/s4u/VirtualMachine.hpp"
13 #include "src/include/mc/mc.h"
14 #include "src/kernel/activity/ExecImpl.hpp"
15 #include "src/mc/mc_replay.hpp"
16 #include "src/surf/HostImpl.hpp"
17
18 #include <algorithm>
19 #include <sstream>
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_actor, s4u, "S4U actors");
22
23 namespace simgrid {
24 namespace s4u {
25
26 xbt::signal<void(Actor&)> s4u::Actor::on_creation;
27 xbt::signal<void(Actor const&)> s4u::Actor::on_suspend;
28 xbt::signal<void(Actor const&)> s4u::Actor::on_resume;
29 xbt::signal<void(Actor const&)> s4u::Actor::on_sleep;
30 xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
31 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start; // deprecated
32 xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;   // deprecated
33 xbt::signal<void(Actor const&, Host const& previous_location)> s4u::Actor::on_host_change;
34 xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
35 xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
36
37 // ***** Actor creation *****
38 Actor* Actor::self()
39 {
40   kernel::context::Context* self_context = kernel::context::Context::self();
41   if (self_context == nullptr)
42     return nullptr;
43
44   return self_context->get_actor()->ciface();
45 }
46
47 ActorPtr Actor::init(const std::string& name, s4u::Host* host)
48 {
49   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
50   kernel::actor::ActorImpl* actor =
51       kernel::actor::simcall([self, &name, host] { return self->init(name, host).get(); });
52   return actor->iface();
53 }
54
55 ActorPtr Actor::start(const std::function<void()>& code)
56 {
57   simgrid::kernel::actor::simcall([this, &code] { pimpl_->start(code); });
58   return this;
59 }
60
61 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function<void()>& code)
62 {
63   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
64   kernel::actor::ActorImpl* actor =
65       kernel::actor::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); });
66
67   return actor->iface();
68 }
69
70 ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function,
71                        std::vector<std::string> args)
72 {
73   simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function);
74   return create(name, host, factory(std::move(args)));
75 }
76
77 void intrusive_ptr_add_ref(Actor* actor)
78 {
79   intrusive_ptr_add_ref(actor->pimpl_);
80 }
81 void intrusive_ptr_release(Actor* actor)
82 {
83   intrusive_ptr_release(actor->pimpl_);
84 }
85 int Actor::get_refcount()
86 {
87   return pimpl_->get_refcount();
88 }
89
90 // ***** Actor methods *****
91
92 void Actor::join()
93 {
94   join(-1);
95 }
96
97 void Actor::join(double timeout)
98 {
99   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
100   kernel::actor::ActorImpl* target = pimpl_;
101   kernel::actor::simcall_blocking<void>([issuer, target, timeout] {
102     if (target->finished_) {
103       // The joined process is already finished, just wake up the issuer right away
104       issuer->simcall_answer();
105     } else {
106       smx_activity_t sync = issuer->join(target, timeout);
107       sync->register_simcall(&issuer->simcall);
108     }
109   });
110 }
111
112 void Actor::set_auto_restart(bool autorestart)
113 {
114   kernel::actor::simcall([this, autorestart]() {
115     xbt_assert(autorestart && not pimpl_->has_to_auto_restart()); // FIXME: handle all cases
116     pimpl_->set_auto_restart(autorestart);
117
118     kernel::actor::ProcessArg* arg = new kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_);
119     XBT_DEBUG("Adding %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname());
120     pimpl_->get_host()->pimpl_->add_actor_at_boot(arg);
121   });
122 }
123
124 void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun) const
125 {
126   kernel::actor::simcall([this, &fun] { pimpl_->on_exit->emplace_back(fun); });
127 }
128
129 void Actor::set_host(Host* new_host)
130 {
131   if (s4u::Actor::on_migration_start.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
132     static bool already_warned = false;
133     if (not already_warned) {
134       XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_start. This will be removed "
135                "in v3.29");
136       already_warned = true;
137     }
138     s4u::Actor::on_migration_start(*this);
139   }
140
141   auto* previous_location = get_host();
142
143   kernel::actor::simcall([this, new_host]() {
144     if (pimpl_->waiting_synchro != nullptr) {
145       // The actor is blocked on an activity. If it's an exec, migrate it too.
146       // FIXME: implement the migration of other kinds of activities
147       kernel::activity::ExecImplPtr exec =
148           boost::dynamic_pointer_cast<kernel::activity::ExecImpl>(pimpl_->waiting_synchro);
149       xbt_assert(exec.get() != nullptr, "We can only migrate blocked actors when they are blocked on executions.");
150       exec->migrate(new_host);
151     }
152     this->pimpl_->set_host(new_host);
153   });
154
155   if (s4u::Actor::on_migration_end.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
156     static bool already_warned = false;
157     if (not already_warned) {
158       XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_end. This will be removed in "
159                "v3.29");
160       already_warned = true;
161     }
162     s4u::Actor::on_migration_end(*this);
163   }
164
165   s4u::Actor::on_host_change(*this, *previous_location);
166 }
167
168 s4u::Host* Actor::get_host() const
169 {
170   return this->pimpl_->get_host();
171 }
172
173 void Actor::daemonize()
174 {
175   kernel::actor::simcall([this]() { pimpl_->daemonize(); });
176 }
177
178 bool Actor::is_daemon() const
179 {
180   return this->pimpl_->is_daemon();
181 }
182
183 const simgrid::xbt::string& Actor::get_name() const
184 {
185   return this->pimpl_->get_name();
186 }
187
188 const char* Actor::get_cname() const
189 {
190   return this->pimpl_->get_cname();
191 }
192
193 aid_t Actor::get_pid() const
194 {
195   return this->pimpl_->get_pid();
196 }
197
198 aid_t Actor::get_ppid() const
199 {
200   return this->pimpl_->get_ppid();
201 }
202
203 void Actor::suspend()
204 {
205   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
206   kernel::actor::ActorImpl* target = pimpl_;
207   s4u::Actor::on_suspend(*this);
208   kernel::actor::simcall_blocking<void>([issuer, target]() {
209     target->suspend();
210     if (target != issuer) {
211       /* If we are suspending ourselves, then just do not finish the simcall now */
212       issuer->simcall_answer();
213     }
214   });
215 }
216
217 void Actor::resume()
218 {
219   kernel::actor::simcall([this] { pimpl_->resume(); });
220   s4u::Actor::on_resume(*this);
221 }
222
223 bool Actor::is_suspended()
224 {
225   return pimpl_->is_suspended();
226 }
227
228 void Actor::set_kill_time(double kill_time)
229 {
230   kernel::actor::simcall([this, kill_time] { pimpl_->set_kill_time(kill_time); });
231 }
232
233 /** @brief Get the kill time of an actor(or 0 if unset). */
234 double Actor::get_kill_time()
235 {
236   return pimpl_->get_kill_time();
237 }
238
239 void Actor::kill()
240 {
241   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
242   kernel::actor::simcall([this, self] { self->kill(pimpl_); });
243 }
244
245 // ***** Static functions *****
246
247 ActorPtr Actor::by_pid(aid_t pid)
248 {
249   kernel::actor::ActorImpl* actor = SIMIX_process_from_PID(pid);
250   if (actor != nullptr)
251     return actor->iface();
252   else
253     return ActorPtr();
254 }
255
256 void Actor::kill_all()
257 {
258   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
259   kernel::actor::simcall([self] { self->kill_all(); });
260 }
261
262 const std::unordered_map<std::string, std::string>* Actor::get_properties() const
263 {
264   return pimpl_->get_properties();
265 }
266
267 /** Retrieve the property value (or nullptr if not set) */
268 const char* Actor::get_property(const std::string& key) const
269 {
270   return pimpl_->get_property(key);
271 }
272
273 void Actor::set_property(const std::string& key, const std::string& value)
274 {
275   kernel::actor::simcall([this, &key, &value] { pimpl_->set_property(key, value); });
276 }
277
278 Actor* Actor::restart()
279 {
280   return kernel::actor::simcall([this]() { return pimpl_->restart(); });
281 }
282
283 // ***** this_actor *****
284
285 namespace this_actor {
286
287 /** Returns true if run from the kernel mode, and false if run from a real actor
288  *
289  * Everything that is run out of any actor (simulation setup before the engine is run,
290  * computing the model evolutions as a result to the actors' action, etc) is run in
291  * kernel mode, just as in any operating systems.
292  *
293  * In SimGrid, the actor in charge of doing the stuff in kernel mode is called Maestro,
294  * because it is the one scheduling when the others should move or wait.
295  */
296 bool is_maestro()
297 {
298   return SIMIX_is_maestro();
299 }
300
301 void sleep_for(double duration)
302 {
303   xbt_assert(std::isfinite(duration), "duration is not finite!");
304
305   if (duration > 0) {
306     kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
307     Actor::on_sleep(*issuer->ciface());
308
309     kernel::actor::simcall_blocking<void>([issuer, duration]() {
310       if (MC_is_active() || MC_record_replay_is_active()) {
311         MC_process_clock_add(issuer, duration);
312         issuer->simcall_answer();
313         return;
314       }
315       smx_activity_t sync = issuer->sleep(duration);
316       sync->register_simcall(&issuer->simcall);
317     });
318
319     Actor::on_wake_up(*issuer->ciface());
320   }
321 }
322
323 void yield()
324 {
325   kernel::actor::simcall([] { /* do nothing*/ });
326 }
327
328 XBT_PUBLIC void sleep_until(double wakeup_time)
329 {
330   double now = SIMIX_get_clock();
331   if (wakeup_time > now)
332     sleep_for(wakeup_time - now);
333 }
334
335 void execute(double flops)
336 {
337   execute(flops, 1.0 /* priority */);
338 }
339
340 void execute(double flops, double priority)
341 {
342   exec_init(flops)->set_priority(priority)->start()->wait();
343 }
344
345 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
346                       const std::vector<double>& bytes_amounts)
347 {
348   exec_init(hosts, flops_amounts, bytes_amounts)->wait();
349 }
350
351 void parallel_execute(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
352                       const std::vector<double>& bytes_amounts, double timeout) // XBT_ATTRIB_DEPRECATED_v329
353 {
354   exec_init(hosts, flops_amounts, bytes_amounts)->wait_for(timeout);
355 }
356
357 ExecPtr exec_init(double flops_amount)
358 {
359   return ExecPtr(new ExecSeq(get_host(), flops_amount));
360 }
361
362 ExecPtr exec_init(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
363                   const std::vector<double>& bytes_amounts)
364 {
365   xbt_assert(hosts.size() > 0, "Your parallel executions must span over at least one host.");
366   xbt_assert(hosts.size() == flops_amounts.size() || flops_amounts.empty(),
367              "Host count (%zu) does not match flops_amount count (%zu).", hosts.size(), flops_amounts.size());
368   xbt_assert(hosts.size() * hosts.size() == bytes_amounts.size() || bytes_amounts.empty(),
369              "bytes_amounts must be a matrix of size host_count * host_count (%zu*%zu), but it's of size %zu.",
370              hosts.size(), hosts.size(), flops_amounts.size());
371   /* Check that we are not mixing VMs and PMs in the parallel task */
372   bool is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(hosts.front()));
373   xbt_assert(std::all_of(hosts.begin(), hosts.end(),
374                          [is_a_vm](s4u::Host* elm) {
375                            bool tmp_is_a_vm = (nullptr != dynamic_cast<VirtualMachine*>(elm));
376                            return is_a_vm == tmp_is_a_vm;
377                          }),
378              "parallel_execute: mixing VMs and PMs is not supported (yet).");
379   /* checking for infinite values */
380   xbt_assert(std::all_of(flops_amounts.begin(), flops_amounts.end(), [](double elm) { return std::isfinite(elm); }),
381              "flops_amounts comprises infinite values!");
382   xbt_assert(std::all_of(bytes_amounts.begin(), bytes_amounts.end(), [](double elm) { return std::isfinite(elm); }),
383              "flops_amounts comprises infinite values!");
384
385   return ExecPtr(new ExecPar(hosts, flops_amounts, bytes_amounts));
386 }
387
388 ExecPtr exec_async(double flops)
389 {
390   ExecPtr res = exec_init(flops);
391   res->start();
392   return res;
393 }
394
395 aid_t get_pid()
396 {
397   return simgrid::kernel::actor::ActorImpl::self()->get_pid();
398 }
399
400 aid_t get_ppid()
401 {
402   return simgrid::kernel::actor::ActorImpl::self()->get_ppid();
403 }
404
405 std::string get_name()
406 {
407   return simgrid::kernel::actor::ActorImpl::self()->get_name();
408 }
409
410 const char* get_cname()
411 {
412   return simgrid::kernel::actor::ActorImpl::self()->get_cname();
413 }
414
415 Host* get_host()
416 {
417   return simgrid::kernel::actor::ActorImpl::self()->get_host();
418 }
419
420 void suspend()
421 {
422   kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
423   s4u::Actor::on_suspend(*self->ciface());
424   kernel::actor::simcall_blocking<void>([self] { self->suspend(); });
425 }
426
427 void resume()
428 {
429   kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
430   kernel::actor::simcall([self] { self->resume(); });
431   Actor::on_resume(*self->ciface());
432 }
433
434 void exit()
435 {
436   kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
437   simgrid::kernel::actor::simcall([self] { self->exit(); });
438 }
439
440 void on_exit(const std::function<void(bool)>& fun)
441 {
442   simgrid::kernel::actor::ActorImpl::self()->iface()->on_exit(fun);
443 }
444
445 /** @brief Moves the current actor to another host
446  *
447  * @see simgrid::s4u::Actor::migrate() for more information
448  */
449 void set_host(Host* new_host)
450 {
451   simgrid::kernel::actor::ActorImpl::self()->iface()->set_host(new_host);
452 }
453 void migrate(Host* new_host) // deprecated
454 {
455   set_host(new_host);
456 }
457
458 } // namespace this_actor
459 } // namespace s4u
460 } // namespace simgrid
461
462 /* **************************** Public C interface *************************** */
463
464 sg_actor_t sg_actor_init(const char* name, sg_host_t host)
465 {
466   return simgrid::s4u::Actor::init(name, host).get();
467 }
468
469 void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, char** argv)
470 {
471   simgrid::simix::ActorCode function;
472   if (code)
473     function = simgrid::xbt::wrap_main(code, argc, static_cast<const char* const*>(argv));
474   actor->start(std::move(function));
475 }
476
477 /** @ingroup m_actor_management
478  * @brief Returns the process ID of @a actor.
479  *
480  * This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem).
481  */
482 aid_t sg_actor_get_PID(sg_actor_t actor)
483 {
484   /* Do not raise an exception here: this function is called by the logs
485    * and the exceptions, so it would be called back again and again */
486   if (actor == nullptr || actor->get_impl() == nullptr)
487     return 0;
488   return actor->get_pid();
489 }
490
491 /** @ingroup m_actor_management
492  * @brief Returns the process ID of the parent of @a actor.
493  *
494  * This function checks whether @a actor is a valid pointer and return its parent's PID.
495  * Returns -1 if the actor has not been created by any other actor.
496  */
497 aid_t sg_actor_get_PPID(sg_actor_t actor)
498 {
499   return actor->get_ppid();
500 }
501
502 /** @ingroup m_actor_management
503  *
504  * @brief Return a #sg_actor_t given its PID.
505  *
506  * This function search in the list of all the created sg_actor_t for a sg_actor_t  whose PID is equal to @a PID.
507  * If none is found, @c nullptr is returned.
508    Note that the PID are unique in the whole simulation, not only on a given host.
509  */
510 sg_actor_t sg_actor_by_PID(aid_t pid)
511 {
512   return simgrid::s4u::Actor::by_pid(pid).get();
513 }
514
515 /** @ingroup m_actor_management
516  * @brief Return the name of an actor.
517  */
518 const char* sg_actor_get_name(sg_actor_t actor)
519 {
520   return actor->get_cname();
521 }
522
523 sg_host_t sg_actor_get_host(sg_actor_t actor)
524 {
525   return actor->get_host();
526 }
527
528 /** @ingroup m_actor_management
529  * @brief Returns the value of a given actor property
530  *
531  * @param actor an actor
532  * @param name a property name
533  * @return value of a property (or nullptr if the property is not set)
534  */
535 const char* sg_actor_get_property_value(sg_actor_t actor, const char* name)
536 {
537   return actor->get_property(name);
538 }
539
540 /** @ingroup m_actor_management
541  * @brief Return the list of properties
542  *
543  * This function returns all the parameters associated with an actor
544  */
545 xbt_dict_t sg_actor_get_properties(sg_actor_t actor)
546 {
547   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
548   xbt_dict_t as_dict                        = xbt_dict_new_homogeneous(xbt_free_f);
549   const std::unordered_map<std::string, std::string>* props = actor->get_properties();
550   if (props == nullptr)
551     return nullptr;
552   for (auto const& kv : *props) {
553     xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()));
554   }
555   return as_dict;
556 }
557
558 /** @ingroup m_actor_management
559  * @brief Suspend the actor.
560  *
561  * This function suspends the actor by suspending the task on which it was waiting for the completion.
562  */
563 void sg_actor_suspend(sg_actor_t actor)
564 {
565   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
566   actor->suspend();
567 }
568
569 /** @ingroup m_actor_management
570  * @brief Resume a suspended actor.
571  *
572  * This function resumes a suspended actor by resuming the task on which it was waiting for the completion.
573  */
574 void sg_actor_resume(sg_actor_t actor)
575 {
576   xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
577   actor->resume();
578 }
579
580 /** @ingroup m_actor_management
581  * @brief Returns true if the actor is suspended .
582  *
583  * This checks whether an actor is suspended or not by inspecting the task on which it was waiting for the completion.
584  */
585 int sg_actor_is_suspended(sg_actor_t actor)
586 {
587   return actor->is_suspended();
588 }
589
590 /**
591  * @ingroup m_actor_management
592  * @brief Restarts an actor from the beginning.
593  */
594 sg_actor_t sg_actor_restart(sg_actor_t actor)
595 {
596   return actor->restart();
597 }
598
599 /**
600  * @ingroup m_actor_management
601  * @brief Sets the "auto-restart" flag of the actor.
602  * If the flag is set to 1, the actor will be automatically restarted when its host comes back up.
603  */
604 void sg_actor_set_auto_restart(sg_actor_t actor, int auto_restart)
605 {
606   actor->set_auto_restart(auto_restart);
607 }
608
609 /** @ingroup m_actor_management
610  * @brief This actor will be terminated automatically when the last non-daemon actor finishes
611  */
612 void sg_actor_daemonize(sg_actor_t actor)
613 {
614   actor->daemonize();
615 }
616
617 /** @ingroup m_actor_management
618  * @brief Migrates an actor to another location.
619  *
620  * This function changes the value of the #sg_host_t on  which @a actor is running.
621  */
622 void sg_actor_set_host(sg_actor_t actor, sg_host_t host)
623 {
624   actor->set_host(host);
625 }
626 void sg_actor_migrate(sg_actor_t process, sg_host_t host) // deprecated
627 {
628   process->set_host(host);
629 }
630
631 /** @ingroup m_actor_management
632  * @brief Wait for the completion of a #sg_actor_t.
633  *
634  * @param actor the actor to wait for
635  * @param timeout wait until the actor is over, or the timeout expires
636  */
637 void sg_actor_join(sg_actor_t actor, double timeout)
638 {
639   actor->join(timeout);
640 }
641
642 void sg_actor_kill(sg_actor_t actor)
643 {
644   actor->kill();
645 }
646
647 void sg_actor_kill_all()
648 {
649   simgrid::s4u::Actor::kill_all();
650 }
651
652 /** @ingroup m_actor_management
653  * @brief Set the kill time of an actor.
654  *
655  * @param actor an actor
656  * @param kill_time the time when the actor is killed.
657  */
658 void sg_actor_set_kill_time(sg_actor_t actor, double kill_time)
659 {
660   actor->set_kill_time(kill_time);
661 }
662
663 /** Yield the current actor; let the other actors execute first */
664 void sg_actor_yield()
665 {
666   simgrid::s4u::this_actor::yield();
667 }
668
669 void sg_actor_sleep_for(double duration)
670 {
671   simgrid::s4u::this_actor::sleep_for(duration);
672 }
673
674 sg_actor_t sg_actor_attach(const char* name, void* data, sg_host_t host, xbt_dict_t properties)
675 {
676   xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr");
677   std::unordered_map<std::string, std::string> props;
678   xbt_dict_cursor_t cursor = nullptr;
679   char* key;
680   char* value;
681   xbt_dict_foreach (properties, cursor, key, value)
682     props[key] = value;
683   xbt_dict_free(&properties);
684
685   /* Let's create the process: SIMIX may decide to start it right now, even before returning the flow control to us */
686   smx_actor_t actor = nullptr;
687   try {
688     actor = simgrid::kernel::actor::ActorImpl::attach(name, data, host, &props).get();
689   } catch (simgrid::HostFailureException const&) {
690     xbt_die("Could not attach");
691   }
692
693   simgrid::s4u::this_actor::yield();
694   return actor->ciface();
695 }
696
697 void sg_actor_detach()
698 {
699   simgrid::kernel::actor::ActorImpl::detach();
700 }
701
702 aid_t sg_actor_self_get_pid()
703 {
704   return simgrid::s4u::this_actor::get_pid();
705 }
706
707 aid_t sg_actor_self_get_ppid()
708 {
709   return simgrid::s4u::this_actor::get_ppid();
710 }
711
712 const char* sg_actor_self_get_name()
713 {
714   return simgrid::s4u::this_actor::get_cname();
715 }
716
717 void* sg_actor_self_data()
718 {
719   return simgrid::s4u::Actor::self()->get_data();
720 }
721
722 void sg_actor_self_data_set(void* userdata)
723 {
724   simgrid::s4u::Actor::self()->set_data(userdata);
725 }
726
727 sg_actor_t sg_actor_self()
728 {
729   return simgrid::s4u::Actor::self();
730 }
731
732 void sg_actor_self_execute(double flops)
733 {
734   simgrid::s4u::this_actor::execute(flops);
735 }
736
737 /** @brief Take an extra reference on that actor to prevent it to be garbage-collected */
738 void sg_actor_ref(sg_actor_t actor)
739 {
740   intrusive_ptr_add_ref(actor);
741 }
742 /** @brief Release a reference on that actor so that it can get be garbage-collected */
743 void sg_actor_unref(sg_actor_t actor)
744 {
745   intrusive_ptr_release(actor);
746 }
747
748 /** @brief Return the user data of a #sg_actor_t */
749 void* sg_actor_data(const_sg_actor_t actor)
750 {
751   return actor->get_data();
752 }
753 /** @brief Set the user data of a #sg_actor_t */
754 void sg_actor_data_set(sg_actor_t actor, void* userdata)
755 {
756   actor->set_data(userdata);
757 }