⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reconfig_sched_utils.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// ============================================================================
//
// Reconfig_Sched_Utils.cpp,v 1.17 2003/10/13 21:43:26 venkita Exp
//
// ============================================================================
//
// = LIBRARY
//    orbsvcs
//
// = FILENAME
//    Reconfig_Sched_Utils.cpp
//
// = AUTHOR
//     Chris Gill <cdgill@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_RECONFIG_SCHED_UTILS_C
#define TAO_RECONFIG_SCHED_UTILS_C

#include "Reconfig_Sched_Utils_T.h"
#include "Reconfig_Sched_Utils.h"


#include "orbsvcs/Time_Utilities.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#if defined (__ACE_INLINE__)
#include "Reconfig_Sched_Utils.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID (Sched, Reconfig_Sched_Utils, "Reconfig_Sched_Utils.cpp,v 1.17 2003/10/13 21:43:26 venkita Exp")

///////////////////////////
// struct TAO_RT_Info_Ex //
///////////////////////////

// Default Constructor.

TAO_RT_Info_Ex::TAO_RT_Info_Ex ()
{
  // Note: the entry_point string takes care of itself.
  handle = 0;
  criticality = RtecScheduler::VERY_LOW_CRITICALITY;
  worst_case_execution_time = 0;
  typical_execution_time = 0;
  cached_execution_time = 0;
  period = 0;
  importance = RtecScheduler::VERY_LOW_IMPORTANCE;
  quantum = 0;
  threads = 0;
  info_type = RtecScheduler::OPERATION;
  priority = 0;
  preemption_subpriority = 0;
  preemption_priority = 0;
  enabled = RtecScheduler::RT_INFO_ENABLED;
  volatile_token = 0;
}


// Constructor from an RT_Info
// (Also serves as a copy constructor)

TAO_RT_Info_Ex::TAO_RT_Info_Ex (const RtecScheduler::RT_Info &info)
{
  this->entry_point = info.entry_point;
  this->handle = info.handle;
  this->criticality = info.criticality;
  this->worst_case_execution_time = info.worst_case_execution_time;
  this->typical_execution_time = info.typical_execution_time;
  this->cached_execution_time = info.cached_execution_time;
  this->period = info.period;
  this->importance = info.importance;
  this->quantum = info.quantum;
  this->threads = info.threads;
  this->info_type = info.info_type;
  this->priority = info.priority;
  this->preemption_subpriority = info.preemption_subpriority;
  this->preemption_priority = info.preemption_priority;
  this->enabled = info.enabled;  // TODO- rethink?
  this->volatile_token = info.volatile_token;
}


// Destructor.
TAO_RT_Info_Ex::~TAO_RT_Info_Ex ()
{
}


// Assignment operator with an RT_Info on the RHS.

void
TAO_RT_Info_Ex::operator = (const RtecScheduler::RT_Info &info)
{
  // IMPORTANT: we don't copy the name or the handle or the output
  // attributes or the volatile token (entry pointer) or the valid
  // flag.  These can only be copied in the copy ctor at
  // initialization.

  criticality = info.criticality;
  worst_case_execution_time = info.worst_case_execution_time;
  typical_execution_time = info.typical_execution_time;
  cached_execution_time = info.cached_execution_time;
  period = info.period;
  importance = info.importance;
  quantum = info.quantum;
  threads = info.threads;
  info_type = info.info_type;
  enabled = info.enabled;
}


// Resets all data members to initial (invalid) values, and removes
// tuples corresponding to the reset flags.

void
TAO_RT_Info_Ex::reset (u_long reset_flags)
{
  // IMPORTANT: among the input arguments, we only reset the period ...
  // TBD - if execution times etc. can be selected as well, then reset those, e.g.,
  // 
  // criticality = RtecScheduler::VERY_LOW_CRITICALITY;
  // worst_case_execution_time = 0;
  // typical_execution_time = 0;
  // cached_execution_time = 0;
  // importance = RtecScheduler::VERY_LOW_IMPORTANCE;
  // quantum = 0;
  // threads = 0;
  // info_type = RtecScheduler::OPERATION;

  period = 0;

  // ... However, we do reset the output attributes ...

  priority = 0;
  preemption_subpriority = 0;
  preemption_priority = 0;

  // ... and the appropriate tuples associated with the entry.
  TAO_Reconfig_Scheduler_Entry * entry_ptr =
      ACE_LONGLONG_TO_PTR (TAO_Reconfig_Scheduler_Entry *,
                           volatile_token);

  //ACE_DEBUG((LM_DEBUG, "Removing Entries for RT_Info: %d, entry_ptr: %x\n", handle, entry_ptr));
  if (entry_ptr)
    {
      entry_ptr->remove_tuples (reset_flags);
    }
  else
    {
      ACE_ERROR ((LM_ERROR, "Pointer to associated entry is zero."));
    }
}

void
TAO_RT_Info_Ex::enabled_state (RtecScheduler::RT_Info_Enabled_Type_t enabled_in)
{
  TAO_Reconfig_Scheduler_Entry * entry_ptr =
      ACE_LONGLONG_TO_PTR (TAO_Reconfig_Scheduler_Entry *,
                           volatile_token);
  if (entry_ptr)
    {
      this->enabled = enabled_in;
      entry_ptr->enabled_state (enabled_in);
    }
  else
    {
      ACE_ERROR ((LM_ERROR, "Pointer to associated entry is zero."));
    }
}

RtecScheduler::RT_Info_Enabled_Type_t
TAO_RT_Info_Ex::enabled_state ()
{
  return this->enabled;
}



//////////////////////////////
// struct TAO_RT_Info_Tuple //
//////////////////////////////

// Default Constructor.
TAO_RT_Info_Tuple::TAO_RT_Info_Tuple ()
  : rate_index (0)
{
}


// Constructor from an RT_Info.
// (Also serves as a copy constructor)

TAO_RT_Info_Tuple::TAO_RT_Info_Tuple (const RtecScheduler::RT_Info &info)
  : TAO_RT_Info_Ex (info),
    rate_index (0)
{
}

// Destructor.

TAO_RT_Info_Tuple::~TAO_RT_Info_Tuple ()
{
}


// Assignment operator with an RT_Info on the RHS.

void
TAO_RT_Info_Tuple::operator = (const RtecScheduler::RT_Info &info)
{
  ACE_static_cast (TAO_RT_Info_Ex, *this) = info;
}  


// Less-than comparison operator: orders tuples by ascending rate (descending period).

int
TAO_RT_Info_Tuple::operator < (const TAO_RT_Info_Tuple &t)
{
  return (this->period > t.period) ? 1 : 0;
}


////////////////////////////////////////
// class TAO_Reconfig_Scheduler_Entry //
////////////////////////////////////////

// Constructor.

TAO_Reconfig_Scheduler_Entry::
TAO_Reconfig_Scheduler_Entry (TAO_RT_Info_Ex &rt_info)
  : actual_rt_info_ (&rt_info),
    fwd_dfs_status_ (NOT_VISITED),
    rev_dfs_status_ (NOT_VISITED),
    fwd_discovered_ (-1),
    rev_discovered_ (-1),
    fwd_finished_ (-1),
    rev_finished_ (-1),
    is_thread_delineator_ (0),
    has_unresolved_remote_dependencies_ (0),
    has_unresolved_local_dependencies_ (0),
    aggregate_exec_time_ (0),
    orig_tuple_period_sum_ (0),
    prop_tuple_period_sum_ (0),
    orig_tuple_count_ (0),
    prop_tuple_count_ (0),
    current_admitted_tuple_ (0),
    enabled_ (rt_info.enabled)
  //    effective_exec_multiplier_ (0),  //WSOA merge commented out
  //  effective_period_ (0)              //WSOA merge commented out
{
  // Store the RT_Info fields.
  this->orig_rt_info_data (*actual_rt_info_);
}

// Constructor.

TAO_Reconfig_Scheduler_Entry::
~TAO_Reconfig_Scheduler_Entry ()
{
  this->remove_tuples (ORIGINAL | PROPAGATED);
}


// Removes all tuples from the entry.

void
TAO_Reconfig_Scheduler_Entry::
remove_tuples (u_long tuple_flags)
{
  TAO_RT_Info_Tuple **tuple_ptr_ptr;

  if (tuple_flags & ORIGINAL)
    {
      TUPLE_SET_ITERATOR orig_tuple_iter (this->orig_tuple_subset_);

      while (orig_tuple_iter.done () == 0)
        {
          if (orig_tuple_iter.next (tuple_ptr_ptr) == 0
              || tuple_ptr_ptr == 0 || *tuple_ptr_ptr == 0)
	    {
              ACE_ERROR ((LM_ERROR,
                          "Failed to access tuple under iterator"));
              return;
            }

          delete (*tuple_ptr_ptr);

          orig_tuple_iter.advance ();
        }

      this->orig_tuple_subset_.reset ();
    }

  // If either the originals or the propagated tuple pointers are to
  // be removed, we have to get rid of the propagated pointers lest
  // they become handles to access violations after the original
  // tuples are destroyed.
  if (tuple_flags & PROPAGATED
      || tuple_flags & ORIGINAL)
    {
      this->prop_tuple_subset_.reset ();
    }
}


// Adds a new tuple to the entry and updates the
// rate indices and mean rate for the tuples.

int
TAO_Reconfig_Scheduler_Entry::
insert_tuple (TAO_RT_Info_Tuple &tuple,
              Tuple_Type tuple_type,
              int replace)
{
  // Choose the appropriate tuple subset.
  TUPLE_SET *set_ptr = (tuple_type == ORIGINAL) ? & orig_tuple_subset_ : & prop_tuple_subset_;

  // Recompute rate indices.

  tuple.rate_index = 0;
  TAO_RT_Info_Tuple **tuple_ptr_ptr;

  TUPLE_SET_ITERATOR tuple_iter (*set_ptr);

  while (tuple_iter.done () == 0)
    {
      // Get a pointer to the tuple under the iterator.
      if (tuple_iter.next (tuple_ptr_ptr) == 0
          || tuple_ptr_ptr == 0 || *tuple_ptr_ptr == 0)
	{
          ACE_ERROR_RETURN ((LM_ERROR, "Failed to access tuple under iterator"), -1);
	}

      // Update existing tuples
      if ((*tuple_ptr_ptr)->period > tuple.period)
	{
          // Move the tuple's rate index higher than any in the set
          // with lower rates.
          ++tuple.rate_index;
	}
      else if (replace && (*tuple_ptr_ptr)->period == tuple.period)
        {
          // If the replace flag is set, and there is already a tuple
          // with the same rate in the set, just update that tuple and
          // return.
          **tuple_ptr_ptr = tuple;
          return 1;
        }
      else
	{
          // Otherwise, just update the rate index of the subsequent
          // tuples, which have the same or higher rates.
          ++(*tuple_ptr_ptr)->rate_index;
	}

      tuple_iter.advance ();
    }

  // Update aggregate rate data, insert the tuple
  if (tuple_type == ORIGINAL)
    {
      this->orig_tuple_period_sum_ += tuple.period;
      ++this->orig_tuple_count_;
      return (this->orig_tuple_subset_.insert (&tuple) < 0) ? -1 : 0;
    }
  else
    {
      this->prop_tuple_period_sum_ += tuple.period;
      ++this->prop_tuple_count_;
      return (this->prop_tuple_subset_.insert (&tuple) < 0) ? -1 : 0;
    }
}


// Updates a matching tuple.

int
TAO_Reconfig_Scheduler_Entry::
update_tuple (TAO_RT_Info_Ex &info,
              Tuple_Type tuple_type)
{
  // Choose the appropriate tuple subset.
  TUPLE_SET *set_ptr = (tuple_type == ORIGINAL) ? & orig_tuple_subset_ : & prop_tuple_subset_;

  // Find and update the first matching tuple, if any.

  TAO_RT_Info_Tuple **tuple_ptr_ptr;
  TUPLE_SET_ITERATOR tuple_iter (*set_ptr);

  while (tuple_iter.done () == 0)
    {
      // Get a pointer to the tuple under the iterator.
      if (tuple_iter.next (tuple_ptr_ptr) == 0
          || tuple_ptr_ptr == 0 || *tuple_ptr_ptr == 0)
	{
          ACE_ERROR_RETURN ((LM_ERROR, "Failed to access tuple under iterator"), -1);
	}
      else if ((*tuple_ptr_ptr)->period < info.period)
	{
          // If we've hit a tuple with a shorter period (higher rate),
          // then we're done.
          break;
	}
      else if ((*tuple_ptr_ptr)->period == info.period)
        {
          // If the replace flag is set, and there is already a tuple
          // with the same rate in the set, just update that tuple and
          // return.
          **tuple_ptr_ptr = info;
          return 1;
        }

      tuple_iter.advance ();
    }

  return 0;
}


// Registers tuples into the passed tuple pointer array.
int
TAO_Reconfig_Scheduler_Entry::
register_tuples (TAO_RT_Info_Tuple ** tuple_ptr_array,
                 long &tuple_count)
{
  // Iterate over the tuples, adding them to the pointer array.

  TAO_RT_Info_Tuple **tuple_ptr_ptr;
  TUPLE_SET_ITERATOR tuple_iter (orig_tuple_subset_);

  while (tuple_iter.done () == 0)
    {
      // Get a pointer to the tuple under the iterator.
      if (tuple_iter.next (tuple_ptr_ptr) == 0
          || tuple_ptr_ptr == 0 || *tuple_ptr_ptr == 0)
	{
          ACE_ERROR_RETURN ((LM_ERROR, "Failed to access tuple under iterator"), -1);
	}
      else
	{
          tuple_ptr_array [tuple_count] = *tuple_ptr_ptr;
          ++tuple_count;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -