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_runnable_int.h -- For inline definitions of some utility functions.
2312027Sjungma@eit.uni-kl.de                       DO NOT EXPORT THIS INCLUDE FILE. Include this file
2412027Sjungma@eit.uni-kl.de                       after "sc_process_int.h" so that we can get the base
2512027Sjungma@eit.uni-kl.de                       class right.
2612027Sjungma@eit.uni-kl.de
2712027Sjungma@eit.uni-kl.de  Original Author: Bishnupriya Bhattacharya , Cadence Design, 28th July, 2003
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de CHANGE LOG AT THE END OF THE FILE
3012027Sjungma@eit.uni-kl.de ******************************************************************************/
3112027Sjungma@eit.uni-kl.de
3212027Sjungma@eit.uni-kl.de#ifndef SC_RUNNABLE_INT_H
3312027Sjungma@eit.uni-kl.de#define SC_RUNNABLE_INT_H
3412027Sjungma@eit.uni-kl.de
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_runnable.h"
3712027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_method_process.h"
3812027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_thread_process.h"
3912027Sjungma@eit.uni-kl.de
4012027Sjungma@eit.uni-kl.de// DEBUGGING MACROS:
4112027Sjungma@eit.uni-kl.de//
4212027Sjungma@eit.uni-kl.de// DEBUG_MSG(NAME,P,MSG)
4312027Sjungma@eit.uni-kl.de//     MSG  = message to print
4412027Sjungma@eit.uni-kl.de//     NAME = name that must match the process for the message to print, or
4512027Sjungma@eit.uni-kl.de//            null if the message should be printed unconditionally.
4612027Sjungma@eit.uni-kl.de//     P    = pointer to process message is for, or NULL in which case the
4712027Sjungma@eit.uni-kl.de//            message will not print.
4812027Sjungma@eit.uni-kl.de#if 0
4912027Sjungma@eit.uni-kl.de#   define DEBUG_NAME ""
5012027Sjungma@eit.uni-kl.de#   define DEBUG_MSG(NAME,P,MSG) \
5112027Sjungma@eit.uni-kl.de    { \
5212027Sjungma@eit.uni-kl.de        if ( P && ( (strlen(NAME)==0) || !strcmp(NAME,P->name())) ) \
5312027Sjungma@eit.uni-kl.de          std::cout << "**** " << sc_time_stamp() << " ("  \
5412027Sjungma@eit.uni-kl.de	            << sc_get_current_process_name() << "): " << MSG \
5512027Sjungma@eit.uni-kl.de		    << " - " << P->name() << std::endl; \
5612027Sjungma@eit.uni-kl.de    }
5712027Sjungma@eit.uni-kl.de#else
5812027Sjungma@eit.uni-kl.de#   define DEBUG_MSG(NAME,P,MSG)
5912027Sjungma@eit.uni-kl.de#endif
6012027Sjungma@eit.uni-kl.de
6112027Sjungma@eit.uni-kl.denamespace sc_core {
6212027Sjungma@eit.uni-kl.de
6312027Sjungma@eit.uni-kl.de// The values below are used to indicate when a queue is empty. A non-zero
6412027Sjungma@eit.uni-kl.de// non-legal pointer value is used for this so that a zero value in the
6512027Sjungma@eit.uni-kl.de// m_execute_p field of an sc_process_b instance can be used to indicate
6612027Sjungma@eit.uni-kl.de// that is has not been queued for run. (If we did not use a non-zero
6712027Sjungma@eit.uni-kl.de// queue empty indicator then a sc_process_b instance that was queued
6812027Sjungma@eit.uni-kl.de// twice in a row might end up on the queue twice if it were the first
6912027Sjungma@eit.uni-kl.de// one that was queued!)
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.de#define SC_NO_METHODS ((sc_method_handle)0xdb)
7212027Sjungma@eit.uni-kl.de#define SC_NO_THREADS ((sc_thread_handle)0xdb)
7312027Sjungma@eit.uni-kl.de
7412027Sjungma@eit.uni-kl.de
7512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
7612027Sjungma@eit.uni-kl.de//"sc_runnable::dump"
7712027Sjungma@eit.uni-kl.de//
7812027Sjungma@eit.uni-kl.de// This method dumps the contents of this object instance.
7912027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
8012027Sjungma@eit.uni-kl.deinline void sc_runnable::dump() const
8112027Sjungma@eit.uni-kl.de{
8212027Sjungma@eit.uni-kl.de    // Dump the thread queues:
8312027Sjungma@eit.uni-kl.de
8412027Sjungma@eit.uni-kl.de    std::cout << "thread pop queue: " << std::endl;
8512027Sjungma@eit.uni-kl.de    for ( sc_thread_handle p = m_threads_pop; p != SC_NO_THREADS;
8612027Sjungma@eit.uni-kl.de          p = p->next_runnable() )
8712027Sjungma@eit.uni-kl.de    {
8812027Sjungma@eit.uni-kl.de        std::cout << "    " << p << std::endl;
8912027Sjungma@eit.uni-kl.de    }
9012027Sjungma@eit.uni-kl.de
9112027Sjungma@eit.uni-kl.de    std::cout << "thread push queue: " << std::endl;
9212027Sjungma@eit.uni-kl.de    for ( sc_thread_handle p = m_threads_push_head->next_runnable();
9312027Sjungma@eit.uni-kl.de          p != SC_NO_THREADS; p = p->next_runnable() )
9412027Sjungma@eit.uni-kl.de    {
9512027Sjungma@eit.uni-kl.de        std::cout << "    " << p << std::endl;
9612027Sjungma@eit.uni-kl.de    }
9712027Sjungma@eit.uni-kl.de}
9812027Sjungma@eit.uni-kl.de
9912027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
10012027Sjungma@eit.uni-kl.de//"sc_runnable::execute_method_next"
10112027Sjungma@eit.uni-kl.de//
10212027Sjungma@eit.uni-kl.de// This method pushes the the supplied method to execute as the next process.
10312027Sjungma@eit.uni-kl.de// This is done by pushing it onto the front of the m_methods_pop.
10412027Sjungma@eit.uni-kl.de//     method_h -> method process to add to the queue.
10512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
10612027Sjungma@eit.uni-kl.deinline void sc_runnable::execute_method_next( sc_method_handle method_h )
10712027Sjungma@eit.uni-kl.de{
10812027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,method_h,"pushing this method to execute next");
10912027Sjungma@eit.uni-kl.de    method_h->set_next_runnable( m_methods_pop );
11012027Sjungma@eit.uni-kl.de    m_methods_pop = method_h;
11112027Sjungma@eit.uni-kl.de}
11212027Sjungma@eit.uni-kl.de
11312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
11412027Sjungma@eit.uni-kl.de//"sc_runnable::execute_thread_next"
11512027Sjungma@eit.uni-kl.de//
11612027Sjungma@eit.uni-kl.de// This method pushes the the supplied thread to execute as the next process.
11712027Sjungma@eit.uni-kl.de// This is done by pushing it onto the front of the m_threads_pop.
11812027Sjungma@eit.uni-kl.de//     thread_h -> thread process to add to the queue.
11912027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
12012027Sjungma@eit.uni-kl.deinline void sc_runnable::execute_thread_next( sc_thread_handle thread_h )
12112027Sjungma@eit.uni-kl.de{
12212027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,thread_h,"pushing this thread to execute next");
12312027Sjungma@eit.uni-kl.de    thread_h->set_next_runnable( m_threads_pop );
12412027Sjungma@eit.uni-kl.de    m_threads_pop = thread_h;
12512027Sjungma@eit.uni-kl.de}
12612027Sjungma@eit.uni-kl.de
12712027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
12812027Sjungma@eit.uni-kl.de//"sc_runnable::init"
12912027Sjungma@eit.uni-kl.de//
13012027Sjungma@eit.uni-kl.de// This method initializes this object instance. Note we allocate the queue
13112027Sjungma@eit.uni-kl.de// heads if necessary. This is done here rather than in the constructor for
13212027Sjungma@eit.uni-kl.de// this class to eliminate CTOR processing errors with gcc.
13312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
13412027Sjungma@eit.uni-kl.deinline void sc_runnable::init()
13512027Sjungma@eit.uni-kl.de{
13612027Sjungma@eit.uni-kl.de    m_methods_pop = SC_NO_METHODS;
13712027Sjungma@eit.uni-kl.de    if ( !m_methods_push_head )
13812027Sjungma@eit.uni-kl.de    {
13912027Sjungma@eit.uni-kl.de        m_methods_push_head = new sc_method_process("methods_push_head", true,
14012027Sjungma@eit.uni-kl.de	                                           (SC_ENTRY_FUNC)0, 0, 0);
14112027Sjungma@eit.uni-kl.de        m_methods_push_head->dont_initialize(true);
14212027Sjungma@eit.uni-kl.de	m_methods_push_head->detach();
14312027Sjungma@eit.uni-kl.de    }
14412027Sjungma@eit.uni-kl.de    m_methods_push_tail = m_methods_push_head;
14512027Sjungma@eit.uni-kl.de    m_methods_push_head->set_next_runnable(SC_NO_METHODS);
14612027Sjungma@eit.uni-kl.de
14712027Sjungma@eit.uni-kl.de    m_threads_pop = SC_NO_THREADS;
14812027Sjungma@eit.uni-kl.de    if ( !m_threads_push_head )
14912027Sjungma@eit.uni-kl.de    {
15012027Sjungma@eit.uni-kl.de        m_threads_push_head = new sc_thread_process("threads_push_head", true,
15112027Sjungma@eit.uni-kl.de	                                            (SC_ENTRY_FUNC)0, 0, 0);
15212027Sjungma@eit.uni-kl.de        m_threads_push_head->dont_initialize(true);
15312027Sjungma@eit.uni-kl.de	m_threads_push_head->detach();
15412027Sjungma@eit.uni-kl.de    }
15512027Sjungma@eit.uni-kl.de    m_threads_push_head->set_next_runnable(SC_NO_THREADS);
15612027Sjungma@eit.uni-kl.de    m_threads_push_tail = m_threads_push_head;
15712027Sjungma@eit.uni-kl.de}
15812027Sjungma@eit.uni-kl.de
15912027Sjungma@eit.uni-kl.de
16012027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
16112027Sjungma@eit.uni-kl.de//"sc_runnable::is_empty"
16212027Sjungma@eit.uni-kl.de//
16312027Sjungma@eit.uni-kl.de// This method returns true if the push queue is empty, or false if not.
16412027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
16512027Sjungma@eit.uni-kl.deinline bool sc_runnable::is_empty() const
16612027Sjungma@eit.uni-kl.de{
16712027Sjungma@eit.uni-kl.de    return m_methods_push_head->next_runnable() == SC_NO_METHODS &&
16812027Sjungma@eit.uni-kl.de           m_methods_pop == SC_NO_METHODS &&
16912027Sjungma@eit.uni-kl.de	   m_threads_push_head->next_runnable() == SC_NO_THREADS &&
17012027Sjungma@eit.uni-kl.de	   m_threads_pop == SC_NO_THREADS;
17112027Sjungma@eit.uni-kl.de}
17212027Sjungma@eit.uni-kl.de
17312027Sjungma@eit.uni-kl.de
17412027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
17512027Sjungma@eit.uni-kl.de//"sc_runnable::is_initialized"
17612027Sjungma@eit.uni-kl.de//
17712027Sjungma@eit.uni-kl.de// This method returns true if the push queue is already initialized.
17812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
17912027Sjungma@eit.uni-kl.deinline bool sc_runnable::is_initialized() const
18012027Sjungma@eit.uni-kl.de{
18112027Sjungma@eit.uni-kl.de    return m_methods_push_head && m_threads_push_head;
18212027Sjungma@eit.uni-kl.de}
18312027Sjungma@eit.uni-kl.de
18412027Sjungma@eit.uni-kl.de
18512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
18612027Sjungma@eit.uni-kl.de//"sc_runnable::push_back_method"
18712027Sjungma@eit.uni-kl.de//
18812027Sjungma@eit.uni-kl.de// This method pushes the supplied method process onto the back of the queue of
18912027Sjungma@eit.uni-kl.de// runnable method processes.
19012027Sjungma@eit.uni-kl.de//     method_h -> method process to add to the queue.
19112027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
19212027Sjungma@eit.uni-kl.deinline void sc_runnable::push_back_method( sc_method_handle method_h )
19312027Sjungma@eit.uni-kl.de{
19412027Sjungma@eit.uni-kl.de    // assert( method_h->next_runnable() == 0 ); // Can't queue twice.
19512027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,method_h,"pushing back method");
19612027Sjungma@eit.uni-kl.de    method_h->set_next_runnable(SC_NO_METHODS);
19712027Sjungma@eit.uni-kl.de    m_methods_push_tail->set_next_runnable(method_h);
19812027Sjungma@eit.uni-kl.de    m_methods_push_tail = method_h;
19912027Sjungma@eit.uni-kl.de}
20012027Sjungma@eit.uni-kl.de
20112027Sjungma@eit.uni-kl.de
20212027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
20312027Sjungma@eit.uni-kl.de//"sc_runnable::push_back_thread"
20412027Sjungma@eit.uni-kl.de//
20512027Sjungma@eit.uni-kl.de// This method pushes the supplied thread process onto the back of the queue of
20612027Sjungma@eit.uni-kl.de// runnable thread processes.
20712027Sjungma@eit.uni-kl.de//     thread_h -> thread process to add to the queue.
20812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
20912027Sjungma@eit.uni-kl.deinline void sc_runnable::push_back_thread( sc_thread_handle thread_h )
21012027Sjungma@eit.uni-kl.de{
21112027Sjungma@eit.uni-kl.de    // assert( thread_h->next_runnable() == 0 ); // Can't queue twice.
21212027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,thread_h,"pushing back thread");
21312027Sjungma@eit.uni-kl.de    thread_h->set_next_runnable(SC_NO_THREADS);
21412027Sjungma@eit.uni-kl.de    m_threads_push_tail->set_next_runnable(thread_h);
21512027Sjungma@eit.uni-kl.de    m_threads_push_tail = thread_h;
21612027Sjungma@eit.uni-kl.de}
21712027Sjungma@eit.uni-kl.de
21812027Sjungma@eit.uni-kl.de
21912027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
22012027Sjungma@eit.uni-kl.de//"sc_runnable::push_front_method"
22112027Sjungma@eit.uni-kl.de//
22212027Sjungma@eit.uni-kl.de// This method pushes the supplied method process onto the front of the queue of
22312027Sjungma@eit.uni-kl.de// runnable method processes. If the queue is empty the process is the tail
22412027Sjungma@eit.uni-kl.de// also.
22512027Sjungma@eit.uni-kl.de//     method_h -> method process to add to the queue.
22612027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
22712027Sjungma@eit.uni-kl.deinline void sc_runnable::push_front_method( sc_method_handle method_h )
22812027Sjungma@eit.uni-kl.de{
22912027Sjungma@eit.uni-kl.de    // assert( method_h->next_runnable() == 0 ); // Can't queue twice.
23012027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,method_h,"pushing front method");
23112027Sjungma@eit.uni-kl.de    method_h->set_next_runnable(m_methods_push_head->next_runnable());
23212027Sjungma@eit.uni-kl.de    if ( m_methods_push_tail == m_methods_push_head ) // Empty queue.
23312027Sjungma@eit.uni-kl.de    {
23412027Sjungma@eit.uni-kl.de        m_methods_push_tail->set_next_runnable(method_h);
23512027Sjungma@eit.uni-kl.de	m_methods_push_tail = method_h;
23612027Sjungma@eit.uni-kl.de    }
23712027Sjungma@eit.uni-kl.de    else                                               // Non-empty queue.
23812027Sjungma@eit.uni-kl.de    {
23912027Sjungma@eit.uni-kl.de	m_methods_push_head->set_next_runnable(method_h);
24012027Sjungma@eit.uni-kl.de    }
24112027Sjungma@eit.uni-kl.de}
24212027Sjungma@eit.uni-kl.de
24312027Sjungma@eit.uni-kl.de
24412027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
24512027Sjungma@eit.uni-kl.de//"sc_runnable::push_front_thread"
24612027Sjungma@eit.uni-kl.de//
24712027Sjungma@eit.uni-kl.de// This method pushes the supplied thread process onto the front of the queue of
24812027Sjungma@eit.uni-kl.de// runnable thread processes. If the queue is empty the process is the tail
24912027Sjungma@eit.uni-kl.de// also.
25012027Sjungma@eit.uni-kl.de//     thread_h -> thread process to add to the queue.
25112027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
25212027Sjungma@eit.uni-kl.deinline void sc_runnable::push_front_thread( sc_thread_handle thread_h )
25312027Sjungma@eit.uni-kl.de{
25412027Sjungma@eit.uni-kl.de    // assert( thread_h->next_runnable() == 0 ); // Can't queue twice.
25512027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,thread_h,"pushing front thread");
25612027Sjungma@eit.uni-kl.de    thread_h->set_next_runnable(m_threads_push_head->next_runnable());
25712027Sjungma@eit.uni-kl.de    if ( m_threads_push_tail == m_threads_push_head ) // Empty queue.
25812027Sjungma@eit.uni-kl.de    {
25912027Sjungma@eit.uni-kl.de        m_threads_push_tail->set_next_runnable(thread_h);
26012027Sjungma@eit.uni-kl.de	m_threads_push_tail = thread_h;
26112027Sjungma@eit.uni-kl.de    }
26212027Sjungma@eit.uni-kl.de    else                                               // Non-empty queue.
26312027Sjungma@eit.uni-kl.de    {
26412027Sjungma@eit.uni-kl.de	m_threads_push_head->set_next_runnable(thread_h);
26512027Sjungma@eit.uni-kl.de    }
26612027Sjungma@eit.uni-kl.de}
26712027Sjungma@eit.uni-kl.de
26812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
26912027Sjungma@eit.uni-kl.de//"sc_runnable::pop_method"
27012027Sjungma@eit.uni-kl.de//
27112027Sjungma@eit.uni-kl.de// This method pops the next method process to be executed, or returns a null
27212027Sjungma@eit.uni-kl.de// if no method processes are available for execution.
27312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
27412027Sjungma@eit.uni-kl.deinline sc_method_handle sc_runnable::pop_method()
27512027Sjungma@eit.uni-kl.de{
27612027Sjungma@eit.uni-kl.de    sc_method_handle result_p;
27712027Sjungma@eit.uni-kl.de
27812027Sjungma@eit.uni-kl.de    result_p = m_methods_pop;
27912027Sjungma@eit.uni-kl.de    if ( result_p != SC_NO_METHODS )
28012027Sjungma@eit.uni-kl.de    {
28112027Sjungma@eit.uni-kl.de        m_methods_pop = result_p->next_runnable();
28212027Sjungma@eit.uni-kl.de        result_p->set_next_runnable(0);
28312027Sjungma@eit.uni-kl.de    }
28412027Sjungma@eit.uni-kl.de    else
28512027Sjungma@eit.uni-kl.de    {
28612027Sjungma@eit.uni-kl.de	result_p = 0;
28712027Sjungma@eit.uni-kl.de    }
28812027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,result_p,"popping method");
28912027Sjungma@eit.uni-kl.de    return result_p;
29012027Sjungma@eit.uni-kl.de
29112027Sjungma@eit.uni-kl.de}
29212027Sjungma@eit.uni-kl.de
29312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
29412027Sjungma@eit.uni-kl.de//"sc_runnable::pop_thread"
29512027Sjungma@eit.uni-kl.de//
29612027Sjungma@eit.uni-kl.de// This method pops the next thread process to be executed, or returns a null
29712027Sjungma@eit.uni-kl.de// if no thread processes are available for execution.
29812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
29912027Sjungma@eit.uni-kl.deinline sc_thread_handle sc_runnable::pop_thread()
30012027Sjungma@eit.uni-kl.de{
30112027Sjungma@eit.uni-kl.de    sc_thread_handle result_p;
30212027Sjungma@eit.uni-kl.de
30312027Sjungma@eit.uni-kl.de    result_p = m_threads_pop;
30412027Sjungma@eit.uni-kl.de    if ( result_p != SC_NO_THREADS )
30512027Sjungma@eit.uni-kl.de    {
30612027Sjungma@eit.uni-kl.de        m_threads_pop = result_p->next_runnable();
30712027Sjungma@eit.uni-kl.de        result_p->set_next_runnable(0);
30812027Sjungma@eit.uni-kl.de    }
30912027Sjungma@eit.uni-kl.de    else
31012027Sjungma@eit.uni-kl.de    {
31112027Sjungma@eit.uni-kl.de	    result_p = 0;
31212027Sjungma@eit.uni-kl.de    }
31312027Sjungma@eit.uni-kl.de    DEBUG_MSG(DEBUG_NAME,result_p,"popping thread for execution");
31412027Sjungma@eit.uni-kl.de    return result_p;
31512027Sjungma@eit.uni-kl.de}
31612027Sjungma@eit.uni-kl.de
31712027Sjungma@eit.uni-kl.de
31812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
31912027Sjungma@eit.uni-kl.de//"sc_runnable::remove_method"
32012027Sjungma@eit.uni-kl.de//
32112027Sjungma@eit.uni-kl.de// This method removes the supplied method process from the push queue if it is
32212027Sjungma@eit.uni-kl.de// present. Note we clear the method's next pointer so that it may be queued
32312027Sjungma@eit.uni-kl.de// again.
32412027Sjungma@eit.uni-kl.de//     remove_p -> method process to remove from the run queue.
32512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
32612027Sjungma@eit.uni-kl.deinline void sc_runnable::remove_method( sc_method_handle remove_p )
32712027Sjungma@eit.uni-kl.de{
32812027Sjungma@eit.uni-kl.de    sc_method_handle now_p;     // Method now checking.
32912027Sjungma@eit.uni-kl.de    sc_method_handle prior_p;   // Method prior to now_p.
33012027Sjungma@eit.uni-kl.de
33112027Sjungma@eit.uni-kl.de    // Don't try to remove things if we have not been initialized.
33212027Sjungma@eit.uni-kl.de
33312027Sjungma@eit.uni-kl.de    if ( !is_initialized() ) return;
33412027Sjungma@eit.uni-kl.de
33512027Sjungma@eit.uni-kl.de    // Search the push queue:
33612027Sjungma@eit.uni-kl.de
33712027Sjungma@eit.uni-kl.de    prior_p = m_methods_push_head;
33812027Sjungma@eit.uni-kl.de    for ( now_p = m_methods_push_head; now_p!= SC_NO_METHODS;
33912027Sjungma@eit.uni-kl.de	    now_p = now_p->next_runnable() )
34012027Sjungma@eit.uni-kl.de    {
34112027Sjungma@eit.uni-kl.de        if ( remove_p == now_p )
34212027Sjungma@eit.uni-kl.de        {
34312027Sjungma@eit.uni-kl.de            prior_p->set_next_runnable( now_p->next_runnable() );
34412027Sjungma@eit.uni-kl.de            if (now_p == m_methods_push_tail) {
34512027Sjungma@eit.uni-kl.de                m_methods_push_tail = prior_p;
34612027Sjungma@eit.uni-kl.de            }
34712027Sjungma@eit.uni-kl.de            now_p->set_next_runnable(0);
34812027Sjungma@eit.uni-kl.de	    DEBUG_MSG(DEBUG_NAME,now_p,"removing method from push queue");
34912027Sjungma@eit.uni-kl.de            return;
35012027Sjungma@eit.uni-kl.de        }
35112027Sjungma@eit.uni-kl.de        prior_p = now_p;
35212027Sjungma@eit.uni-kl.de    }
35312027Sjungma@eit.uni-kl.de
35412027Sjungma@eit.uni-kl.de    // Search the pop queue:
35512027Sjungma@eit.uni-kl.de
35612027Sjungma@eit.uni-kl.de    prior_p = NULL;
35712027Sjungma@eit.uni-kl.de    for ( now_p = m_methods_pop; now_p != SC_NO_METHODS;
35812027Sjungma@eit.uni-kl.de	  now_p = now_p->next_runnable() )
35912027Sjungma@eit.uni-kl.de    {
36012027Sjungma@eit.uni-kl.de        if ( remove_p == now_p )
36112027Sjungma@eit.uni-kl.de        {
36212027Sjungma@eit.uni-kl.de	    if ( prior_p )
36312027Sjungma@eit.uni-kl.de		prior_p->set_next_runnable( now_p->next_runnable() );
36412027Sjungma@eit.uni-kl.de	    else
36512027Sjungma@eit.uni-kl.de	        m_methods_pop = now_p->next_runnable();
36612027Sjungma@eit.uni-kl.de            now_p->set_next_runnable(0);
36712027Sjungma@eit.uni-kl.de	    DEBUG_MSG(DEBUG_NAME,now_p,"removing method from pop queue");
36812027Sjungma@eit.uni-kl.de            return;
36912027Sjungma@eit.uni-kl.de        }
37012027Sjungma@eit.uni-kl.de        prior_p = now_p;
37112027Sjungma@eit.uni-kl.de    }
37212027Sjungma@eit.uni-kl.de}
37312027Sjungma@eit.uni-kl.de
37412027Sjungma@eit.uni-kl.de
37512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
37612027Sjungma@eit.uni-kl.de//"sc_runnable::remove_thread"
37712027Sjungma@eit.uni-kl.de//
37812027Sjungma@eit.uni-kl.de// This method removes the supplied thread process from the push or pop
37912027Sjungma@eit.uni-kl.de// queue if it is present. Note we clear the thread's next pointer so that it
38012027Sjungma@eit.uni-kl.de// may be queued again.
38112027Sjungma@eit.uni-kl.de//     remove_p -> thread process to remove from the run queue.
38212027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
38312027Sjungma@eit.uni-kl.deinline void sc_runnable::remove_thread( sc_thread_handle remove_p )
38412027Sjungma@eit.uni-kl.de{
38512027Sjungma@eit.uni-kl.de    sc_thread_handle now_p;     // Thread now checking.
38612027Sjungma@eit.uni-kl.de    sc_thread_handle prior_p;   // Thread prior to now_p.
38712027Sjungma@eit.uni-kl.de
38812027Sjungma@eit.uni-kl.de    // Don't try to remove things if we have not been initialized.
38912027Sjungma@eit.uni-kl.de
39012027Sjungma@eit.uni-kl.de    if ( !is_initialized() ) return;
39112027Sjungma@eit.uni-kl.de
39212027Sjungma@eit.uni-kl.de    // Search the push queue:
39312027Sjungma@eit.uni-kl.de
39412027Sjungma@eit.uni-kl.de    prior_p = m_threads_push_head;
39512027Sjungma@eit.uni-kl.de    for ( now_p = m_threads_push_head; now_p != SC_NO_THREADS;
39612027Sjungma@eit.uni-kl.de	  now_p = now_p->next_runnable() )
39712027Sjungma@eit.uni-kl.de    {
39812027Sjungma@eit.uni-kl.de        if ( remove_p == now_p )
39912027Sjungma@eit.uni-kl.de        {
40012027Sjungma@eit.uni-kl.de            prior_p->set_next_runnable( now_p->next_runnable() );
40112027Sjungma@eit.uni-kl.de            if (now_p == m_threads_push_tail) {
40212027Sjungma@eit.uni-kl.de                m_threads_push_tail = prior_p;
40312027Sjungma@eit.uni-kl.de            }
40412027Sjungma@eit.uni-kl.de            now_p->set_next_runnable(0);
40512027Sjungma@eit.uni-kl.de	    DEBUG_MSG(DEBUG_NAME,now_p,"removing thread from push queue");
40612027Sjungma@eit.uni-kl.de            return;
40712027Sjungma@eit.uni-kl.de        }
40812027Sjungma@eit.uni-kl.de        prior_p = now_p;
40912027Sjungma@eit.uni-kl.de    }
41012027Sjungma@eit.uni-kl.de
41112027Sjungma@eit.uni-kl.de    // Search the pop queue:
41212027Sjungma@eit.uni-kl.de
41312027Sjungma@eit.uni-kl.de    prior_p = NULL;
41412027Sjungma@eit.uni-kl.de    for ( now_p = m_threads_pop; now_p != SC_NO_THREADS;
41512027Sjungma@eit.uni-kl.de	  now_p = now_p->next_runnable() )
41612027Sjungma@eit.uni-kl.de    {
41712027Sjungma@eit.uni-kl.de        if ( remove_p == now_p )
41812027Sjungma@eit.uni-kl.de        {
41912027Sjungma@eit.uni-kl.de	    if ( prior_p )
42012027Sjungma@eit.uni-kl.de		prior_p->set_next_runnable( now_p->next_runnable() );
42112027Sjungma@eit.uni-kl.de	    else
42212027Sjungma@eit.uni-kl.de	        m_threads_pop = now_p->next_runnable();
42312027Sjungma@eit.uni-kl.de            now_p->set_next_runnable(0);
42412027Sjungma@eit.uni-kl.de	    DEBUG_MSG(DEBUG_NAME,now_p,"removing thread from pop queue");
42512027Sjungma@eit.uni-kl.de            return;
42612027Sjungma@eit.uni-kl.de        }
42712027Sjungma@eit.uni-kl.de        prior_p = now_p;
42812027Sjungma@eit.uni-kl.de    }
42912027Sjungma@eit.uni-kl.de}
43012027Sjungma@eit.uni-kl.de
43112027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
43212027Sjungma@eit.uni-kl.de//"sc_runnable::sc_runnable"
43312027Sjungma@eit.uni-kl.de//
43412027Sjungma@eit.uni-kl.de// This is the object instance constructor for this class.
43512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
43612027Sjungma@eit.uni-kl.deinline sc_runnable::sc_runnable() :
43712027Sjungma@eit.uni-kl.de   m_methods_push_head(0), m_methods_push_tail(0), m_methods_pop(SC_NO_METHODS),
43812027Sjungma@eit.uni-kl.de   m_threads_push_head(0), m_threads_push_tail(0), m_threads_pop(SC_NO_THREADS)
43912027Sjungma@eit.uni-kl.de{}
44012027Sjungma@eit.uni-kl.de
44112027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
44212027Sjungma@eit.uni-kl.de//"sc_runnable::~sc_runnable"
44312027Sjungma@eit.uni-kl.de//
44412027Sjungma@eit.uni-kl.de// This is the object instance destructor for this class.
44512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
44612027Sjungma@eit.uni-kl.deinline sc_runnable::~sc_runnable()
44712027Sjungma@eit.uni-kl.de{
44812027Sjungma@eit.uni-kl.de    delete m_methods_push_head;
44912027Sjungma@eit.uni-kl.de    delete m_threads_push_head;
45012027Sjungma@eit.uni-kl.de}
45112027Sjungma@eit.uni-kl.de
45212027Sjungma@eit.uni-kl.de
45312027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
45412027Sjungma@eit.uni-kl.de//"sc_runnable::toggle_methods"
45512027Sjungma@eit.uni-kl.de//
45612027Sjungma@eit.uni-kl.de// This method moves the methods push queue to the pop queue and zeros the push
45712027Sjungma@eit.uni-kl.de// queue. This will only be done if the pop queue is presently empty.
45812027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
45912027Sjungma@eit.uni-kl.deinline void sc_runnable::toggle_methods()
46012027Sjungma@eit.uni-kl.de{
46112027Sjungma@eit.uni-kl.de    if ( m_methods_pop == SC_NO_METHODS )
46212027Sjungma@eit.uni-kl.de    {
46312027Sjungma@eit.uni-kl.de	m_methods_pop = m_methods_push_head->next_runnable();
46412027Sjungma@eit.uni-kl.de	m_methods_push_head->set_next_runnable(SC_NO_METHODS);
46512027Sjungma@eit.uni-kl.de	m_methods_push_tail = m_methods_push_head;
46612027Sjungma@eit.uni-kl.de    }
46712027Sjungma@eit.uni-kl.de}
46812027Sjungma@eit.uni-kl.de
46912027Sjungma@eit.uni-kl.de
47012027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
47112027Sjungma@eit.uni-kl.de//"sc_runnable::toggle_threads"
47212027Sjungma@eit.uni-kl.de//
47312027Sjungma@eit.uni-kl.de// This method moves the threads push queue to the pop queue and zeros the push
47412027Sjungma@eit.uni-kl.de// queue. This will only be done if the pop queue is presently empty.
47512027Sjungma@eit.uni-kl.de//------------------------------------------------------------------------------
47612027Sjungma@eit.uni-kl.deinline void sc_runnable::toggle_threads()
47712027Sjungma@eit.uni-kl.de{
47812027Sjungma@eit.uni-kl.de    if ( m_threads_pop == SC_NO_THREADS )
47912027Sjungma@eit.uni-kl.de    {
48012027Sjungma@eit.uni-kl.de	m_threads_pop = m_threads_push_head->next_runnable();
48112027Sjungma@eit.uni-kl.de	m_threads_push_head->set_next_runnable(SC_NO_THREADS);
48212027Sjungma@eit.uni-kl.de	m_threads_push_tail = m_threads_push_head;
48312027Sjungma@eit.uni-kl.de    }
48412027Sjungma@eit.uni-kl.de}
48512027Sjungma@eit.uni-kl.de
48612027Sjungma@eit.uni-kl.de#undef SC_NO_METHODS
48712027Sjungma@eit.uni-kl.de#undef SC_NO_THREADS
48812027Sjungma@eit.uni-kl.de#undef DEBUG_MSG
48912027Sjungma@eit.uni-kl.de
49012027Sjungma@eit.uni-kl.de} // namespace sc_core
49112027Sjungma@eit.uni-kl.de
49212027Sjungma@eit.uni-kl.de
49312027Sjungma@eit.uni-kl.de/*******************************************************************************
49412027Sjungma@eit.uni-kl.de
49512027Sjungma@eit.uni-kl.de  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
49612027Sjungma@eit.uni-kl.de  changes you are making here.
49712027Sjungma@eit.uni-kl.de      Andy Goodrich, Forte Design Systems, 2 September 2003
49812027Sjungma@eit.uni-kl.de      Changed queue heads to instances to eliminate the checks for null heads.
49912027Sjungma@eit.uni-kl.de
50012027Sjungma@eit.uni-kl.de ******************************************************************************/
50112027Sjungma@eit.uni-kl.de
50212027Sjungma@eit.uni-kl.de// $Log: sc_runnable_int.h,v $
50312027Sjungma@eit.uni-kl.de// Revision 1.19  2011/08/24 22:05:51  acg
50412027Sjungma@eit.uni-kl.de//  Torsten Maehne: initialization changes to remove warnings.
50512027Sjungma@eit.uni-kl.de//
50612027Sjungma@eit.uni-kl.de// Revision 1.18  2011/08/07 19:08:04  acg
50712027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved logs to end of file so line number synching works
50812027Sjungma@eit.uni-kl.de//  better between versions.
50912027Sjungma@eit.uni-kl.de//
51012027Sjungma@eit.uni-kl.de// Revision 1.17  2011/04/13 02:45:11  acg
51112027Sjungma@eit.uni-kl.de//  Andy Goodrich: eliminated warning message that occurred if the DEBUG_MSG
51212027Sjungma@eit.uni-kl.de//  macro was used.
51312027Sjungma@eit.uni-kl.de//
51412027Sjungma@eit.uni-kl.de// Revision 1.16  2011/04/10 22:18:23  acg
51512027Sjungma@eit.uni-kl.de//  Andy Goodrich: debugging message clean up.
51612027Sjungma@eit.uni-kl.de//
51712027Sjungma@eit.uni-kl.de// Revision 1.15  2011/04/08 18:26:07  acg
51812027Sjungma@eit.uni-kl.de//  Andy Goodrich: added execute_method_next() to handle method dispatch
51912027Sjungma@eit.uni-kl.de//   for asynchronous notifications that occur outside the evaluation phase.
52012027Sjungma@eit.uni-kl.de//
52112027Sjungma@eit.uni-kl.de// Revision 1.14  2011/04/01 21:31:10  acg
52212027Sjungma@eit.uni-kl.de//  Andy Goodrich: turn off diagnostic messages by default.
52312027Sjungma@eit.uni-kl.de//
52412027Sjungma@eit.uni-kl.de// Revision 1.13  2011/04/01 21:30:02  acg
52512027Sjungma@eit.uni-kl.de//  Andy Goodrich: inserted conditional displays for queue manipulations.
52612027Sjungma@eit.uni-kl.de//
52712027Sjungma@eit.uni-kl.de// Revision 1.12  2011/03/30 00:01:34  acg
52812027Sjungma@eit.uni-kl.de//  Philip A. Hartmann: change break to return in remove_method() to short
52912027Sjungma@eit.uni-kl.de//  circuit the search the way remove_thread() works.
53012027Sjungma@eit.uni-kl.de//
53112027Sjungma@eit.uni-kl.de// Revision 1.11  2011/03/28 13:02:52  acg
53212027Sjungma@eit.uni-kl.de//  Andy Goodrich: Changes for disable() interactions.
53312027Sjungma@eit.uni-kl.de//
53412027Sjungma@eit.uni-kl.de// Revision 1.10  2011/03/06 15:58:17  acg
53512027Sjungma@eit.uni-kl.de//  Andy Goodrich: formatting changes.
53612027Sjungma@eit.uni-kl.de//
53712027Sjungma@eit.uni-kl.de// Revision 1.9  2011/02/18 20:27:14  acg
53812027Sjungma@eit.uni-kl.de//  Andy Goodrich: Updated Copyrights.
53912027Sjungma@eit.uni-kl.de//
54012027Sjungma@eit.uni-kl.de// Revision 1.8  2011/02/13 21:47:38  acg
54112027Sjungma@eit.uni-kl.de//  Andy Goodrich: update copyright notice.
54212027Sjungma@eit.uni-kl.de//
54312027Sjungma@eit.uni-kl.de// Revision 1.7  2011/02/02 06:37:03  acg
54412027Sjungma@eit.uni-kl.de//  Andy Goodrich: removed toggle() method since it is no longer used.
54512027Sjungma@eit.uni-kl.de//
54612027Sjungma@eit.uni-kl.de// Revision 1.6  2011/02/01 21:09:13  acg
54712027Sjungma@eit.uni-kl.de//  Andy Goodrich: addition of toggle_methods() and toggle_threads() calls.
54812027Sjungma@eit.uni-kl.de//
54912027Sjungma@eit.uni-kl.de// Revision 1.5  2011/01/25 20:50:37  acg
55012027Sjungma@eit.uni-kl.de//  Andy Goodrich: changes for IEEE 1666 2011.
55112027Sjungma@eit.uni-kl.de//
55212027Sjungma@eit.uni-kl.de// Revision 1.4  2010/07/22 20:02:33  acg
55312027Sjungma@eit.uni-kl.de//  Andy Goodrich: bug fixes.
55412027Sjungma@eit.uni-kl.de//
55512027Sjungma@eit.uni-kl.de// Revision 1.3  2009/02/28 00:26:58  acg
55612027Sjungma@eit.uni-kl.de//  Andy Goodrich: changed boost name space to sc_boost to allow use with
55712027Sjungma@eit.uni-kl.de//  full boost library applications.
55812027Sjungma@eit.uni-kl.de//
55912027Sjungma@eit.uni-kl.de// Revision 1.2  2008/05/22 17:06:26  acg
56012027Sjungma@eit.uni-kl.de//  Andy Goodrich: updated copyright notice to include 2008.
56112027Sjungma@eit.uni-kl.de//
56212027Sjungma@eit.uni-kl.de// Revision 1.1.1.1  2006/12/15 20:20:05  acg
56312027Sjungma@eit.uni-kl.de// SystemC 2.3
56412027Sjungma@eit.uni-kl.de//
56512027Sjungma@eit.uni-kl.de// Revision 1.4  2006/04/20 17:08:17  acg
56612027Sjungma@eit.uni-kl.de//  Andy Goodrich: 3.0 style process changes.
56712027Sjungma@eit.uni-kl.de//
56812027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:44:30  acg
56912027Sjungma@eit.uni-kl.de// Added $Log to record CVS changes into the source.
57012027Sjungma@eit.uni-kl.de//
57112027Sjungma@eit.uni-kl.de
57212027Sjungma@eit.uni-kl.de#endif // SC_RUNNABLE_INT_H
57312027Sjungma@eit.uni-kl.de
57412027Sjungma@eit.uni-kl.de// Taf!
575