Example #1
0
    // service initialization method
    int 
    net_ace::
    open (void *p) 
    {        
        // we need to use a 'ACE_Condition' to wait for the thread to properly comes up
        // otherwise there might be conflict in data access by two threads
        
        ACE_Thread_Mutex mutex;
        _up_cond = new ACE_Condition<ACE_Thread_Mutex>(mutex);
        
        printf ("ace_net::open (), before activate thread count: %lu\n", this->thr_count ()); 
        
        // activate the ACE network layer as a thread
        // NOTE: _active should be set true by now, so that the loop in svc () may proceed correctly
        _active = true;
        this->activate ();        

        // wait until server is up and running (e.g. svc() is executing)
        // NOTE: this works because we expect svc () will first take sometime to execute,
        //       during which the _up_cond->wait () is first called.
        //       if wait () is called *after* svc () has called _up_cond->signal ();
        //       we will face long, infinite waiting.
        mutex.acquire ();
        _up_cond->wait ();
        mutex.release ();
        
        delete _up_cond;
        _up_cond = NULL;
        
        printf ("ace_net::open (), after activate thread count: %lu\n", this->thr_count ()); 

        return 0;
    }
Example #2
0
    // service termination method;
    int 
    net_ace::
    close (u_long i)
    {       
        if (_active == true)
        {
            ACE_Thread_Mutex mutex;
            _down_cond = new ACE_Condition<ACE_Thread_Mutex>(mutex);
                   
            printf ("ace_net::close () thread count: %lu (before closing reactor)\n", this->thr_count ()); 
            
            // allow the reactor to leave its event handling loop
            _active = false;
            _reactor->end_reactor_event_loop ();
                            
            // wait until the svc() thread terminates
            mutex.acquire ();
            _down_cond->wait ();
            mutex.release ();
            
            delete _down_cond;
            _down_cond = NULL;

            printf ("ace_net::close (), thread count: %lu (after closing reactor)\n", this->thr_count ()); 
        }

        return 0;
    }
int
ACE_Condition<ACE_Thread_Mutex>::wait (ACE_Thread_Mutex &mutex,
                                  const ACE_Time_Value *abstime)
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::wait");
  return ACE_OS::cond_timedwait (&this->cond_,
                                 &mutex.lock (),
                                 const_cast <ACE_Time_Value *> (abstime));
}
Example #4
0
static double
prof_mutex_base (size_t iteration)
{
#if defined (ACE_HAS_THREADS)
    ACE_Thread_Mutex plain;
    if (iteration != 0)
    {
        ACE_Profile_Timer ptimer;
        ACE_Profile_Timer::ACE_Elapsed_Time et;
        double time = 0;

        for (size_t i = 0; i < iteration; i++)
        {
            ACE_STOP_SIGN;
            ptimer.start ();

            for (size_t j=0; j < MULTIPLY_FACTOR; j++)
            {
                plain.acquire ();
                plain.release ();
            }

            ptimer.stop ();
            ptimer.elapsed_time (et);
            time += et.real_time;
        }
        iteration *= MULTIPLY_FACTOR;
        return time / iteration;
    }
    else
        return -1.0;
#else
    ACE_UNUSED_ARG (iteration);
    ACE_ERROR_RETURN ((LM_ERROR, "Threads are not supported on this platform."), -1);
#endif
}
Example #5
0
static void *seekerThread(void *seekerThreadArgsVoidStar)
{
   SeekerThreadArgs *seekerThreadArgs =
      static_cast<SeekerThreadArgs *>(seekerThreadArgsVoidStar);
   SeekerCmdLineParser *seekerParser = seekerThreadArgs->seekerParser;
   ACE_Thread_Mutex *startingSeeker = seekerThreadArgs->startingSeeker;
   delete seekerThreadArgs;

   SseArchive::setup();
   SseArchive::SystemLog() << "Seeker started.  " 
                           << SSE_VERSION << endl;

   Scheduler *scheduler = Scheduler::instance();
   Site* site;

   try {

      site = new Site(seekerParser->getDxPort(),
                      seekerParser->getDxArchiverPort(),
                      seekerParser->getChannelizerPort(),
                      seekerParser->getDxArchiver1Hostname(),
                      seekerParser->getDxToArchiver1Port(),
                      seekerParser->getDxArchiver2Hostname(),
                      seekerParser->getDxToArchiver2Port(),
                      seekerParser->getDxArchiver3Hostname(),
                      seekerParser->getDxToArchiver3Port(),
                      seekerParser->getIfcPort(),
                      seekerParser->getTscopePort(),
                      seekerParser->getTsigPort(),
                      seekerParser->getComponentControlPort(),
                      seekerParser->getExpectedComponentsFilename(),
                      seekerParser->getNoUi());

      delete seekerParser;
    
      paraGlobal.setSite(site);  // attach the site to the Text UI
      paraGlobal.act_->setScheduler(scheduler);
      scheduler->setSite(site);

      addActivityTypesToScheduler(scheduler);
      addActStrategyTypesToScheduler(scheduler);
   }
   catch (NssAcceptHandlerException &exception) {
      scheduler->failed();

      stringstream strm;
      strm << "Scheduler failed to start. " << exception.descrip(); 
      SseMessage::log(MsgSender,
                      NSS_NO_ACTIVITY_ID, SSE_MSG_SCHED_FAILED,
                      SEVERITY_ERROR, strm.str(),
                      __FILE__, __LINE__);

      cerr << exception.descrip() 
           << "Warning: failed to start one or more component accept" 
           << " handlers." << endl
           << "Make sure that another copy of this program"
           << " is not already running" << endl
           << "on this machine." << endl
           << "If new component port numbers were specified, "
           << "make sure they're valid."
           << endl;
    
      exit(1);

   }
   catch (SseException &exception) {
      scheduler->failed();

      stringstream strm;
      strm << "Scheduler failed to start. " << exception.descrip(); 
      SseMessage::log(MsgSender,
                      NSS_NO_ACTIVITY_ID, SSE_MSG_SCHED_FAILED,
                      SEVERITY_ERROR, strm.str(),
                      __FILE__, __LINE__);

      cerr << strm.str();

      exit(1);

   }
   catch (...) {
      cerr << "seeker main: caught unknown exception" << endl;
      SseMessage::log(MsgSender,
                      NSS_NO_ACTIVITY_ID, SSE_MSG_EXCEPTION,
                      SEVERITY_ERROR, 
                      "seeker main: caught unknown exception",
                      __FILE__, __LINE__);

      exit(1);
   }

   startingSeeker->release();

   // Prevent the ACE Reactor event loop from exiting prematurely
   // when a system call is interrupted (ie, errno == EINTR)
   // by enabling restart.
   ACE_Reactor::instance()->restart(1);

   //int status =
   ACE_Reactor::run_event_loop();

   SseArchive::SystemLog() << "Seeker done" << endl;

   return 0;
}