Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / performance-tests / CSD_Strategy / TestInf / AppShutdown.cpp
blob0491e01babab4bbcb2a78f82864f75e47f867c5a
1 #include "AppShutdown.h"
2 #include "TestAppExceptionC.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_unistd.h"
6 AppShutdown::AppShutdown()
7 : num_clients_(0),
8 num_clients_shutdown_(0)
13 AppShutdown::~AppShutdown()
18 void
19 AppShutdown::init(CORBA::ORB_ptr orb,
20 unsigned num_clients)
22 if ((!CORBA::is_nil(this->orb_.in())) ||
23 (CORBA::is_nil(orb)) ||
24 (num_clients == 0))
26 // Already init()'ed, or bad argument values.
27 throw TestAppException();
29 else
31 this->orb_ = CORBA::ORB::_duplicate(orb);
32 this->num_clients_ = num_clients;
33 this->num_clients_shutdown_ = 0;
38 void
39 AppShutdown::wait ()
41 this->orb_shutdown_task_.wait();
45 void
46 AppShutdown::client_done()
48 if ((this->num_clients_ == 0) || (CORBA::is_nil(this->orb_.in())))
50 ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown was never initialized.\n"));
51 return;
54 unsigned cur_shutdown;
57 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);
58 cur_shutdown = ++this->num_clients_shutdown_;
61 if (cur_shutdown == this->num_clients_)
63 // Sleep for one second before shutting down the ORB. This
64 // is a poor-man version of "wait until the CSD request queue drains".
65 ACE_OS::sleep(1);
66 this->orb_shutdown_task_.orb(this->orb_.in());
67 if (this->orb_shutdown_task_.open(0) != 0)
69 ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown failed to create orb "\
70 "shutdown thread.\n"));
71 return;
77 AppShutdown*
78 AppShutdown::instance ()
80 static AppShutdown app_shutdown;
81 return &app_shutdown;