Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a2cdff3885302ef7190a43d9587a9de9104fa6b3
[simgrid.git] / src / kernel / activity / ActivityImpl.cpp
1 /* Copyright (c) 2007-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 "src/kernel/activity/ActivityImpl.hpp"
7
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
9
10 namespace simgrid {
11 namespace kernel {
12 namespace activity {
13
14 void ActivityImpl::suspend()
15 {
16   if (surf_action_ == nullptr)
17     return;
18   XBT_VERB("This activity is suspended (remain: %f)", surf_action_->get_remains());
19   surf_action_->suspend();
20   on_suspended(this);
21 }
22
23 void ActivityImpl::resume()
24 {
25   if (surf_action_ == nullptr)
26     return;
27   XBT_VERB("This activity is resumed (remain: %f)", surf_action_->get_remains());
28   surf_action_->resume();
29   on_resumed(this);
30 }
31
32 void ActivityImpl::set_category(std::string category)
33 {
34   if (surf_action_)
35     surf_action_->set_category(category);
36 }
37
38 // boost::intrusive_ptr<Activity> support:
39 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
40 {
41   activity->refcount_.fetch_add(1, std::memory_order_relaxed);
42 }
43
44 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
45 {
46   if (activity->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
47     std::atomic_thread_fence(std::memory_order_acquire);
48     delete activity;
49   }
50 }
51 xbt::signal<void(ActivityImplPtr)> ActivityImpl::on_resumed;
52 xbt::signal<void(ActivityImplPtr)> ActivityImpl::on_suspended;
53 }
54 }
55 } // namespace simgrid::kernel::activity::