sc_event_queue.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_event_queue.cpp -- Event Queue Support
00021 
00022   Original Author: Stuart Swan, Cadence Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 
00037 // $Log: sc_event_queue.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:35  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.4  2006/01/26 21:00:50  acg
00042 //  Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of
00043 //  sc_event::notify_delayed()
00044 //
00045 // Revision 1.3  2006/01/13 18:47:42  acg
00046 // Added $Log command so that CVS comments are reproduced in the source.
00047 //
00048 
00049 #include "sysc/communication/sc_event_queue.h"
00050 #include "sysc/kernel/sc_method_process.h"
00051 
00052 namespace sc_core {
00053 
00054 static int 
00055 sc_time_compare( const void* p1, const void* p2 )
00056 {
00057     const sc_time* t1 = static_cast<const sc_time*>( p1 );
00058     const sc_time* t2 = static_cast<const sc_time*>( p2 );
00059 
00060     if( *t1 < *t2 ) {
00061     return 1;
00062     } else if( *t1 > *t2 ) {
00063     return -1;
00064     } else {
00065     return 0;
00066     }  
00067 }
00068 
00069 sc_event_queue::sc_event_queue( sc_module_name name_ )
00070     : sc_module( name_ ),
00071       m_ppq( 128, sc_time_compare ),
00072       m_pending_delta(0)
00073 {
00074     m_delta=0;
00075     SC_METHOD( fire_event );
00076     sensitive << m_e;
00077     dont_initialize();
00078 }
00079 
00080 sc_event_queue::~sc_event_queue()
00081 {
00082   while (m_ppq.size() > 0) {
00083     delete m_ppq.extract_top();
00084   }
00085 }
00086 
00087 void sc_event_queue::cancel_all()
00088 {
00089     m_pending_delta = 0;
00090     while( m_ppq.size() > 0 )
00091     m_ppq.extract_top();
00092     m_e.cancel();
00093 }
00094 
00095 void sc_event_queue::notify (const sc_time& when)
00096 {
00097     m_delta = sc_delta_count();
00098     sc_time* t = new sc_time( when+sc_time_stamp() );
00099     if ( m_ppq.size()==0 || *t < *m_ppq.top() ) {
00100     m_e.notify( when );
00101     }
00102     m_ppq.insert( t );
00103 }
00104     
00105 void sc_event_queue::fire_event()
00106 {
00107     sc_time* t = m_ppq.extract_top();
00108     assert( *t==sc_time_stamp() );
00109     delete t;
00110 
00111     if ( m_ppq.size() > 0 ) {
00112     m_e.notify( *m_ppq.top() - sc_time_stamp() );
00113     }
00114 }
00115 
00116 } // namespace sc_core

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5