00001
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, "$Id: EC_Priority_Dispatching.cpp 76626 2007-01-26 13:50:03Z elliott_c $")
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
00032 this->ntasks_ = ACE_Scheduler_MAX_PRIORITIES;
00033 ACE_NEW (this->tasks_, TAO_EC_Dispatching_Task*[this->ntasks_]);
00034
00035
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 for (int i = 0; i < this->ntasks_; ++i)
00042 {
00043 try
00044 {
00045 RtecScheduler::Period_t period =
00046 ACE_CU64_TO_CU32 (ACE_Scheduler_Rates[i]);
00047 char buf[128];
00048 ACE_OS::sprintf (buf, "Dispatching_Task-%d.us", period);
00049
00050 RtecScheduler::handle_t rt_info =
00051 this->scheduler_->create (buf);
00052
00053 this->scheduler_->set (rt_info,
00054 RtecScheduler::VERY_LOW_CRITICALITY,
00055 0,
00056 0,
00057 0,
00058 period,
00059 RtecScheduler::VERY_LOW_IMPORTANCE,
00060 0,
00061 1,
00062 RtecScheduler::OPERATION);
00063 }
00064 catch (const CORBA::Exception&)
00065 {
00066
00067 }
00068
00069 ACE_NEW (this->tasks_[i],
00070 TAO_EC_Dispatching_Task (&this->thread_manager_));
00071
00072
00073 long flags = THR_BOUND | THR_SCHED_FIFO;
00074 if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00075 {
00076 flags = THR_BOUND;
00077 priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER,
00078 ACE_SCOPE_THREAD);
00079 if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00080 ACE_ERROR ((LM_ERROR,
00081 "EC (%P|%t) cannot activate queue %d", i));
00082 }
00083 }
00084 }
00085
00086 void
00087 TAO_EC_Priority_Dispatching::shutdown (void)
00088 {
00089 if (this->tasks_ == 0)
00090 return;
00091
00092 for (int i = 0; i < this->ntasks_; ++i)
00093 this->tasks_[i]->putq (new TAO_EC_Shutdown_Task_Command);
00094
00095 this->thread_manager_.wait ();
00096
00097 for (int j = 0; j < this->ntasks_; ++j)
00098 delete this->tasks_[j];
00099
00100 delete[] this->tasks_;
00101 this->tasks_ = 0;
00102 }
00103
00104 void
00105 TAO_EC_Priority_Dispatching::push (TAO_EC_ProxyPushSupplier* proxy,
00106 RtecEventComm::PushConsumer_ptr consumer,
00107 const RtecEventComm::EventSet& event,
00108 TAO_EC_QOS_Info& qos_info)
00109 {
00110 RtecEventComm::EventSet event_copy = event;
00111 this->push_nocopy (proxy, consumer, event_copy, qos_info);
00112 }
00113
00114 void
00115 TAO_EC_Priority_Dispatching::push_nocopy (TAO_EC_ProxyPushSupplier* proxy,
00116 RtecEventComm::PushConsumer_ptr consumer,
00117 RtecEventComm::EventSet& event,
00118 TAO_EC_QOS_Info& qos_info)
00119 {
00120 if (this->tasks_ == 0)
00121 this->activate ();
00122
00123 int i = qos_info.preemption_priority;
00124 if (i < 0 || i >= this->ntasks_)
00125 {
00126
00127 i = 0;
00128 }
00129
00130
00131 this->tasks_[i]->push (proxy, consumer, event);
00132 }
00133
00134 TAO_END_VERSIONED_NAMESPACE_DECL