summaryrefslogtreecommitdiff
path: root/TAO/tao/GUIResource_Factory.cpp
blob: 33695590b87b0ceab7a507ce9b950b18b5b20e92 (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 "tao/GUIResource_Factory.h"
#include "ace/Reactor.h"
#include "tao/debug.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  GUIResource_Factory::GUIResource_Factory (void)
    : dynamically_allocated_reactor_ (false)
  {
  }

  GUIResource_Factory::~GUIResource_Factory (void)
  {
  }

  ACE_Reactor *
  GUIResource_Factory::get_reactor (void)
  {
    // @@Marek, do we need a lock here??
    // @Bala, I suppose we don't need locking for any
    //   reasonable use case as this
    //   factory is intended to be a variable in TSS.
    //   I can imagine that    someone may try to use it in distinct
    //   threads, though I do not know
    //   what for. Nevertheless, just for a case  I sync the creation of reactor.
    //   I think, that double checked locking is
    //   not necessary, because the performance is not an issue here.
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);

    ACE_Reactor *reactor = 0;
    ACE_NEW_RETURN (reactor,
                    ACE_Reactor (this->reactor_impl (), 1),
                    0);

    if (reactor->initialized () == 0)
    {
      delete reactor;
      reactor = 0;
    }
    else
      this->dynamically_allocated_reactor_ = true;

    return reactor;
  }

  void
  GUIResource_Factory::reclaim_reactor (ACE_Reactor *reactor)
  {
    ACE_GUARD ( TAO_SYNCH_MUTEX, ace_mon, this->lock_ );

    if (this->dynamically_allocated_reactor_)
      delete reactor;
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL