Skip to content

Commit

Permalink
Use std::unique_ptr with a custom deleter for TAO_ORB_Core_Auto_Ptr
Browse files Browse the repository at this point in the history
    * TAO/tao/ORB_Core_Auto_Ptr.inl:
      Deleted.

    * TAO/tao/Collocated_Invocation.cpp:
    * TAO/tao/ORB_Core.cpp:
    * TAO/tao/ORB_Core_Auto_Ptr.cpp:
    * TAO/tao/ORB_Core_Auto_Ptr.h:
    * TAO/tests/Bug_2084_Regression/EventNode.cpp:
    * TAO/tests/Bug_2084_Regression/Hello.cpp:
    * TAO/tests/COIOP/Hello.cpp:
    * TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.cpp:
    * TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.cpp:
    * TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.cpp:
    * TAO/tests/Collocated_NoColl/Hello.cpp:
    * TAO/tests/Collocation_Exception_Test/Hello.cpp:
    * TAO/tests/Collocation_Oneway_Tests/Hello.cpp:
    * TAO/tests/Collocation_Tests/Hello.cpp:
    * TAO/tests/DII_Collocation_Tests/oneway/Hello.cpp:
    * TAO/tests/DII_Collocation_Tests/twoway/Hello.cpp:
  • Loading branch information
jwillemsen committed Sep 5, 2023
1 parent 243d7b1 commit 800a332
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 133 deletions.
4 changes: 1 addition & 3 deletions TAO/tao/Collocated_Invocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ namespace TAO
orb_core->_incr_refcnt ();
TAO_ORB_Core_Auto_Ptr my_orb_core (orb_core);

dispatcher->dispatch (orb_core,
request,
this->forwarded_to_.out ());
dispatcher->dispatch (orb_core, request, this->forwarded_to_.out ());

if (request.is_forwarded ())
{
Expand Down
9 changes: 3 additions & 6 deletions TAO/tao/ORB_Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2089,8 +2089,7 @@ TAO_ORB_Core::create_object (TAO_Stub *stub)
if (this->is_collocation_enabled (other_core, mprofile))
{
other_core->_incr_refcnt();
TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
collocated_orb_core = tmp_auto_ptr;
collocated_orb_core.reset(other_core);
break;
}
}
Expand Down Expand Up @@ -2154,12 +2153,10 @@ TAO_ORB_Core::initialize_object_i (TAO_Stub *stub, const TAO_MProfile &mprofile)
{
TAO_ORB_Core * const other_core = (*i).second.core ();

if (this->is_collocation_enabled (other_core,
mprofile))
if (this->is_collocation_enabled (other_core, mprofile))
{
other_core->_incr_refcnt ();
TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
collocated_orb_core = tmp_auto_ptr;
collocated_orb_core.reset(other_core);
break;
}
}
Expand Down
22 changes: 2 additions & 20 deletions TAO/tao/ORB_Core_Auto_Ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@
#include "tao/ORB_Core_Auto_Ptr.h"
#include "tao/ORB_Core.h"

#if !defined (__ACE_INLINE__)
# include "tao/ORB_Core_Auto_Ptr.inl"
#endif /* !__ACE_INLINE */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_ORB_Core_Auto_Ptr::~TAO_ORB_Core_Auto_Ptr ()
void TAO_ORB_Core_Decr_Refcnt::operator()(TAO_ORB_Core* core) const
{
if (this->get () != nullptr)
{
this->get ()->_decr_refcnt ();
}
}

void
TAO_ORB_Core_Auto_Ptr::reset (TAO_ORB_Core *p)
{
if (this->get () != p && this->get () != nullptr)
{
this->get ()->_decr_refcnt ();
}

this->p_ = p;
if (core) core->_decr_refcnt();
}

TAO_END_VERSIONED_NAMESPACE_DECL
46 changes: 10 additions & 36 deletions TAO/tao/ORB_Core_Auto_Ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,27 @@
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include /**/ "tao/Versioned_Namespace.h"
#include <memory>

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

class TAO_ORB_Core;

/**
* @class TAO_ORB_Core_Auto_Ptr
*
* @brief Define a TAO_ORB_Core auto_ptr class.
*
* This class is used as an aid to make ORB initialization exception
* safe. It ensures that the ORB core is deallocated through its
* reference counting mechanism if an exception is thrown.
* Custom deleter to decrement the refcount when called
*/
class TAO_Export TAO_ORB_Core_Auto_Ptr
struct TAO_Export TAO_ORB_Core_Decr_Refcnt
{
public:
/**
* @name Initialization and termination methods
*/
//@{
explicit TAO_ORB_Core_Auto_Ptr (TAO_ORB_Core *p = 0);
TAO_ORB_Core_Auto_Ptr (TAO_ORB_Core_Auto_Ptr &ap);
TAO_ORB_Core_Auto_Ptr &operator= (TAO_ORB_Core_Auto_Ptr &rhs);
~TAO_ORB_Core_Auto_Ptr ();
//@}

/**
* @name Accessor methods.
*/
//@{
TAO_ORB_Core &operator *() const;
TAO_ORB_Core *get () const;
TAO_ORB_Core *release ();
void reset (TAO_ORB_Core *p = 0);
TAO_ORB_Core *operator-> () const;
//@}

protected:
TAO_ORB_Core *p_;
void operator()(TAO_ORB_Core* core) const;
};

TAO_END_VERSIONED_NAMESPACE_DECL
/**
* TAO_ORB_Core_Auto_Ptr will decrement the refcount when going our of scope
* using std::unique_ptr and a custom deleter
*/
using TAO_ORB_Core_Auto_Ptr = std::unique_ptr<TAO_ORB_Core, TAO_ORB_Core_Decr_Refcnt>;

#if defined (__ACE_INLINE__)
# include "tao/ORB_Core_Auto_Ptr.inl"
#endif /* __ACE_INLINE__ */
TAO_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"

Expand Down
56 changes: 0 additions & 56 deletions TAO/tao/ORB_Core_Auto_Ptr.inl

This file was deleted.

2 changes: 1 addition & 1 deletion TAO/tests/Bug_2084_Regression/EventNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void EventNode::registerHello (::Test::Hello_ptr h)
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Bug_2084_Regression/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Hello::get_string (::Test::ThreadId caller_threadid)
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/COIOP/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocated_Best/Collocated_Best_Direct/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocated_Best/Collocated_Best_NoColl/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocated_Best/Collocated_Best_ThuP/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocated_NoColl/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocation_Exception_Test/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocation_Oneway_Tests/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/Collocation_Tests/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/DII_Collocation_Tests/oneway/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion TAO/tests/DII_Collocation_Tests/twoway/Hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Hello::get_string ()
TAO::ORB_Table::instance ();

TAO_ORB_Core_Auto_Ptr tmp (orb_table->find ("server_orb"));
if (tmp.get () == 0)
if (tmp.get () == nullptr)
{
// We are running on a single ORB and this is an error.
ACE_ERROR ((LM_ERROR,
Expand Down

0 comments on commit 800a332

Please sign in to comment.