Ejemplo n.º 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;
    }
Ejemplo n.º 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;
    }
Ejemplo n.º 3
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
}