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

📄 scheduler_factory.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// Scheduler_Factory.cpp,v 1.40 2003/10/13 21:43:26 venkita Exp

#include "ace/OS.h"
#include "ace/Singleton.h"
#include "ace/Null_Mutex.h"

#include "orbsvcs/Runtime_Scheduler.h"
#include "orbsvcs/Sched/Reconfig_Scheduler.h"
#include "orbsvcs/Sched/Reconfig_Sched_Utils.h"
#include "orbsvcs/Scheduler_Factory.h"

#if ! defined (__ACE_INLINE__)
#include "orbsvcs/Scheduler_Factory.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID(orbsvcs,
          Scheduler_Factory,
          "Scheduler_Factory.cpp,v 1.40 2003/10/13 21:43:26 venkita Exp")

// Initialize static class members.
RtecScheduler::Scheduler_ptr ACE_Scheduler_Factory::server_ = 0;
ACE_Scheduler_Factory::Factory_Status ACE_Scheduler_Factory::status_ =
  ACE_Scheduler_Factory::UNINITIALIZED;


RtecScheduler::Period_t ACE_Scheduler_Factory::period_default_ = 0;
RtecScheduler::Threads_t ACE_Scheduler_Factory::threads_default_ = 0;
RtecScheduler::Importance_t ACE_Scheduler_Factory::importance_default_ = RtecScheduler::MEDIUM_IMPORTANCE;
RtecScheduler::Criticality_t ACE_Scheduler_Factory::criticality_default_ = RtecScheduler::HIGH_CRITICALITY;
RtecScheduler::RT_Info_Enabled_Type_t ACE_Scheduler_Factory::rt_info_enable_state_default_ = RtecScheduler::RT_INFO_NON_VOLATILE;

RtecScheduler::Period_t ACE_Scheduler_Factory::period_default()
{
   return period_default_;
}

RtecScheduler::Threads_t ACE_Scheduler_Factory::threads_default()
{
   return threads_default_;
}

RtecScheduler::Importance_t ACE_Scheduler_Factory::importance_default()
{
   return importance_default_;
}

RtecScheduler::Criticality_t ACE_Scheduler_Factory::criticality_default()
{
   return criticality_default_;
}

void ACE_Scheduler_Factory::period_default(RtecScheduler::Period_t period_default)
{
   period_default_ = period_default;
}

void ACE_Scheduler_Factory::threads_default(RtecScheduler::Threads_t threads_default)
{
   threads_default_ = threads_default;
}

void ACE_Scheduler_Factory::importance_default(RtecScheduler::Importance_t importance_default)
{
   importance_default_ = importance_default;
}

void ACE_Scheduler_Factory::criticality_default(RtecScheduler::Criticality_t criticality_default)
{
   criticality_default_ = criticality_default;
}

RtecScheduler::RT_Info_Enabled_Type_t ACE_Scheduler_Factory::rt_info_enable_state_default()
{
   return rt_info_enable_state_default_;
}

void ACE_Scheduler_Factory::rt_info_enable_state_default(RtecScheduler::RT_Info_Enabled_Type_t rt_info_enable_state_default)
{
   rt_info_enable_state_default_ = rt_info_enable_state_default;
}

// This symbols are extern because the automatic template
// instantiation mechanism in SunCC gets confused otherwise.
int TAO_SF_config_count = -1;
ACE_Scheduler_Factory::POD_Config_Info* TAO_SF_config_info = 0;
int TAO_SF_entry_count = -1;
ACE_Scheduler_Factory::POD_RT_Info* TAO_SF_rt_info = 0;
int TAO_SF_dependency_count = -1;
ACE_Scheduler_Factory::POD_Dependency_Info* TAO_SF_dep_info = 0;

struct ACE_Scheduler_Factory_Data
{
  // = TITLE
  //   Helper struct, to encapsulate the singleton static server and
  //   ACE_TSS objects.  We can't use ACE_Singleton directly, because
  //   construction of ACE_Runtime_Scheduler takes arguments.

/* WSOA merge - commented out 
  ACE_Runtime_Scheduler scheduler_;
  // The static runtime scheduler.
*/
  
  TAO_Reconfig_Scheduler<TAO_MUF_FAIR_Reconfig_Sched_Strategy, ACE_SYNCH_MUTEX> scheduler_;
  // The scheduler.

  ACE_TSS<ACE_TSS_Type_Adapter<RtecScheduler::Preemption_Priority_t> >
  preemption_priority_;
  // The dispatch queue number of the calling thread.  For access by
  // applications; must be set by either the application or Event
  // Channel.

  ACE_Scheduler_Factory_Data (void)
    : scheduler_ (TAO_SF_config_count,
                  TAO_SF_config_info,
                  TAO_SF_entry_count,
                  TAO_SF_rt_info, 
                  TAO_SF_dependency_count,
                  TAO_SF_dep_info,
                  0),
      preemption_priority_ ()
  {
  }
};

static ACE_Scheduler_Factory_Data *ace_scheduler_factory_data = 0;

int ACE_Scheduler_Factory::use_runtime (int cc,
                                        POD_Config_Info cfgi[],
                                        int ec,
                                        POD_RT_Info rti[])
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_LIB_TEXT("ACE_Scheduler_Factory::use_runtime - ")
                       ACE_LIB_TEXT("server already configured\n")),
                      -1);
  TAO_SF_config_count = cc;
  TAO_SF_config_info = cfgi;
  TAO_SF_entry_count = ec;
  TAO_SF_rt_info = rti;
  status_ = ACE_Scheduler_Factory::RUNTIME;

  return 0;
}

static RtecScheduler::Scheduler_ptr
static_server (void)
{
  RtecScheduler::Scheduler_ptr server_ = 0;

  // This isn't thread safe, but the static instance that it replaces
  // wasn't thread safe either.  Hola, Sr. Sandiego :-) If it needs to
  // be made thread safe, it should be protected using double-checked
  // locking.
  if (! ace_scheduler_factory_data  &&
      (ace_scheduler_factory_data =
         ACE_Singleton<ACE_Scheduler_Factory_Data,
                       ACE_Null_Mutex>::instance ()) == 0)
        return 0;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      server_ = ace_scheduler_factory_data->scheduler_._this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                  ACE_LIB_TEXT("ACE_Scheduler_Factory - configured static server\n")));
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           ACE_LIB_TEXT("ACE_Scheduler_Factory::config_runtime - ")
                           ACE_LIB_TEXT("cannot allocate server\n"));
    }
  ACE_ENDTRY;

  return server_;
}

int
ACE_Scheduler_Factory::use_config (CosNaming::NamingContext_ptr naming)
{
  return ACE_Scheduler_Factory::use_config (naming,
                                            "ScheduleService");
}

int
ACE_Scheduler_Factory::use_config (CosNaming::NamingContext_ptr naming,
                                   const char* name)
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    // No errors, runtime execution simply takes precedence over
    // config runs.
    return 0;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      CosNaming::Name schedule_name (1);
      schedule_name.length (1);
      schedule_name[0].id = CORBA::string_dup (name);
      CORBA::Object_var objref =
        naming->resolve (schedule_name
                         ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      server_ =
        RtecScheduler::Scheduler::_narrow(objref.in ()
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      server_ = 0;
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           ACE_LIB_TEXT("ACE_Scheduler_Factory::use_config - ")
                           ACE_LIB_TEXT(" exception while resolving server\n"));
    }
  ACE_ENDTRY;

  status_ = ACE_Scheduler_Factory::CONFIG;
  return 0;
}

int
ACE_Scheduler_Factory::server (RtecScheduler::Scheduler_ptr sptr)
{
  if (server_ != 0 || TAO_SF_entry_count != -1)
    return -1;

  server_ = RtecScheduler::Scheduler::_duplicate (sptr);
  return 0;
}

RtecScheduler::Scheduler_ptr
ACE_Scheduler_Factory::server (void)
{
  if (server_ == 0 && TAO_SF_entry_count != -1)
    server_ = static_server ();

  if (server_ == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_LIB_TEXT("ACE_Scheduler_Factor::server - ")
                       ACE_LIB_TEXT("no scheduling service configured\n")),
                      0);
  return server_;
}

static char header[] =
"// $Id $\n\n"
"// This file was automatically generated by the Scheduler_Factory.\n"
"// Before editing the file please consider generating it again.\n"
"\n"
"#include \"orbsvcs/Scheduler_Factory.h\"\n"
"\n";

static char footer[] =
"\n"
"// This sets up Scheduler_Factory to use the runtime version.\n"
"int scheduler_factory_setup = \n"
"  ACE_Scheduler_Factory::use_runtime (configs_size, configs, infos_size, infos);\n"
"\n"
"// EOF\n";

static char start_anomalies_found[] =
"\n// The following scheduling anomalies were detected:\n";

static char start_anomalies_none[] =
"\n// There were no scheduling anomalies.\n";

static char start_infos[] =
"\n\nstatic ACE_Scheduler_Factory::POD_RT_Info infos[] = {\n";

static char end_infos[] =
"};\n\n"
"static int infos_size = sizeof(infos)/sizeof(infos[0]);\n\n";

static char end_infos_empty[] =
"};\n\n"
"static int infos_size = 0;\n\n";

static char start_dependencies[] =
"\n\nstatic ACE_Scheduler_Factory::POD_Dependency_Info dependencies[] = {\n";

static char end_dependencies[] =
"};\n\n"
"static int dependencies_size = sizeof(dependencies)/sizeof(dependencies[0]);\n\n";

static char end_dependencies_empty[] =
"};\n\n"
"static int dependencies_size = 0;\n\n";

static char start_configs[] =
"\nstatic ACE_Scheduler_Factory::POD_Config_Info configs[] = {\n";

static char end_configs[] =
"};\n\n"

⌨️ 快捷键说明

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