Logo AND Algorithmique Numérique Distribuée

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