EC_Priority_Dispatching.cpp

Go to the documentation of this file.
00001 // EC_Priority_Dispatching.cpp,v 1.22 2006/03/14 06:14:25 jtc Exp
00002 
00003 #include "orbsvcs/Event/EC_Priority_Dispatching.h"
00004 #include "orbsvcs/Event/EC_Dispatching_Task.h"
00005 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00006 #include "orbsvcs/Event/EC_QOS_Info.h"
00007 
00008 #include "orbsvcs/Event_Service_Constants.h"
00009 #include "orbsvcs/RtecSchedulerC.h"
00010 
00011 #include "ace/Sched_Params.h"
00012 
00013 ACE_RCSID(Event, EC_Priority_Dispatching, "EC_Priority_Dispatching.cpp,v 1.22 2006/03/14 06:14:25 jtc Exp")
00014 
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016 
00017 TAO_EC_Priority_Dispatching::TAO_EC_Priority_Dispatching (TAO_EC_Event_Channel_Base *ec)
00018   :  ntasks_ (0),
00019      tasks_ (0)
00020 {
00021   CORBA::Object_var tmp = ec->scheduler ();
00022   this->scheduler_ = RtecScheduler::Scheduler::_narrow (tmp.in ());
00023 }
00024 
00025 void
00026 TAO_EC_Priority_Dispatching::activate (void)
00027 {
00028   if (this->tasks_ != 0)
00029     return;
00030 
00031   // @@ Query the scheduler to obtain this....
00032   this->ntasks_ = ACE_Scheduler_MAX_PRIORITIES;
00033   ACE_NEW (this->tasks_, TAO_EC_Dispatching_Task*[this->ntasks_]);
00034 
00035   // @@ Query the scheduler to obtain the priorities!
00036   int priority =
00037     (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) +
00038      ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
00039   priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority);
00040 
00041   ACE_DECLARE_NEW_CORBA_ENV;
00042   for (int i = 0; i < this->ntasks_; ++i)
00043     {
00044       ACE_TRY
00045         {
00046           RtecScheduler::Period_t period =
00047             ACE_CU64_TO_CU32 (ACE_Scheduler_Rates[i]);
00048           char buf[128];
00049           ACE_OS::sprintf (buf, "Dispatching_Task-%d.us", period);
00050 
00051           RtecScheduler::handle_t rt_info =
00052             this->scheduler_->create (buf ACE_ENV_ARG_PARAMETER);
00053           ACE_TRY_CHECK;
00054 
00055           this->scheduler_->set (rt_info,
00056                                  RtecScheduler::VERY_LOW_CRITICALITY,
00057                                  0, // worst_cast_execution_time
00058                                  0, // typical_cast_execution_time
00059                                  0, // cached_cast_execution_time
00060                                  period,
00061                                  RtecScheduler::VERY_LOW_IMPORTANCE,
00062                                  0, // quantum
00063                                  1, // threads
00064                                  RtecScheduler::OPERATION
00065                                   ACE_ENV_ARG_PARAMETER);
00066           ACE_TRY_CHECK;
00067         }
00068       ACE_CATCHANY
00069         {
00070           // Ignore exceptions..
00071         }
00072       ACE_ENDTRY;
00073 
00074       ACE_NEW (this->tasks_[i],
00075                TAO_EC_Dispatching_Task (&this->thread_manager_));
00076 
00077       // @@ Query the scheduler to obtain the priority...
00078       long flags = THR_BOUND | THR_SCHED_FIFO;
00079       if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00080         {
00081           flags = THR_BOUND;
00082           priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER,
00083                                                      ACE_SCOPE_THREAD);
00084           if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00085             ACE_ERROR ((LM_ERROR,
00086                         "EC (%P|%t) cannot activate queue %d", i));
00087         }
00088     }
00089 }
00090 
00091 void
00092 TAO_EC_Priority_Dispatching::shutdown (void)
00093 {
00094   if (this->tasks_ == 0)
00095     return;
00096 
00097   for (int i = 0; i < this->ntasks_; ++i)
00098     this->tasks_[i]->putq (new TAO_EC_Shutdown_Task_Command);
00099 
00100   this->thread_manager_.wait ();
00101 
00102   for (int j = 0; j < this->ntasks_; ++j)
00103     delete this->tasks_[j];
00104 
00105   delete[] this->tasks_;
00106   this->tasks_ = 0;
00107 }
00108 
00109 void
00110 TAO_EC_Priority_Dispatching::push (TAO_EC_ProxyPushSupplier* proxy,
00111                                    RtecEventComm::PushConsumer_ptr consumer,
00112                                    const RtecEventComm::EventSet& event,
00113                                    TAO_EC_QOS_Info& qos_info
00114                                    ACE_ENV_ARG_DECL)
00115 {
00116   RtecEventComm::EventSet event_copy = event;
00117   this->push_nocopy (proxy, consumer, event_copy, qos_info ACE_ENV_ARG_PARAMETER);
00118 }
00119 
00120 void
00121 TAO_EC_Priority_Dispatching::push_nocopy (TAO_EC_ProxyPushSupplier* proxy,
00122                                           RtecEventComm::PushConsumer_ptr consumer,
00123                                           RtecEventComm::EventSet& event,
00124                                           TAO_EC_QOS_Info& qos_info
00125                                           ACE_ENV_ARG_DECL)
00126 {
00127   if (this->tasks_ == 0)
00128     this->activate ();
00129 
00130   int i = qos_info.preemption_priority;
00131   if (i < 0 || i >= this->ntasks_)
00132     {
00133       // @@ Throw something?
00134       i = 0;
00135     }
00136 
00137 
00138   this->tasks_[i]->push (proxy, consumer, event ACE_ENV_ARG_PARAMETER);
00139 }
00140 
00141 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:11:08 2006 for TAO_RTEvent by doxygen 1.3.6