1 /* Copyright (c) 2007-2019. 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"
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
14 ActivityImpl::~ActivityImpl()
17 XBT_DEBUG("Destroy activity %p", this);
20 void ActivityImpl::clean_action()
23 surf_action_->unref();
24 surf_action_ = nullptr;
28 double ActivityImpl::get_remaining() const
30 return surf_action_ ? surf_action_->get_remains() : 0;
33 void ActivityImpl::suspend()
35 if (surf_action_ == nullptr)
37 XBT_VERB("This activity is suspended (remain: %f)", surf_action_->get_remains());
38 surf_action_->suspend();
42 void ActivityImpl::resume()
44 if (surf_action_ == nullptr)
46 XBT_VERB("This activity is resumed (remain: %f)", surf_action_->get_remains());
47 surf_action_->resume();
51 void ActivityImpl::cancel()
53 XBT_VERB("Activity %p is canceled", this);
54 if (surf_action_ != nullptr)
55 surf_action_->cancel();
56 state_ = SIMIX_CANCELED;
59 // boost::intrusive_ptr<Activity> support:
60 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
62 activity->refcount_.fetch_add(1, std::memory_order_relaxed);
65 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
67 if (activity->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
68 std::atomic_thread_fence(std::memory_order_acquire);
72 xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_resumed;
73 xbt::signal<void(ActivityImpl const&)> ActivityImpl::on_suspended;
76 } // namespace simgrid::kernel::activity::