1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/kernel/activity/ActivityImpl.hpp"
7 #include "src/simix/smx_private.hpp"
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
15 ActivityImpl::~ActivityImpl()
18 XBT_DEBUG("Destroy activity %p", this);
21 void ActivityImpl::register_simcall(smx_simcall_t simcall)
23 simcalls_.push_back(simcall);
24 simcall->issuer_->waiting_synchro = this;
27 void ActivityImpl::clean_action()
30 surf_action_->unref();
31 surf_action_ = nullptr;
35 double ActivityImpl::get_remaining() const
37 return surf_action_ ? surf_action_->get_remains() : 0;
40 bool ActivityImpl::test()
42 if (state_ != State::WAITING && state_ != State::RUNNING) {
49 void ActivityImpl::suspend()
51 if (surf_action_ == nullptr)
53 XBT_VERB("This activity is suspended (remain: %f)", surf_action_->get_remains());
54 surf_action_->suspend();
58 void ActivityImpl::resume()
60 if (surf_action_ == nullptr)
62 XBT_VERB("This activity is resumed (remain: %f)", surf_action_->get_remains());
63 surf_action_->resume();
67 void ActivityImpl::cancel()
69 XBT_VERB("Activity %p is canceled", this);
70 if (surf_action_ != nullptr)
71 surf_action_->cancel();
72 state_ = State::CANCELED;
75 // boost::intrusive_ptr<Activity> support:
76 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
78 activity->refcount_.fetch_add(1, std::memory_order_relaxed);
81 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
83 if (activity->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
84 std::atomic_thread_fence(std::memory_order_acquire);
88 xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_resumed;
89 xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_suspended;
92 } // namespace simgrid::kernel::activity::