summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Refcountable.cpp
blob: 29f2061e5ba700d04d68f5079811a263eef14b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// $Id$

#include "Refcountable.h"
#include "tao/debug.h"
#include "ace/Log_Msg.h"
#include "ace/Guard_T.h"

ACE_RCSID(Notify, TAO_Notify_Refcountable, "$Id$")

TAO_Notify_Refcountable::TAO_Notify_Refcountable (void)
{
}

TAO_Notify_Refcountable::~TAO_Notify_Refcountable ()
{
  Counter refcount = this->refcount_.value();
  if ( refcount != 0 )
  {
    ACE_ERROR ((LM_ERROR,"ERROR: object:%x delete with non-zero refcount = %d\n", this, refcount ));
    ACE_ASSERT( refcount == 0 );
  }
}

CORBA::ULong
TAO_Notify_Refcountable::_incr_refcnt (void)
{
  Counter refcount = ++this->refcount_;
  if (TAO_debug_level > 1 )
  {
    ACE_DEBUG ((LM_DEBUG,"object:%x incr refcount = %d\n", this, refcount ));
  }
  return static_cast< CORBA::ULong >( refcount );
}

CORBA::ULong
TAO_Notify_Refcountable::_decr_refcnt (void)
{
  Counter refcount = --this->refcount_;

    if (TAO_debug_level > 1 )
  {
    ACE_DEBUG ((LM_DEBUG,"object:%x  decr refcount = %d\n", this, refcount ));
  }

  // If error
  if ( refcount < 0 )
  {
    ACE_ERROR ((LM_ERROR,"ERROR: object:%x _decr_refcnt (%d < 0)\n", this, refcount ));
    ACE_ASSERT( refcount >= 0 );
  }

  // Release if count is zero
  else if ( refcount == 0 )
  {
  this->release ();
  }

  return static_cast< CORBA::ULong >( refcount );
}