Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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-2004 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.3 (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 #include "systemc/communication/sc_event_queue.h"
00038 
00039 static int 
00040 sc_time_compare( const void* p1, const void* p2 )
00041 {
00042     const sc_time* t1 = static_cast<const sc_time*>( p1 );
00043     const sc_time* t2 = static_cast<const sc_time*>( p2 );
00044 
00045     if( *t1 < *t2 ) {
00046   return 1;
00047     } else if( *t1 > *t2 ) {
00048   return -1;
00049     } else {
00050   return 0;
00051     }  
00052 }
00053 
00054 sc_event_queue::sc_event_queue()
00055     : sc_module( sc_gen_unique_name( "sc_event_queue" ) ),
00056       m_ppq( 128, sc_time_compare ),
00057       m_pending_delta(0)
00058     
00059 {
00060     m_delta=0;
00061     SC_METHOD( fire_event );
00062     sensitive << m_e;
00063     dont_initialize();
00064     end_module();
00065 }
00066 
00067 sc_event_queue::sc_event_queue( sc_module_name name_ )
00068     : sc_module( name_ ),
00069       m_ppq( 128, sc_time_compare ),
00070       m_pending_delta(0)
00071 {
00072     m_delta=0;
00073     SC_METHOD( fire_event );
00074     sensitive << m_e;
00075     dont_initialize();
00076 }
00077 
00078 sc_event_queue::~sc_event_queue()
00079 {
00080   while (m_ppq.size() > 0) {
00081     delete m_ppq.extract_top();
00082   }
00083 }
00084 
00085 void sc_event_queue::cancel_all()
00086 {
00087     m_pending_delta = 0;
00088     while( m_ppq.size() > 0 )
00089   m_ppq.extract_top();
00090     m_e.cancel();
00091 }
00092 
00093 void sc_event_queue::notify (const sc_time& when)
00094 {
00095     m_delta = sc_get_curr_simcontext()->delta_count();
00096     sc_time* t = new sc_time( when+sc_time_stamp() );
00097     if ( m_ppq.size()==0 || *t < *m_ppq.top() ) {
00098   m_e.notify( when );
00099     }
00100     m_ppq.insert( t );
00101 }
00102     
00103 void sc_event_queue::fire_event()
00104 {
00105     sc_time* t = m_ppq.extract_top();
00106     assert( *t==sc_time_stamp() );
00107     delete t;
00108 
00109     if ( m_ppq.size() > 0 ) {
00110   m_e.notify( *m_ppq.top() - sc_time_stamp() );
00111     }
00112 }
00113 

Generated on Fri Jan 14 08:29:01 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18