Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further WIP on the ActivityImplPtr feature. Now it compiles (but fails)
[simgrid.git] / src / kernel / activity / ActivityImpl.cpp
1 /* Copyright (c) 2007-2017. 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_CATEGORY(simix_network);
9
10 namespace simgrid {
11 namespace kernel {
12 namespace activity {
13
14 ActivityImpl::ActivityImpl()  = default;
15 ActivityImpl::~ActivityImpl() = default;
16
17 void ActivityImpl::ref()
18 {
19   xbt_assert(refcount_ != 0);
20   refcount_++;
21   XBT_CDEBUG(simix_network, "%p->refcount++ ~> %d", this, (int)refcount_);
22   if (XBT_LOG_ISENABLED(simix_network, xbt_log_priority_trace))
23     xbt_backtrace_display_current();
24 }
25
26 void ActivityImpl::unref()
27 {
28   XBT_CDEBUG(simix_network, "%p->refcount-- ~> %d", this, ((int)refcount_) - 1);
29   xbt_assert(refcount_ > 0,
30              "This activity has a negative refcount! You can only call test() or wait() once per activity.");
31   refcount_--;
32   if (XBT_LOG_ISENABLED(simix_network, xbt_log_priority_trace))
33     xbt_backtrace_display_current();
34   if (refcount_ <= 0)
35     delete this;
36 }
37
38 // boost::intrusive_ptr<Activity> support:
39 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
40 {
41   activity->ref();
42 }
43
44 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
45 {
46   activity->unref();
47 }
48 }
49 }
50 } // namespace simgrid::kernel::activity::