112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_event_queue.cpp -- Event Queue Support 2312027Sjungma@eit.uni-kl.de 2412027Sjungma@eit.uni-kl.de Original Author: Stuart Swan, Cadence Inc. 2512027Sjungma@eit.uni-kl.de 2612027Sjungma@eit.uni-kl.de CHANGE LOG IS AT THE END OF THE FILE 2712027Sjungma@eit.uni-kl.de *****************************************************************************/ 2812027Sjungma@eit.uni-kl.de 2912027Sjungma@eit.uni-kl.de#include "sysc/communication/sc_event_queue.h" 3012027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_method_process.h" 3112027Sjungma@eit.uni-kl.de 3212027Sjungma@eit.uni-kl.denamespace sc_core { 3312027Sjungma@eit.uni-kl.de 3412027Sjungma@eit.uni-kl.destatic int 3512027Sjungma@eit.uni-kl.desc_time_compare( const void* p1, const void* p2 ) 3612027Sjungma@eit.uni-kl.de{ 3712027Sjungma@eit.uni-kl.de const sc_time* t1 = static_cast<const sc_time*>( p1 ); 3812027Sjungma@eit.uni-kl.de const sc_time* t2 = static_cast<const sc_time*>( p2 ); 3912027Sjungma@eit.uni-kl.de 4012027Sjungma@eit.uni-kl.de if( *t1 < *t2 ) { 4112027Sjungma@eit.uni-kl.de return 1; 4212027Sjungma@eit.uni-kl.de } else if( *t1 > *t2 ) { 4312027Sjungma@eit.uni-kl.de return -1; 4412027Sjungma@eit.uni-kl.de } else { 4512027Sjungma@eit.uni-kl.de return 0; 4612027Sjungma@eit.uni-kl.de } 4712027Sjungma@eit.uni-kl.de} 4812027Sjungma@eit.uni-kl.de 4912027Sjungma@eit.uni-kl.desc_event_queue::sc_event_queue( sc_module_name name_ ) 5012027Sjungma@eit.uni-kl.de : sc_module( name_ ), 5112027Sjungma@eit.uni-kl.de m_ppq( 128, sc_time_compare ), 5212027Sjungma@eit.uni-kl.de m_e( (std::string(SC_KERNEL_EVENT_PREFIX)+"_event").c_str() ), 5312027Sjungma@eit.uni-kl.de m_change_stamp(0), 5412027Sjungma@eit.uni-kl.de m_pending_delta(0) 5512027Sjungma@eit.uni-kl.de{ 5612027Sjungma@eit.uni-kl.de SC_METHOD( fire_event ); 5712027Sjungma@eit.uni-kl.de sensitive << m_e; 5812027Sjungma@eit.uni-kl.de dont_initialize(); 5912027Sjungma@eit.uni-kl.de} 6012027Sjungma@eit.uni-kl.de 6112027Sjungma@eit.uni-kl.desc_event_queue::~sc_event_queue() 6212027Sjungma@eit.uni-kl.de{ 6312027Sjungma@eit.uni-kl.de while (m_ppq.size() > 0) { 6412027Sjungma@eit.uni-kl.de delete m_ppq.extract_top(); 6512027Sjungma@eit.uni-kl.de } 6612027Sjungma@eit.uni-kl.de} 6712027Sjungma@eit.uni-kl.de 6812027Sjungma@eit.uni-kl.devoid sc_event_queue::cancel_all() 6912027Sjungma@eit.uni-kl.de{ 7012027Sjungma@eit.uni-kl.de m_pending_delta = 0; 7112027Sjungma@eit.uni-kl.de while( m_ppq.size() > 0 ) 7212027Sjungma@eit.uni-kl.de delete m_ppq.extract_top(); 7312027Sjungma@eit.uni-kl.de m_e.cancel(); 7412027Sjungma@eit.uni-kl.de} 7512027Sjungma@eit.uni-kl.de 7612027Sjungma@eit.uni-kl.devoid sc_event_queue::notify (const sc_time& when) 7712027Sjungma@eit.uni-kl.de{ 7812027Sjungma@eit.uni-kl.de m_change_stamp = simcontext()->change_stamp(); 7912027Sjungma@eit.uni-kl.de sc_time* t = new sc_time( when+sc_time_stamp() ); 8012027Sjungma@eit.uni-kl.de if ( m_ppq.size()==0 || *t < *m_ppq.top() ) { 8112027Sjungma@eit.uni-kl.de m_e.notify( when ); 8212027Sjungma@eit.uni-kl.de } 8312027Sjungma@eit.uni-kl.de m_ppq.insert( t ); 8412027Sjungma@eit.uni-kl.de} 8512027Sjungma@eit.uni-kl.de 8612027Sjungma@eit.uni-kl.devoid sc_event_queue::fire_event() 8712027Sjungma@eit.uni-kl.de{ 8812027Sjungma@eit.uni-kl.de if ( m_ppq.empty() ) { // event has been cancelled 8912027Sjungma@eit.uni-kl.de return; 9012027Sjungma@eit.uni-kl.de } 9112027Sjungma@eit.uni-kl.de sc_time* t = m_ppq.extract_top(); 9212027Sjungma@eit.uni-kl.de assert( *t==sc_time_stamp() ); 9312027Sjungma@eit.uni-kl.de delete t; 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de if ( m_ppq.size() > 0 ) { 9612027Sjungma@eit.uni-kl.de m_e.notify( *m_ppq.top() - sc_time_stamp() ); 9712027Sjungma@eit.uni-kl.de } 9812027Sjungma@eit.uni-kl.de} 9912027Sjungma@eit.uni-kl.de 10012027Sjungma@eit.uni-kl.de} // namespace sc_core 10112027Sjungma@eit.uni-kl.de 10212027Sjungma@eit.uni-kl.de// $Log: sc_event_queue.cpp,v $ 10312027Sjungma@eit.uni-kl.de// Revision 1.9 2011/08/26 22:45:53 acg 10412027Sjungma@eit.uni-kl.de// Torsten Maehne: remove redundant initialization assignment. 10512027Sjungma@eit.uni-kl.de// 10612027Sjungma@eit.uni-kl.de// Revision 1.8 2011/08/26 21:44:58 acg 10712027Sjungma@eit.uni-kl.de// Andy Goodrich: fix internal event naming. 10812027Sjungma@eit.uni-kl.de// 10912027Sjungma@eit.uni-kl.de// Revision 1.7 2011/08/26 20:45:39 acg 11012027Sjungma@eit.uni-kl.de// Andy Goodrich: moved the modification log to the end of the file to 11112027Sjungma@eit.uni-kl.de// eliminate source line number skew when check-ins are done. 11212027Sjungma@eit.uni-kl.de// 11312027Sjungma@eit.uni-kl.de// Revision 1.6 2011/08/24 22:05:35 acg 11412027Sjungma@eit.uni-kl.de// Torsten Maehne: initialization changes to remove warnings. 11512027Sjungma@eit.uni-kl.de// 11612027Sjungma@eit.uni-kl.de// Revision 1.5 2011/04/08 18:22:46 acg 11712027Sjungma@eit.uni-kl.de// Philipp A. Hartmann: use the context of the primitive channel to get 11812027Sjungma@eit.uni-kl.de// the change stamp value. 11912027Sjungma@eit.uni-kl.de// 12012027Sjungma@eit.uni-kl.de// Revision 1.4 2011/04/05 20:48:09 acg 12112027Sjungma@eit.uni-kl.de// Andy Goodrich: changes to make sure that event(), posedge() and negedge() 12212027Sjungma@eit.uni-kl.de// only return true if the clock has not moved. 12312027Sjungma@eit.uni-kl.de// 12412027Sjungma@eit.uni-kl.de// Revision 1.3 2011/02/18 20:23:45 acg 12512027Sjungma@eit.uni-kl.de// Andy Goodrich: Copyright update. 12612027Sjungma@eit.uni-kl.de// 12712027Sjungma@eit.uni-kl.de// Revision 1.2 2010/07/22 20:02:30 acg 12812027Sjungma@eit.uni-kl.de// Andy Goodrich: bug fixes. 12912027Sjungma@eit.uni-kl.de// 13012027Sjungma@eit.uni-kl.de// Revision 1.1.1.1 2006/12/15 20:20:04 acg 13112027Sjungma@eit.uni-kl.de// SystemC 2.3 13212027Sjungma@eit.uni-kl.de// 13312027Sjungma@eit.uni-kl.de// Revision 1.5 2006/11/28 20:30:48 acg 13412027Sjungma@eit.uni-kl.de// Andy Goodrich: updated from 2.2 source. sc_event_queue constructors 13512027Sjungma@eit.uni-kl.de// collapsed into a single constructor with an optional argument to get 13612027Sjungma@eit.uni-kl.de// the sc_module_name stack done correctly. Class name prefixing added 13712027Sjungma@eit.uni-kl.de// to sc_semaphore calls to wait() to keep gcc 4.x happy. 13812027Sjungma@eit.uni-kl.de// 13912027Sjungma@eit.uni-kl.de// Revision 1.4 2006/01/26 21:00:50 acg 14012027Sjungma@eit.uni-kl.de// Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of 14112027Sjungma@eit.uni-kl.de// sc_event::notify_delayed() 14212027Sjungma@eit.uni-kl.de// 14312027Sjungma@eit.uni-kl.de// Revision 1.3 2006/01/13 18:47:42 acg 14412027Sjungma@eit.uni-kl.de// Added $Log command so that CVS comments are reproduced in the source. 14512027Sjungma@eit.uni-kl.de 14612027Sjungma@eit.uni-kl.de// taf 147