Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refcount should be automatic now, and initialized to 0
[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   refcount_--;
31   if (XBT_LOG_ISENABLED(simix_network, xbt_log_priority_trace))
32     xbt_backtrace_display_current();
33   if (refcount_ <= 0)
34     delete this;
35 }
36
37 // boost::intrusive_ptr<Activity> support:
38 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
39 {
40   activity->ref();
41 }
42
43 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
44 {
45   activity->unref();
46 }
47 }
48 }
49 } // namespace simgrid::kernel::activity::