Esempio n. 1
0
int
Worker::svc()
{
  {
    ACE_GUARD_RETURN (ACE_Mutex, ace_mon, this->lock_, 0);
    if (this->orb_threads_ > 0)
      {
        --this->orb_threads_;
        hello_->set_callback(this->callback_.in());
        ace_mon.release();
        this->orb_->run();
        return 0;
      }
    else
      ++this->busy_threads_;
  }
  bool excep = false;
  ACE_DEBUG ((LM_DEBUG, "(%t) starting loop\n"));
  for (int i = 0; i < 40; i++)
    {
      try
        {
          CORBA::Short n = 0;
          {
            ACE_GUARD_RETURN (ACE_Mutex, ace_mon, this->lock_, 0);
            n = ++this->message_counter_;
          }
          this->asynch_hello_->method (n);

          ACE_Time_Value udelay(0,400);
          struct timespec ts = udelay;
          ACE_OS::nanosleep (&ts);

        }
      catch (CORBA::Exception &ex)
        {
          excep = true;
          ACE_ERROR ((LM_ERROR,
                      "(%t) Exception caught: %s after %d invocations\n",
                      ex._name(), i));
          i = 39;
        }
    }
  if (!excep)
    ACE_DEBUG ((LM_DEBUG, "(%t) Did all iterations\n"));

  {
    ACE_GUARD_RETURN (ACE_Mutex, ace_mon, this->lock_, 0);
    --this->busy_threads_;
    if (this->busy_threads_)
      return 0;
  }

  try
    {
      this->orb_->shutdown();
    }
  catch (CORBA::Exception &)
    {
    }

  return 0;
}