Ignore:
Timestamp:
Mar 14, 2014, 8:26:33 PM (11 years ago)
Author:
hock@…
Message:

new functionality: SystemQueue::leave() and SystemQueue::join()

( + unit tests)

Location:
source/ariba/utility/system
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/system/SystemQueue.cpp

    r12764 r12765  
    7676void SystemQueue::scheduleEvent( const SystemEvent& event, uint32_t delay )
    7777{
    78     assert ( SysQ->running );  // should we really enforce this?
     78//     assert ( SysQ->running );  // should we really enforce this?
     79    if ( ! SysQ->running )
     80    {
     81        logging_debug("/// WARNING: The SystemQueue is NOT RUNNING!");
     82    }
    7983   
    8084    // copy
     
    140144    SysQ.reset( new QueueThread() );
    141145}
     146
     147
     148void SystemQueue::leave()
     149{
     150    // signal SysQ to quit (and abort queued events)
     151    SysQ->cancel();
     152}
     153
     154void SystemQueue::join()
     155{
     156    if ( sysq_thread )
     157    {
     158        logging_debug("/// ... joining SysQ thread");
     159        sysq_thread->join();
     160    }
     161}
     162
     163
    142164
    143165void SystemQueue::dropAll( const SystemEventListener* mlistener)
     
    303325        if ( timedEventsQ.empty() )
    304326        {
    305             logging_debug("/// SysQ is going to sleep.");
     327//             logging_debug("/// SysQ is going to sleep.");
    306328           
    307329            this->system_queue_idle.wait( lock );
     
    310332        else
    311333        {
    312             logging_debug( "/// SysQ is going to sleep for "
    313                         << ( timedEventsQ.top().deadline - get_clock() ).total_milliseconds()
    314                         << "ms. Deadline: "
    315                         << timedEventsQ.top().deadline
    316                         << ", Clock: "
    317                         << get_clock() );
     334//             logging_debug( "/// SysQ is going to sleep for "
     335//                         << ( timedEventsQ.top().deadline - get_clock() ).total_milliseconds()
     336//                         << "ms. Deadline: "
     337//                         << timedEventsQ.top().deadline
     338//                         << ", Clock: "
     339//                         << get_clock() );
    318340
    319341            this->system_queue_idle.timed_wait( lock, timedEventsQ.top().deadline );
  • source/ariba/utility/system/SystemQueue.h

    r12764 r12765  
    117117         * Cancels the system queue and ends the processing after the
    118118         * currently processed event is processed.
     119     *
     120     * NOTE: Do not call this function from within a SystemQueue-Event.
     121     *   Use SystemQueue::leave() instead.
    119122         *
    120123         * This method is thread-safe.
    121124         */
    122125        void cancel();
     126   
     127    /**
     128     * Like SystemQueue::cancel(), but may only be called from within a SystemQueue-Event.
     129     *
     130     * NOTE: In this case some cleanup can not be made. -- If the SystemQueue is
     131     *   restarted, SystemQueue::cancel() must be called before SystemQueue::run()
     132     *   can be called again.
     133     */
     134    void leave();
     135   
     136    /**
     137     * Join the SystemQueue thread -- the current thread is blocked until the
     138     * SystemQueue finishes.
     139     *
     140     * NOTE: Use this only in combination with SystemQueue::leave()
     141     *
     142     * [ There is a possible race condition with SystemQueue::cancel(), but
     143     *   SystemQueue::join() should not be used at the same time as
     144     *   SystemQueue::cancel() anyway. (SystemQueue::leave() is fine, though.)
     145     */
     146    void join();
    123147
    124148        /**
Note: See TracChangeset for help on using the changeset viewer.