Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / GUIResource_Factory.cpp
blob18e9854bf0dbaa5c5f5442f2dfc16cf47be16707
1 #include "tao/GUIResource_Factory.h"
2 #include "ace/Reactor.h"
3 #include "ace/Guard_T.h"
4 #include "tao/debug.h"
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 namespace TAO
10 GUIResource_Factory::GUIResource_Factory ()
11 : dynamically_allocated_reactor_ (false)
15 GUIResource_Factory::~GUIResource_Factory ()
19 ACE_Reactor *
20 GUIResource_Factory::get_reactor ()
22 // @@Marek, do we need a lock here??
23 // @Bala, I suppose we don't need locking for any
24 // reasonable use case as this
25 // factory is intended to be a variable in TSS.
26 // I can imagine that someone may try to use it in distinct
27 // threads, though I do not know
28 // what for. Nevertheless, just for a case I sync the creation of reactor.
29 // I think, that double checked locking is
30 // not necessary, because the performance is not an issue here.
31 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, nullptr);
33 ACE_Reactor *reactor = nullptr;
34 ACE_NEW_RETURN (reactor,
35 ACE_Reactor (this->reactor_impl (), 1),
36 nullptr);
38 if (reactor->initialized () == 0)
40 delete reactor;
41 reactor = nullptr;
43 else
44 this->dynamically_allocated_reactor_ = true;
46 return reactor;
49 void
50 GUIResource_Factory::reclaim_reactor (ACE_Reactor *reactor)
52 ACE_GUARD ( TAO_SYNCH_MUTEX, ace_mon, this->lock_ );
54 if (this->dynamically_allocated_reactor_)
55 delete reactor;
59 TAO_END_VERSIONED_NAMESPACE_DECL