diff options
author | venkita <venkita@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-25 23:41:55 +0000 |
---|---|---|
committer | venkita <venkita@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-25 23:41:55 +0000 |
commit | 4f9008d582eca63957fa9805ac46425f8baf475a (patch) | |
tree | 0c2d30977f52d7860362ff76b28ecc4d9a158421 | |
parent | 540f1412da766da7f25aed420b518e1f372b69bf (diff) | |
download | ATCD-4f9008d582eca63957fa9805ac46425f8baf475a.tar.gz |
ChangeLogTag: Fri Jul 25 17:41:08 2003 Venkita Subramonian <venkita@cse.wustl.edu>
36 files changed, 2459 insertions, 940 deletions
diff --git a/Kokyu/DSRT_Direct_Dispatcher_Impl_T.cpp b/Kokyu/DSRT_Direct_Dispatcher_Impl_T.cpp new file mode 100644 index 00000000000..f92457eee77 --- /dev/null +++ b/Kokyu/DSRT_Direct_Dispatcher_Impl_T.cpp @@ -0,0 +1,278 @@ +// $Id$ + +#ifndef DSRT_DIRECT_DISPATCHER_IMPL_T_CPP +#define DSRT_DIRECT_DISPATCHER_IMPL_T_CPP + +#include "DSRT_Direct_Dispatcher_Impl_T.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#if !defined (__ACE_INLINE__) +//#include "DSRT_Direct_Dispatcher_Impl_T.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, DSRT_Direct_Dispatcher_Impl_T, "$Id$") + +namespace Kokyu +{ +template <class DSRT_Scheduler_Traits> +int Comparator_Adapter_Generator<DSRT_Scheduler_Traits>::MoreEligible:: +operator ()(const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item1, + const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item2) +{ + int rc = qos_comparator_ (item1->qos (), item2->qos ()); + + //more eligible + if (rc == 1) + return 1; + + //if equally eligible, then resolve tie with the creation time of + //the item + if (rc == 0 && item1->insertion_time () < item2->insertion_time ()) + return 1; + + return 0; +} + +template <class DSRT_Scheduler_Traits> +DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +DSRT_Direct_Dispatcher_Impl () + :min_prio_ (ACE_Sched_Params::priority_min + (ACE_SCHED_FIFO, + ACE_SCOPE_THREAD)), + max_prio_ (ACE_Sched_Params::priority_max + (ACE_SCHED_FIFO, + ACE_SCOPE_THREAD)), + executive_prio_ (max_prio_), + blocked_prio_ (ACE_Sched_Params::previous_priority + (ACE_SCHED_FIFO, + max_prio_, + ACE_SCOPE_THREAD)), + inactive_prio_ (min_prio_), + active_prio_ (ACE_Sched_Params::next_priority + (ACE_SCHED_FIFO, + min_prio_)), + curr_scheduled_thr_handle_ (0), + sched_queue_modified_ (0), + sched_queue_modified_cond_ (sched_queue_modified_cond_lock_), + shutdown_flagged_ (0) +{ + + long flags = + THR_NEW_LWP | + THR_JOINABLE | + THR_BOUND | + THR_SCHED_FIFO; + + //Run scheduler thread at highest priority + if (this->activate (flags, 1, 0, executive_prio_) == -1) + { + flags = THR_NEW_LWP | THR_JOINABLE | THR_BOUND; + if (this->activate (flags) == -1) + ACE_ERROR ((LM_ERROR, + "EC (%P|%t) cannot activate scheduler thread\n")); + } +} + +template <class DSRT_Scheduler_Traits> int +DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +init_i (const DSRT_ConfigInfo&) +{ + return 0; +} + +template <class DSRT_Scheduler_Traits> int +DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>::svc (void) +{ + int prio; + ACE_hthread_t scheduler_thr_handle; + ACE_Thread::self (scheduler_thr_handle); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("max prio=%d\n") + ACE_TEXT ("min prio=%d\n") + ACE_TEXT ("active prio=%d\n") + ACE_TEXT ("inactive prio=%d\n"), + max_prio_, + min_prio_, + active_prio_, + inactive_prio_)); + + if (ACE_Thread::getprio (scheduler_thr_handle, prio) == -1) + { + if (errno == ENOTSUP) + { + ACE_ERROR((LM_ERROR, + ACE_TEXT ("getprio not supported\n") + )); + } + else + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n") + ACE_TEXT ("thr_getprio failed"))); + } + } + + ACE_DEBUG ((LM_DEBUG, "(%t): Scheduler thread prio is %d\n", prio)); + + while(1) + { + ACE_GUARD_RETURN (cond_lock_t, + mon, sched_queue_modified_cond_lock_, 0); + + if (shutdown_flagged_) + break; + + while (!sched_queue_modified_) + { + ACE_DEBUG ((LM_DEBUG, + "(%t): sched thread about to wait on cv\n")); + sched_queue_modified_cond_.wait (); + } + ACE_DEBUG ((LM_DEBUG, "(%t): sched thread done waiting on cv\n")); + + sched_queue_modified_ = 0; + + if (ready_queue_.current_size () <= 0) + continue; + + ready_queue_.dump (); + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> item_var; + ready_queue_.most_eligible (item_var); + + ACE_hthread_t most_eligible_thread = item_var->thread_handle (); + /* + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%t): most eligible thread guid = %d\n"), + item_var->guid ())); + */ + if (curr_scheduled_thr_handle_ != most_eligible_thread) + { + ACE_OS::thr_setprio (curr_scheduled_thr_handle_, + inactive_prio_); + ACE_OS::thr_setprio (most_eligible_thread, active_prio_); + curr_scheduled_thr_handle_ = most_eligible_thread; + curr_scheduled_guid_ = item_var->guid (); + } + } + + ACE_DEBUG ((LM_DEBUG, "(%t): sched thread exiting\n")); + return 0; +} + +template <class DSRT_Scheduler_Traits> +int DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +schedule_i (Guid_t id, const DSRT_QoSDescriptor& qos) +{ + //@@ Perhaps the lock could be moved further down just before + //setting the condition variable? + ACE_GUARD_RETURN (cond_lock_t, + mon, sched_queue_modified_cond_lock_, 0); + if (ready_queue_.insert (id, qos) == -1) + return -1; + + ACE_hthread_t thr_handle; + ACE_Thread::self (thr_handle); + + if (ACE_OS::thr_setprio (thr_handle, inactive_prio_) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("thr_setprio failed")), + -1); + } + + ready_queue_.dump (); + + sched_queue_modified_ = 1; + sched_queue_modified_cond_.signal (); + return 0; +} + +template <class DSRT_Scheduler_Traits> +int DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +update_schedule_i (Guid_t guid, const DSRT_QoSDescriptor& qos) +{ + return this->schedule (guid, qos); +} + +template <class DSRT_Scheduler_Traits> +int DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +update_schedule_i (Guid_t guid, Block_Flag_t flag) +{ + ACE_DEBUG ((LM_DEBUG, "(%t): update schedule for block entered\n")); + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> dispatch_item; + ACE_hthread_t thr_handle; + //@@ Perhaps the lock could be got rid of. It looks like the state + //of this object is not getting modified here. It makes calls to + //other methods, which already are thread-safe. + ACE_Guard<cond_lock_t> mon(sched_queue_modified_cond_lock_); + + int found = this->ready_queue_.find (guid, dispatch_item); + if (found == 0 && flag == BLOCK) + { + thr_handle = dispatch_item->thread_handle (); + ACE_OS::thr_setprio (thr_handle, blocked_prio_); + + //monitor released because cancel_schedule would acquire the + //lock. Using recursive mutex creates lock up. + // + //@@ Need to investigate this further. Also we can consider + //using the Thread-Safe interface pattern. + mon.release (); + int rc = this->cancel_schedule (guid); + ACE_DEBUG ((LM_DEBUG, "(%t): update schedule for block done\n")); + return rc; + } + + ACE_DEBUG ((LM_DEBUG, "(%t): update schedule for block done\n")); + return -1; +} + +template <class DSRT_Scheduler_Traits> int +DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +cancel_schedule_i (Guid_t guid) +{ + //@@ Perhaps the lock could be moved further down? + ACE_GUARD_RETURN (cond_lock_t, + mon, sched_queue_modified_cond_lock_, 0); + ready_queue_.dump (); + ACE_DEBUG ((LM_DEBUG, "(%t): about to remove guid\n")); + ready_queue_.remove (guid); + ready_queue_.dump (); + + if (curr_scheduled_guid_ == guid) + { + curr_scheduled_guid_ = 0; + curr_scheduled_thr_handle_ = 0; + } + + sched_queue_modified_ = 1; + sched_queue_modified_cond_.signal (); + return 0; +} + +template <class DSRT_Scheduler_Traits> int +DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +shutdown_i () +{ + ACE_Guard<cond_lock_t> mon(sched_queue_modified_cond_lock_); + shutdown_flagged_ = 1; + sched_queue_modified_ = 1; + sched_queue_modified_cond_.signal (); + // We have to wait until the scheduler executive thread shuts + // down. But we have acquired the lock and if we wait without + // releasing it, the scheduler thread will try to acquire it after + // it gets woken up by the above signal and it fails to acquire the + // lock. This will lead to a deadlock. So release the lock before we + // wait. + mon.release (); + this->wait (); + return 0; +} + +} + +#endif /* DSRT_DIRECT_DISPATCHER_IMPL_T_CPP */ diff --git a/Kokyu/DSRT_Direct_Dispatcher_Impl_T.h b/Kokyu/DSRT_Direct_Dispatcher_Impl_T.h new file mode 100644 index 00000000000..f5241302945 --- /dev/null +++ b/Kokyu/DSRT_Direct_Dispatcher_Impl_T.h @@ -0,0 +1,163 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Direct_Dispatcher_Impl_T.h + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +#ifndef DSRT_DIRECT_DISPATCHER_IMPL_T_H +#define DSRT_DIRECT_DISPATCHER_IMPL_T_H +#include "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Kokyu_dsrt.h" +#include "DSRT_Sched_Queue_T.h" +#include "DSRT_Dispatcher_Impl_T.h" + +namespace Kokyu +{ + /** + * @class Comparator_Adapter_Generator + * + * @brief Generates function object adapter that adapts the + * QoSComparator function object to compare between two schedulable + * items instead of QoSDescriptors. + * + * The QoSComparator function object that gets passed through the + * <code> DSRT_Scheduler_Traits </code> takes two qos values and + * determines the more eligible one. Since the INT_ID (key) for + * RB_Tree needs to be of type <code> DSRT_Dispatch_Item_var + * </code>, the QoSComparator needs to be adapted using an adapter + * to compare two schedulable items. This adapter compares the two + * using their qos values. Ties are resolved by giving preference to + * items which arrived earlier. Note that this class serves the + * purpose of a generator class, since it generates the adapter + * class for a given qos comparator function object. + */ + + template <class DSRT_Scheduler_Traits> + class Comparator_Adapter_Generator + { + public: + typedef typename + DSRT_Scheduler_Traits::QoSComparator_t QoSComparator_t; + + /** + * @class More_Eligible + * + * @brief Actual function object that gets generated. + */ + class MoreEligible + { + public: + /** + * Function call operator to do comparison between two + * schedulable items. Returns 1 if item1 is more eligible than + * item2, otherwise 0. + */ + int operator () + (const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item1, + const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item2); + + private: + QoSComparator_t qos_comparator_; + }; + + /** + * Facilitates return of the generated function object adapter. + */ + typedef MoreEligible RET; + }; + + template<class DSRT_Scheduler_Traits> + class DSRT_Direct_Dispatcher_Impl : + public ACE_Task_Base, + public DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>, + public non_copyable + { + public: + typedef typename + DSRT_Scheduler_Traits::Guid_t Guid_t; + + typedef typename + DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor; + + DSRT_Direct_Dispatcher_Impl (); + + int init_i (const DSRT_ConfigInfo&); + + /// Schedule a thread dynamically based on the qos info supplied. + int schedule_i (Guid_t, const DSRT_QoSDescriptor&); + + /// Update the schedule for a thread. This could alter the current + /// schedule. + int update_schedule_i (Guid_t, const DSRT_QoSDescriptor&); + + /// Inform the scheduler that the caller thread is about to + /// block. This could alter the current schedule. + int update_schedule_i (Guid_t, Block_Flag_t); + + /// Cancel the schedule for a thread. This could alter the current + /// schedule. + int cancel_schedule_i (Guid_t); + + /// Shut down the dispatcher. The dispatcher will stop processing + /// requests. + int shutdown_i (); + + private: + + /// Generate the QoSComparator adapter. + typedef typename + Comparator_Adapter_Generator<DSRT_Scheduler_Traits>::RET + Queue_Item_Comparator_t; + + typedef Sched_Ready_Queue<DSRT_Scheduler_Traits, + Queue_Item_Comparator_t, + ACE_SYNCH_NULL_MUTEX> + DSRT_Sched_Queue; + + typedef ACE_SYNCH_MUTEX cond_lock_t; + typedef ACE_SYNCH_CONDITION cond_t; + + Priority_t min_prio_; + Priority_t max_prio_; + Priority_t executive_prio_; + Priority_t blocked_prio_; + Priority_t inactive_prio_; + Priority_t active_prio_; + ACE_hthread_t curr_scheduled_thr_handle_; + Guid_t curr_scheduled_guid_; + DSRT_Sched_Queue ready_queue_; + u_int sched_queue_modified_; + cond_lock_t sched_queue_modified_cond_lock_; + cond_t sched_queue_modified_cond_; + int shutdown_flagged_; + + private: + int svc (void); + }; + +} + +#if !defined (__ACE_INLINE__) +//#include "DSRT_Direct_Dispatcher_Impl_T.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "DSRT_Direct_Dispatcher_Impl_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("DSRT_Direct_Dispatcher_Impl_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* DSRT_DIRECT_DISPATCHER_IMPL_T_H */ diff --git a/Kokyu/DSRT_Dispatch_Item_T.cpp b/Kokyu/DSRT_Dispatch_Item_T.cpp new file mode 100644 index 00000000000..b2cc29fa788 --- /dev/null +++ b/Kokyu/DSRT_Dispatch_Item_T.cpp @@ -0,0 +1,35 @@ +// $Id$ + +#ifndef DSRT_DISPATCH_ITEM_T_CPP +#define DSRT_DISPATCH_ITEM_T_CPP + +#include "DSRT_Dispatch_Item_T.h" + +#if ! defined (__ACE_INLINE__) +#include "DSRT_Dispatch_Item_T.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, DSRT_Dispatch_Item, "$Id$") + +namespace Kokyu +{ + +template <class DSRT_Scheduler_Traits> +DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>:: +DSRT_Dispatch_Item_var (DSRT_Dispatch_Item<DSRT_Scheduler_Traits> *p) + :ACE_Strong_Bound_Ptr<DSRT_Dispatch_Item<DSRT_Scheduler_Traits>, + ACE_SYNCH_MUTEX> (p) +{ +} + +template <class DSRT_Scheduler_Traits> +DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>:: +DSRT_Dispatch_Item_var (const DSRT_Dispatch_Item_var &r) + :ACE_Strong_Bound_Ptr<DSRT_Dispatch_Item<DSRT_Scheduler_Traits>, + ACE_SYNCH_MUTEX> (r) +{ +} + +} + +#endif /* DSRT_DISPATCH_ITEM_T_CPP */ diff --git a/Kokyu/DSRT_Dispatch_Item_T.h b/Kokyu/DSRT_Dispatch_Item_T.h new file mode 100644 index 00000000000..727920ef187 --- /dev/null +++ b/Kokyu/DSRT_Dispatch_Item_T.h @@ -0,0 +1,102 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Dispatch_Item.h + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +#ifndef DSRT_DISPATCH_ITEM_H +#define DSRT_DISPATCH_ITEM_H +#include "ace/pre.h" +#include "ace/Bound_Ptr.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Kokyu_dsrt.h" + +namespace Kokyu +{ + /** + * @class DSRT_Dispatch_Item + * + * @brief This stores information about a schedulable thread. + */ + + template <class DSRT_Scheduler_Traits> + class DSRT_Dispatch_Item : private non_copyable + { + typedef typename + DSRT_Scheduler_Traits::Guid_t Guid_t; + + typedef typename + DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor; + + protected: + ACE_hthread_t thr_handle_; + Guid_t guid_; + DSRT_QoSDescriptor qos_; + ACE_Time_Value insertion_time_; + + public: + DSRT_Dispatch_Item (Guid_t guid, const DSRT_QoSDescriptor&); + + /// Get the guid. + Guid_t guid (); + + /// Get the associated qos value. + DSRT_QoSDescriptor qos (); + + /// Get the thread handle. + ACE_hthread_t thread_handle (); + + /// Set the thread handle. + void thread_handle (ACE_hthread_t &handle); + + /// Get the insertion time. + ACE_Time_Value insertion_time (); + + /// Set the insertion time. + void insertion_time (const ACE_Time_Value&); + }; + + /** + * @class DSRT_Dispatch_Item_var + * + * @brief Smart pointer to dynamically allocated <code> + * DSRT_Dispatch_Item </code> objects. + */ + template <class DSRT_Scheduler_Traits> + class DSRT_Dispatch_Item_var : + public ACE_Strong_Bound_Ptr< + DSRT_Dispatch_Item<DSRT_Scheduler_Traits>, + ACE_SYNCH_MUTEX> + { + public: + ACE_EXPLICIT + DSRT_Dispatch_Item_var (DSRT_Dispatch_Item<DSRT_Scheduler_Traits> + *p = 0); + + DSRT_Dispatch_Item_var ( + const DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> &r); + }; +} + +#if defined (__ACE_INLINE__) +#include "DSRT_Dispatch_Item_T.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "DSRT_Dispatch_Item_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("DSRT_Dispatch_Item_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* DSRT_DISPATCH_ITEM_H */ diff --git a/Kokyu/DSRT_Dispatch_Item_T.i b/Kokyu/DSRT_Dispatch_Item_T.i new file mode 100644 index 00000000000..88887cf3ce3 --- /dev/null +++ b/Kokyu/DSRT_Dispatch_Item_T.i @@ -0,0 +1,70 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Dispatch_Item.i + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +namespace Kokyu +{ + +template <class DSRT_Scheduler_Traits> +ACE_INLINE +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +DSRT_Dispatch_Item (Guid_t guid, const DSRT_QoSDescriptor& qos) + :guid_ (guid), qos_ (qos) +{ +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE typename DSRT_Dispatch_Item<DSRT_Scheduler_Traits>::Guid_t +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +guid () +{ + return guid_; +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE typename DSRT_Dispatch_Item<DSRT_Scheduler_Traits>::DSRT_QoSDescriptor +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +qos () +{ + return qos_; +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE ACE_hthread_t +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +thread_handle () +{ + return thr_handle_; +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE void +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +thread_handle (ACE_hthread_t &handle) +{ + thr_handle_ = handle; +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE void +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +insertion_time (const ACE_Time_Value& tv) +{ + this->insertion_time_ = tv; +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE ACE_Time_Value +DSRT_Dispatch_Item<DSRT_Scheduler_Traits>:: +insertion_time () +{ + return this->insertion_time_; +} + +} diff --git a/Kokyu/DSRT_Dispatcher_Impl_T.cpp b/Kokyu/DSRT_Dispatcher_Impl_T.cpp new file mode 100644 index 00000000000..2bfb610b412 --- /dev/null +++ b/Kokyu/DSRT_Dispatcher_Impl_T.cpp @@ -0,0 +1,25 @@ +// $Id$ + +#ifndef DSRT_DISPATCHER_IMPL_T_CPP +#define DSRT_DISPATCHER_IMPL_T_CPP + +#include "DSRT_Dispatcher_Impl_T.h" + +#if ! defined (__ACE_INLINE__) +#include "DSRT_Dispatcher_Impl_T.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, DSRT_Dispatcher_Impl, "$Id$") + +namespace Kokyu +{ + +//virtual - so don't inline +template <class DSRT_Scheduler_Traits> +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>::~DSRT_Dispatcher_Impl () +{ +} + +} + +#endif /* DSRT_DISPATCHER_IMPL_T_CPP */ diff --git a/Kokyu/DSRT_Dispatcher_Impl_T.h b/Kokyu/DSRT_Dispatcher_Impl_T.h new file mode 100644 index 00000000000..6c6e0f3ec7e --- /dev/null +++ b/Kokyu/DSRT_Dispatcher_Impl_T.h @@ -0,0 +1,95 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Dispatcher_Impl.h + * + * $Id$ + * + */ + +#ifndef DSRT_DISPATCHER_IMPL_H +#define DSRT_DISPATCHER_IMPL_H +#include "ace/pre.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +//# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Kokyu_dsrt.h" + +namespace Kokyu +{ + /** + * @class DSRT_Dispatcher + * + * @brief Base class for DSRT dispatcher implementations + * + * The responsibility of this class is to act as a common base class + * for different DSRT dispatcher implementations. This is an + * abstract base class and cannot be instantiated. + */ + template <class DSRT_Scheduler_Traits> + class DSRT_Dispatcher_Impl + { + public: + typedef typename DSRT_Scheduler_Traits::Guid_t Guid_t; + typedef typename DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor; + + /// Configure the DSRT dispatcher. + int init (const DSRT_ConfigInfo&); + + /// Schedule a thread dynamically based on the qos info supplied. + int schedule (Guid_t guid, + const DSRT_QoSDescriptor&); + + /// Update the schedule for a thread. This could alter the current + /// schedule. + int update_schedule (Guid_t guid, + const DSRT_QoSDescriptor&); + + /// Inform the scheduler that the caller thread is about to + /// block. This could alter the current schedule. + int update_schedule (Guid_t guid, Block_Flag_t flag); + + /// Cancel the schedule for a thread. This could alter the current + /// schedule. + int cancel_schedule (Guid_t guid); + + /// Shut down the dispatcher. The dispatcher will stop processing + /// requests. + int shutdown (); + + virtual ~DSRT_Dispatcher_Impl (); + + private: + + //following an idiom to avoid public virtual functions. + //instead make them private and use the template method + //pattern - "Virtually Yours" article in CUJ Experts Forum + + virtual int init_i (const DSRT_ConfigInfo&)=0; + virtual int schedule_i (Guid_t guid, + const DSRT_QoSDescriptor&)=0; + virtual int update_schedule_i (Guid_t guid, + const DSRT_QoSDescriptor&)=0; + virtual int update_schedule_i (Guid_t guid, Block_Flag_t flag)=0; + virtual int cancel_schedule_i (Guid_t guid)=0; + virtual int shutdown_i ()=0; + + }; + +} //end of namespace + +#if defined (__ACE_INLINE__) +#include "DSRT_Dispatcher_Impl_T.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "DSRT_Dispatcher_Impl_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("DSRT_Dispatcher_Impl_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* DSRT_DISPATCHER_IMPL_H */ diff --git a/Kokyu/DSRT_Dispatcher_Impl_T.i b/Kokyu/DSRT_Dispatcher_Impl_T.i new file mode 100644 index 00000000000..e4983a17ba3 --- /dev/null +++ b/Kokyu/DSRT_Dispatcher_Impl_T.i @@ -0,0 +1,57 @@ +// $Id$ + +namespace Kokyu +{ + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +init (const DSRT_ConfigInfo& config_info) +{ + return this->init_i (config_info); +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +schedule (Guid_t guid, + const DSRT_QoSDescriptor& qos) +{ + return this->schedule_i (guid, qos); +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +update_schedule (Guid_t guid, + const DSRT_QoSDescriptor& qos) +{ + return this->update_schedule_i (guid, qos); +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +update_schedule (Guid_t guid, + Block_Flag_t flag) +{ + return this->update_schedule_i (guid, flag); +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>:: +cancel_schedule (Guid_t guid) +{ + return this->cancel_schedule_i (guid); +} + +template <class DSRT_Scheduler_Traits> +ACE_INLINE int +DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>::shutdown () + +{ + return this->shutdown_i (); +} + +} diff --git a/Kokyu/DSRT_Sched_Queue_T.cpp b/Kokyu/DSRT_Sched_Queue_T.cpp new file mode 100644 index 00000000000..bd63267fc1d --- /dev/null +++ b/Kokyu/DSRT_Sched_Queue_T.cpp @@ -0,0 +1,218 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Sched_Queue_T.cpp + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ +#ifndef DSRT_SCHED_QUEUE_T_CPP +#define DSRT_SCHED_QUEUE_T_CPP + +#include "DSRT_Sched_Queue_T.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#if !defined (__ACE_INLINE__) +//#include "DSRT_Sched_Queue_T.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, + DSRT_Sched_Queue_T, + "$Id$") + +namespace Kokyu +{ + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +u_long +Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +Guid_Hash::operator () (const Guid_t& id) +{ + typename DSRT_Scheduler_Traits::Guid_Hash guid_hash; + return guid_hash(id); +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +int Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +current_size () +{ + return dispatch_items_prio_queue_.current_size (); +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +int Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +most_eligible (DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& item) +{ + if (dispatch_items_prio_queue_.current_size () == 0) + return -1; + + PRIO_QUEUE_ITERATOR start = dispatch_items_prio_queue_.begin (); + PRIO_QUEUE_ENTRY &ent = (*start); + item = ent.item (); + return 0; +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +int Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +find (Guid_t guid, + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& found_item) +{ + ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1); + RB_Tree_Dispatch_Item_Node* rb_tree_node; + + if (dispatch_items_hash_map_.find(guid, rb_tree_node) == -1) + { + return -1; + } + else + { + found_item = rb_tree_node->item (); + return 0; + } + + return 0; +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +int Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +insert(Guid_t guid, const DSRT_QoSDescriptor_t& qos) +{ + DSRT_Dispatch_Item<DSRT_Scheduler_Traits>* item; + ACE_hthread_t thr_handle; + ACE_Thread::self (thr_handle); + + ACE_NEW_RETURN (item, + DSRT_Dispatch_Item<DSRT_Scheduler_Traits> (guid, qos), + -1); + item->thread_handle (thr_handle); + item->insertion_time (ACE_OS::gettimeofday ()); + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> item_var(item); + + ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1); + + RB_Tree_Dispatch_Item_Node* rb_tree_node; + if (dispatch_items_hash_map_.find(guid, rb_tree_node) == -1) + { + if (dispatch_items_prio_queue_.bind (item_var, + item_var, + rb_tree_node) == 0) + { + if (dispatch_items_hash_map_.bind (guid, rb_tree_node) == 0) + { + ACE_DEBUG ((LM_DEBUG, "(%t) insert item done\n")); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents Begin===>\n")); + dispatch_items_hash_map_.dump (); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents End=====>\n")); + return 0; + } + } + } + else + { + dispatch_items_hash_map_.unbind (guid); + dispatch_items_prio_queue_.unbind (rb_tree_node); + if (dispatch_items_prio_queue_.bind (item_var, + item_var, + rb_tree_node) == 0) + { + if (dispatch_items_hash_map_.bind (guid, rb_tree_node) == 0) + { + ACE_DEBUG ((LM_DEBUG, "(%t) insert item done\n")); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents Begin===>\n")); + dispatch_items_hash_map_.dump (); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents End===>\n")); + return 0; + } + } + } + + return -1; +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, class ACE_LOCK> +int Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, ACE_LOCK>:: +remove(Guid_t guid) +{ + ACE_GUARD_RETURN (ACE_LOCK, mon, lock_, -1); + RB_Tree_Dispatch_Item_Node* rb_tree_node; + + if (dispatch_items_hash_map_.find(guid, rb_tree_node) == 0) + { + dispatch_items_hash_map_.unbind (guid); + dispatch_items_prio_queue_.unbind (rb_tree_node); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents Begin===>\n")); + dispatch_items_hash_map_.dump (); + ACE_DEBUG ((LM_DEBUG, + "<===Hash Table contents End===>\n")); + return 0; + } + + return -1; +} + +template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> +void Sched_Ready_Queue<DSRT_Scheduler_Traits, + More_Eligible_Comparator, + ACE_LOCK>:: +dump() +{ + ACE_GUARD (ACE_LOCK, mon, lock_); + if (dispatch_items_prio_queue_.current_size ()) + { + PRIO_QUEUE_ITERATOR end_iter = dispatch_items_prio_queue_.end (); + PRIO_QUEUE_ITERATOR start; + + start = dispatch_items_prio_queue_.begin (); + while( start != end_iter ) + { + PRIO_QUEUE_ENTRY &ent = (*start); + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> + item_var = ent.item (); + /* + int guid; + ACE_OS::memcpy (&guid, + item_var->guid ()->get_buffer (), + item_var->guid ()->length ()); + + ACE_DEBUG ((LM_DEBUG, "guid %d\n", guid)); + */ + ++start; + } + } +} + +} + +#endif /* DSRT_SCHED_QUEUE_T_CPP */ diff --git a/Kokyu/DSRT_Sched_Queue_T.h b/Kokyu/DSRT_Sched_Queue_T.h new file mode 100644 index 00000000000..9faa043f9e2 --- /dev/null +++ b/Kokyu/DSRT_Sched_Queue_T.h @@ -0,0 +1,222 @@ +/* -*- C++ -*- */ +/** + * @file DSRT_Sched_Queue_T.h + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +#ifndef DSRT_SCHED_QUEUE_T_H +#define DSRT_SCHED_QUEUE_T_H +#include "ace/pre.h" + +#include "DSRT_Dispatch_Item_T.h" +#include "ace/RB_Tree.h" +#include "ace/Hash_Map_Manager_T.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "Kokyu_dsrt.h" + +namespace Kokyu +{ + + /** + * @class Sched_Ready_Queue + * + * @brief RB_Tree based template class for implementation of + * reordering queue. + * + * This queue is used as a priority queue to store schedulable + * entities. The item at the top of the RB_Tree is the most eligible + * item. The comparator used to determine the most eligible item is + * passed as a template parameter <code> More_Eligible_Comparator + * </code>. This is expected to be a functor which compares two + * schedulable items. The mutex type template parameter for RB_Tree + * is chosen to be a null mutex since all the methods in the + * enclosing <code> Sched_Ready_Queue </code> class are thread + * safe. Since QoS is used for comparison between two schedulable + * items, QoSDescriptor is the ideal candidate to be used as the key + * or the EXT_ID for RB_Tree instantiation. But two qos descriptors + * could be the same. The existing implementation of RB_Tree does + * not allow duplicate keys. In order to facilitate insertion of + * duplicate qos descriptors, the qos descriptors are contained in a + * <code> DSRT_Dispatch_Item </code> and this is used as the basis + * of comparison. To resolve tie between equal qos values, an + * insertion time stamp is maintained in each item and an item with + * an earlier time stamp is more eligible than an item with an + * identical qos value. Another requirement is that it should be + * possible to remove an item from the RB_Tree based on guid. Since + * we have already used up the qos descriptor for the key, we need a + * separate index into the list of schedulable items. The second + * index should be based on guid. This is achieved by using a hash + * map to store <guid, RB_Tree_Node*> pairs. This makes the deletion + * of nodes from RB_Tree more efficient. + * + */ + template <class DSRT_Scheduler_Traits, + class More_Eligible_Comparator, + class ACE_LOCK> + class Sched_Ready_Queue + { + /// Extract the necessary types from the traits class + typedef typename DSRT_Scheduler_Traits::Guid_t Guid_t; + + typedef typename + DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor_t; + + public: + + /** + * Given a guid, find an item in the priority queue. + * + * @param guid Guid of item + * + * @param found_item Reference to DSRT_Dispatch_Item_var + * to hold the found item. + * @return -1 if no item found and 0 otherwise. + */ + int find(Guid_t guid, + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& + found_item); + + + /** + * Insert an item in the priority queue. If item with same guid is + * already in the queue, the existing one is deleted and the new + * one inserted. A deletion and insertion has to happen instead of + * update since the rebalancing of the RB_Tree should take place. + * + * @param guid Guid of item. + * + * @param qos QoS associated with item. + * + * @return -1 if insertion failed and 0 otherwise. + */ + int insert(Guid_t guid, const DSRT_QoSDescriptor_t& qos); + + /** + * Remove an item from the priority queue. + * + * @param guid Guid of item. + * + * @param qos QoS associated with item. + * + * @return -1 if removal failed and 0 otherwise. + */ + int remove(Guid_t guid); + + /** + * Returns current size of the priority queue. + */ + int current_size (); + + /** + * Get the most eligible item from the priority queue. + * + * @param item Item which is most eligible, i.e. one at the + * "top" of the priority queue. + * + * @return -1 if there are no items in the priority queue. + */ + int most_eligible (DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>& + item); + + void dump(); + + private: + + /** + * @class Guid_Hash + * + * @brief Internal class to generate hash for guid. + * + * This acts just as a wrapper functor to the Hash functor passed + * as part of the traits class <code> DSRT_Scheduler_Traits + * </code>. + * + */ + class Guid_Hash + { + public: + /// Returns hash value. + u_long operator () (const Guid_t &id); + }; + + // RB_Tree related typedefs + typedef ACE_RB_Tree <DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>, + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>, + More_Eligible_Comparator, + ACE_SYNCH_NULL_MUTEX> Dispatch_Items_Priority_Queue; + + + typedef + ACE_RB_Tree_Node<DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits>, + DSRT_Dispatch_Item_var<DSRT_Scheduler_Traits> > + RB_Tree_Dispatch_Item_Node; + + typedef typename + Dispatch_Items_Priority_Queue::ITERATOR PRIO_QUEUE_ITERATOR; + + typedef typename + Dispatch_Items_Priority_Queue::ENTRY PRIO_QUEUE_ENTRY; + + // Hash map related typedefs + typedef ACE_Hash_Map_Manager_Ex<Guid_t, + RB_Tree_Dispatch_Item_Node*, + Guid_Hash, + ACE_Equal_To<Guid_t>, + ACE_SYNCH_NULL_MUTEX> + Dispatch_Items_Hash_Map; + + typedef ACE_Hash_Map_Iterator_Ex<Guid_t, + RB_Tree_Dispatch_Item_Node*, + Guid_Hash, + ACE_Equal_To<Guid_t>, + ACE_SYNCH_NULL_MUTEX> + Dispatch_Items_Hash_Map_Iterator; + + typedef ACE_Hash_Map_Entry <Guid_t, + RB_Tree_Dispatch_Item_Node*> + Dispatch_Items_Hash_Map_Entry; + + /** + * Lock used to protect the state of the scheduler queue. A + * separate lock is not used for the internal RB_Tree and hashmap. + */ + ACE_LOCK lock_; + + /** + * Hash table to maintain a second index into the list of + * schedulable items. This is for efficient removal of items from + * the RB_Tree based on guid. The guid is used as the key for the + * hash map, whereas the qos value is used as the key for the + * RB_Tree. + */ + Dispatch_Items_Hash_Map dispatch_items_hash_map_; + + /** + * RB_Tree implementation of priority queue of schedulable items. + */ + Dispatch_Items_Priority_Queue dispatch_items_prio_queue_; + }; +} + +#if !defined (__ACE_INLINE__) +//#include "DSRT_Sched_Queue_T.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "DSRT_Sched_Queue_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("DSRT_Sched_Queue_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* DSRT_SCHED_QUEUE_T_H */ diff --git a/Kokyu/Default_Dispatcher_Impl.cpp b/Kokyu/Default_Dispatcher_Impl.cpp index 8e1fea22d01..0b8dcb7b7e7 100644 --- a/Kokyu/Default_Dispatcher_Impl.cpp +++ b/Kokyu/Default_Dispatcher_Impl.cpp @@ -7,7 +7,7 @@ #include "Default_Dispatcher_Impl.i" #endif /* __ACE_INLINE__ */ -ACE_RCSID(Kokyu, Dispatcher_Impl, "$Id$") +ACE_RCSID(Kokyu, Default_Dispatcher_Impl, "$Id$") namespace Kokyu { diff --git a/Kokyu/Default_Dispatcher_Impl.h b/Kokyu/Default_Dispatcher_Impl.h index 7c59faa15b2..b563302d6c8 100644 --- a/Kokyu/Default_Dispatcher_Impl.h +++ b/Kokyu/Default_Dispatcher_Impl.h @@ -12,28 +12,31 @@ #ifndef DEFAULT_DISPATCHER_IMPL_H #define DEFAULT_DISPATCHER_IMPL_H -#include /**/ "ace/pre.h" -#include "ace/OS.h" +#include "ace/pre.h" +#include "ace/Task.h" +#include "ace/Auto_Ptr.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/Task.h" -#include "ace/Message_Block.h" -#include "ace/Auto_Ptr.h" - #include "kokyu_export.h" -#include "Kokyu.h" +#include "Kokyu_defs.h" #include "Dispatcher_Impl.h" #include "Dispatcher_Task.h" namespace Kokyu { + /** + * @class Default_Dispatcher_Impl + * + * @brief Default implementation class for EC dispatcher + * implementations + * + */ class Default_Dispatcher_Impl : public Dispatcher_Impl { public: - virtual ~Default_Dispatcher_Impl (); int activate (); private: @@ -50,8 +53,6 @@ namespace Kokyu ConfigInfoSet curr_config_info_; }; - // **************************************************************** - class Shutdown_Task_Command : public Dispatch_Command { public: @@ -62,13 +63,11 @@ namespace Kokyu int execute (); }; - // **************************************************************** - } //end of namespace #if defined (__ACE_INLINE__) #include "Default_Dispatcher_Impl.i" #endif /* __ACE_INLINE__ */ -#include /**/ "ace/post.h" +#include "ace/post.h" #endif /* DEFAULT_DISPATCHER_IMPL_H */ diff --git a/Kokyu/Default_Dispatcher_Impl.i b/Kokyu/Default_Dispatcher_Impl.i index 07df24d94d9..2d10b58a2ac 100644 --- a/Kokyu/Default_Dispatcher_Impl.i +++ b/Kokyu/Default_Dispatcher_Impl.i @@ -3,11 +3,6 @@ namespace Kokyu { ACE_INLINE -Default_Dispatcher_Impl::~Default_Dispatcher_Impl() -{ -} - -ACE_INLINE Shutdown_Task_Command::Shutdown_Task_Command (ACE_Allocator *mb_allocator) { ACE_UNUSED_ARG ((mb_allocator)); diff --git a/Kokyu/Dispatcher_Impl.cpp b/Kokyu/Dispatcher_Impl.cpp index 762d0254fdf..9ad5994eb63 100644 --- a/Kokyu/Dispatcher_Impl.cpp +++ b/Kokyu/Dispatcher_Impl.cpp @@ -7,3 +7,13 @@ #endif /* __ACE_INLINE__ */ ACE_RCSID(Kokyu, Dispatcher_Impl, "$Id$") + +namespace Kokyu +{ + +//virtual - so don't inline +Dispatcher_Impl::~Dispatcher_Impl() +{ +} + +} diff --git a/Kokyu/Dispatcher_Impl.h b/Kokyu/Dispatcher_Impl.h index 46d00dae2bc..32f083a54ee 100644 --- a/Kokyu/Dispatcher_Impl.h +++ b/Kokyu/Dispatcher_Impl.h @@ -12,30 +12,45 @@ #ifndef DISPATCHER_IMPL_H #define DISPATCHER_IMPL_H -#include /**/ "ace/pre.h" -#include "ace/OS.h" +#include "ace/pre.h" -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ +//#if !defined (ACE_LACKS_PRAGMA_ONCE) +//# pragma once +//#endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "kokyu_export.h" -#include "Kokyu.h" +#include "Kokyu_defs.h" namespace Kokyu { + /** + * @class Dispatcher + * + * @brief Base class for EC dispatcher implementations + * + * The responsibility of this class is to act as a common base class + * for different EC dispatcher implementations. This is an + * abstract base class and cannot be instantiated. + */ class Dispatcher_Impl { public: - //following an idiom to avoid public virtual functions. - //instead make them private and use the template method - //pattern - "Virtually Yours" article in CUJ Experts Forum + /// Configure the dispatcher. int init (const ConfigInfoSet&); + + /// dispatch a command (eg. event) based on the QoS supplied. int dispatch (const Dispatch_Command*, const QoSDescriptor&); + + /// shutdown the dispatcher. int shutdown (); + virtual ~Dispatcher_Impl(); + private: + //following an idiom to avoid public virtual functions. + //instead make them private and use the template method + //pattern - "Virtually Yours" article in CUJ Experts Forum + virtual int init_i (const ConfigInfoSet&) =0; virtual int dispatch_i (const Dispatch_Command*, const QoSDescriptor&) =0; @@ -48,5 +63,5 @@ namespace Kokyu #include "Dispatcher_Impl.i" #endif /* __ACE_INLINE__ */ -#include /**/ "ace/post.h" +#include "ace/post.h" #endif /* DISPATCHER_IMPL_H */ diff --git a/Kokyu/Dispatcher_Impl.i b/Kokyu/Dispatcher_Impl.i index 54a9748aae7..a6c1d1ded3f 100644 --- a/Kokyu/Dispatcher_Impl.i +++ b/Kokyu/Dispatcher_Impl.i @@ -2,6 +2,7 @@ namespace Kokyu { + ACE_INLINE int Dispatcher_Impl::init (const ConfigInfoSet& config_info) { @@ -21,8 +22,4 @@ int Dispatcher_Impl::shutdown () return shutdown_i (); } -ACE_INLINE -Dispatcher_Impl::~Dispatcher_Impl() -{ -} } diff --git a/Kokyu/Dispatcher_Task.h b/Kokyu/Dispatcher_Task.h index 5d45894a691..5d8eb49ca31 100644 --- a/Kokyu/Dispatcher_Task.h +++ b/Kokyu/Dispatcher_Task.h @@ -12,17 +12,14 @@ #ifndef TAO_DISPATCHER_TASK_H #define TAO_DISPATCHER_TASK_H -#include /**/ "ace/pre.h" -#include "ace/OS.h" +#include "ace/pre.h" +#include "ace/Task.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/Task.h" - -#include "kokyu_export.h" -#include "Kokyu.h" +#include "Kokyu_defs.h" namespace Kokyu { @@ -102,5 +99,5 @@ private: #include "Dispatcher_Task.i" #endif /* __ACE_INLINE__ */ -#include /**/ "ace/post.h" +#include "ace/post.h" #endif /* DISPATCHER_TASK_H */ diff --git a/Kokyu/Kokyu.cpp b/Kokyu/Kokyu.cpp index 274068c8a22..54953431006 100644 --- a/Kokyu/Kokyu.cpp +++ b/Kokyu/Kokyu.cpp @@ -1,14 +1,14 @@ // $Id$ -#include "ace/Dynamic_Service.h" #include "Kokyu.h" + #include "Default_Dispatcher_Impl.h" #if ! defined (__ACE_INLINE__) #include "Kokyu.i" #endif /* __ACE_INLINE__ */ -ACE_RCSID(Kokyu, Dispatcher_Impl, "$Id$") +ACE_RCSID(Kokyu, Kokyu, "$Id$") namespace Kokyu { @@ -35,66 +35,19 @@ void Dispatcher::implementation (Dispatcher_Impl* impl) //dispatcher_impl_.reset (impl); } - -Dispatcher* +Dispatcher_Auto_Ptr Dispatcher_Factory:: -create_dispatcher (const ConfigInfoSet& config_info_set) +create_dispatcher(const ConfigInfoSet& config_info_set) { - Dispatcher_Impl* tmp; - ACE_NEW_RETURN (tmp, Default_Dispatcher_Impl, (Dispatcher*)0); Dispatcher* disp; - ACE_NEW_RETURN (disp, Dispatcher, (Dispatcher*)0); + Dispatcher_Auto_Ptr nil_ptr((Dispatcher*)0); + Dispatcher_Impl* tmp; + ACE_NEW_RETURN (tmp, Default_Dispatcher_Impl, nil_ptr); + ACE_NEW_RETURN (disp, Dispatcher, nil_ptr); + Dispatcher_Auto_Ptr disp_auto_ptr(disp); disp->implementation (tmp); tmp->init (config_info_set); - return disp; -} - -void -DSRT_Dispatcher::implementation (DSRT_Dispatcher_Impl* impl) -{ - dispatcher_impl_ = impl; -} - -int -DSRT_Dispatcher::schedule (guid_t guid, const DSRT_QoSDescriptor& qos) -{ - return dispatcher_impl_->schedule (guid, qos); -} - -int -DSRT_Dispatcher::update_schedule (guid_t guid, const DSRT_QoSDescriptor& qos) -{ - return dispatcher_impl_->update_schedule (guid, qos); -} - -int -DSRT_Dispatcher::cancel_schedule (guid_t guid, const DSRT_QoSDescriptor& qos) -{ - return dispatcher_impl_->cancel_schedule (guid, qos); -} - -DSRT_Dispatcher* -Dispatcher_Factory:: -create_DSRT_dispatcher (const DSRT_ConfigInfo& config_info) -{ - ACE_UNUSED_ARG ((config_info)); - - DSRT_Dispatcher_Impl* tmp; - - //DSRT_Dispatcher_Impl::init_svcs (); - - ACE_Service_Config::open ("Kokyu", ACE_DEFAULT_LOGGER_KEY, 0); - - //tmp = - // ACE_Dynamic_Service<DSRT_Dispatcher_Impl>::instance ("DSRT_Dispatcher_Impl"); - - ACE_NEW_RETURN (tmp, DSRT_Dispatcher_Impl, (DSRT_Dispatcher*) 0); - ACE_ASSERT (tmp != 0); - DSRT_Dispatcher* disp; - ACE_NEW_RETURN (disp, DSRT_Dispatcher, (DSRT_Dispatcher*)0); - disp->implementation (tmp); - tmp->init (config_info); - return disp; + return disp_auto_ptr; } } diff --git a/Kokyu/Kokyu.dsp b/Kokyu/Kokyu.dsp new file mode 100644 index 00000000000..141dbf61fd1 --- /dev/null +++ b/Kokyu/Kokyu.dsp @@ -0,0 +1,204 @@ +# Microsoft Developer Studio Project File - Name="Kokyu DLL" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=Kokyu DLL - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE run the tool that generated this project file and specify the
+!MESSAGE nmake output type. You can then use the following command:
+!MESSAGE
+!MESSAGE NMAKE /f "Kokyu.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Kokyu.mak" CFG="Kokyu DLL - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Kokyu DLL - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "Kokyu DLL - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Kokyu DLL - Win32 Release"
+
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "."
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD CPP /nologo /W3 /GX /O2 /MD /Zi /Ob2 /GR /I ".." /D NDEBUG=1 /D WIN32=1 /D _WINDOWS=1 /D KOKYU_BUILD_DLL=1 /FD /c
+# SUBTRACT CPP /YX
+# ADD RSC /l 0x409 /d NDEBUG=1 /i ".."
+BSC32=bscmake.exe
+# ADD BSC32 /nologo /o".\Kokyu.bsc"
+LINK32=link.exe
+# ADD LINK32 advapi32.lib user32.lib /INCREMENTAL:NO ACE.lib /libpath:"..\ace" /nologo /version:5.2.4 /subsystem:windows /dll /machine:I386 /out:"..\bin\Kokyu.dll"
+
+!ELSEIF "$(CFG)" == "Kokyu DLL - Win32 Debug"
+
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "."
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /MDd /GR /Gy /I ".." /D _DEBUG=1 /D WIN32=1 /D _WINDOWS=1 /D KOKYU_BUILD_DLL=1 /FD /c
+# SUBTRACT CPP /Fr /YX
+# ADD RSC /l 0x409 /d _DEBUG=1 /i ".."
+BSC32=bscmake.exe
+# ADD BSC32 /nologo /o".\Kokyu.bsc"
+LINK32=link.exe
+# ADD LINK32 advapi32.lib user32.lib /INCREMENTAL:NO ACEd.lib /libpath:"..\ace" /nologo /version:5.2.4 /subsystem:windows /dll /debug /pdb:Kokyud.pdb /machine:I386 /out:"..\bin\Kokyud.dll"
+
+!ENDIF
+
+# Begin Target
+
+# Name "Kokyu DLL - Win32 Release"
+# Name "Kokyu DLL - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;cxx;c"
+# Begin Source File
+
+SOURCE=.\Default_Dispatcher_Impl
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Impl
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Task
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_defs
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hh"
+# Begin Source File
+
+SOURCE=.\Default_Dispatcher_Impl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Impl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Task.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Direct_Dispatcher_Impl_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatch_Item_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatcher_Impl_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Sched_Queue_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_defs.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_dsrt.h
+# End Source File
+# End Group
+# Begin Group "Inline Files"
+
+# PROP Default_Filter "i;inl"
+# Begin Source File
+
+SOURCE=.\Default_Dispatcher_Impl.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Impl.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Dispatcher_Task.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatch_Item_T.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatcher_Impl_T.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_defs.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_dsrt.i
+# End Source File
+# End Group
+# Begin Group "Template Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\DSRT_Direct_Dispatcher_Impl_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatch_Item_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatcher_Impl_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Sched_Queue_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_dsrt
+# PROP Exclude_From_Build 1
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/Kokyu/Kokyu.dsw b/Kokyu/Kokyu.dsw index 9ce4ef90750..e2eda87a2ca 100644 --- a/Kokyu/Kokyu.dsw +++ b/Kokyu/Kokyu.dsw @@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ###############################################################################
-Project: "Kokyu_DLL"=.\Kokyu_DLL.dsp - Package Owner=<4>
+Project: "Kokyu DLL"=Kokyu.dsp - Package Owner=<4>
Package=<5>
{{{
@@ -11,11 +11,14 @@ Package=<5> Package=<4>
{{{
+ Begin Project Dependency
+ Project_Dep_Name ace DLL
+ End Project Dependency
}}}
###############################################################################
-Project: "Kokyu_static"=.\Kokyu_static.dsp - Package Owner=<4>
+Project: "Kokyu LIB"=Kokyu_Static.dsp - Package Owner=<4>
Package=<5>
{{{
diff --git a/Kokyu/Kokyu.h b/Kokyu/Kokyu.h index 9d7b1342c83..e3a07108083 100644 --- a/Kokyu/Kokyu.h +++ b/Kokyu/Kokyu.h @@ -6,149 +6,83 @@ * * @author Venkita Subramonian (venkita@cs.wustl.edu) * - * Based on previous work by Tim Harrison (harrison@cs.wustl.edu), - * Chris Gill, Carlos O'Ryan and other members of the DOC group. + * Based on previous work by Tim Harrison Chris Gill, + * Carlos O'Ryan and other members of the DOC group. */ #ifndef KOKYU_H #define KOKYU_H -#include /**/ "ace/pre.h" -#include "ace/OS.h" +#include "ace/pre.h" -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Array.h" -#include "ace/Time_Value.h" -#include "ace/Auto_Ptr.h" -#include "ace/Message_Block.h" -#include "ace/Sched_Params.h" +//#if !defined (ACE_LACKS_PRAGMA_ONCE) +//# pragma once +//#endif /* ACE_LACKS_PRAGMA_ONCE */ #include "kokyu_export.h" +#include "Kokyu_defs.h" namespace Kokyu { - typedef long Priority_t; - typedef ACE_Time_Value Deadline_t; //absolute deadline - typedef ACE_Time_Value Execution_Time_t; //execution time - - enum Dispatching_Type_t - // Defines the type of prioritization strategy - // to be used by a dispatching queue - { - FIFO_DISPATCHING, - DEADLINE_DISPATCHING, - LAXITY_DISPATCHING - }; - - enum Criticality_t - // Defines the criticality of the operation. - // For use with Dynamic Scheduler. - { - VERY_LOW_CRITICALITY, - LOW_CRITICALITY, - MEDIUM_CRITICALITY, - HIGH_CRITICALITY, - VERY_HIGH_CRITICALITY - }; - - enum Importance_t - // Defines the importance of the operation, - // which can be used by the RtecScheduler as a - // "tie-breaker" when other scheduling - // parameters are equal. - { - VERY_LOW_IMPORTANCE, - LOW_IMPORTANCE, - MEDIUM_IMPORTANCE, - HIGH_IMPORTANCE, - VERY_HIGH_IMPORTANCE - }; - - struct ConfigInfo - { - Priority_t preemption_priority_; - - // OS priority of the dispatching thread associated with the queue - Priority_t thread_priority_; - - // type of dispatching queue - Dispatching_Type_t dispatching_type_; - }; - - typedef ACE_Array<ConfigInfo> ConfigInfoSet; - - struct QoSDescriptor - { - Priority_t preemption_priority_; - Deadline_t deadline_; - Execution_Time_t execution_time_; - Importance_t importance_; - }; - - struct DSRT_QoSDescriptor - { - short importance_; - }; - - class Kokyu_Export Dispatch_Command - { - public: - Dispatch_Command(int dont_delete = 0); - - /// Command callback - virtual int execute () = 0; - - int can_be_deleted () const; - - void destroy (void); - protected: - /// Destructor - // only inheritance is possible and object should be on heap, - // since object could be handed over to a different thread. - virtual ~Dispatch_Command (void); - - private: - int dont_delete_; - }; - class Dispatcher_Impl; - class DSRT_Dispatcher_Impl; - - struct DSRT_ConfigInfo - { - }; - typedef int guid_t; - class Kokyu_Export DSRT_Dispatcher - { - public: - int schedule (guid_t guid, const DSRT_QoSDescriptor&); - int update_schedule (guid_t guid, const DSRT_QoSDescriptor&); - int cancel_schedule (guid_t guid, const DSRT_QoSDescriptor&); - void implementation (DSRT_Dispatcher_Impl*); - - private: - DSRT_Dispatcher_Impl* dispatcher_impl_; - }; - - class Kokyu_Export Dispatcher + /** + * @class Dispatcher + * + * @brief Interface class for dynamic scheduling of events + * + * The responsibility of this class is to forward all methods to + * its delegation/implementation class, e.g., + * @c Default_Dispatcher_Impl. This class follows the pImpl idiom + * or the bridge pattern to separate the implementation from the interface. + * Dispatcher is the class that users will be using to achieve + * dynamic dispatching of events in an event channel. + */ + class Kokyu_Export Dispatcher : private non_copyable { public: + /// Dispatch a command object based on the qos info supplied. int dispatch (const Dispatch_Command*, const QoSDescriptor&); + + /// Shut down the dispatcher. The dispatcher will stop processing requests. int shutdown (); + + /// Supply this interface with an appripriate implementation. void implementation (Dispatcher_Impl*); + + /// Non virtual destructor. Read as <b><i>this class not available + /// for inheritance<i></b>. + ~Dispatcher (); private: + /// Auto ptr to the implementation. Implementation will be created on the + /// heap and deleted automatically when the dispatcher object is destructed. auto_ptr<Dispatcher_Impl> dispatcher_impl_; }; - class Kokyu_Export Dispatcher_Factory + typedef auto_ptr<Dispatcher> Dispatcher_Auto_Ptr; + + /** + * @class Dispatcher_Factory + * + * @brief Factory class to create one of the dispatcher interface + * objects - for events. + * + * Factory class creates a dispatcher for EC and configures the + * interface object with the appropriate implementation. + */ + class Kokyu_Export Dispatcher_Factory : private non_copyable { public: - //@@ Should we return auto_ptr<Dispatcher> instead? - static Dispatcher* create_dispatcher (const ConfigInfoSet&); - static DSRT_Dispatcher* create_DSRT_dispatcher (const DSRT_ConfigInfo&); + /** + * Create a dispatcher for dynamic dispatching of commands + * (eg. events). The caller is responsible for freeing the + * returned dynamically allocated memory. + * + * @param config Configuration information for the dispatcher. + * + * @return Auto pointer to the dispatcher. + */ + static Dispatcher_Auto_Ptr create_dispatcher (const ConfigInfoSet& config); + }; } //end of namespace @@ -156,8 +90,15 @@ namespace Kokyu #include "Kokyu.i" #endif /* __ACE_INLINE__ */ +//Currently I am not seeing a way to avoid including these here. The +//whole purpose of the pImpl idiom is to avoid this dependency. But +//using the auto_ptr<> to store the implementation causes a compile +//error (in the destructor) that the implementation definition is not +//found. Note that the auto-ptr<T>::~auto_ptr() calls delete on the +//internal pointer and at this point the class definition needs to be +//visible. Need to revisit this and see whether there is a work +//around. #include "Dispatcher_Impl.h" -#include "DSRT_Dispatcher_Impl.h" -#include /**/ "ace/post.h" +#include "ace/post.h" #endif /* KOKYU_H */ diff --git a/Kokyu/Kokyu.i b/Kokyu/Kokyu.i index 583e64c237f..0de9481c16d 100644 --- a/Kokyu/Kokyu.i +++ b/Kokyu/Kokyu.i @@ -1,33 +1,10 @@ // $Id$ - namespace Kokyu { - -ACE_INLINE -Dispatch_Command::Dispatch_Command (int dont_delete) - :dont_delete_ (dont_delete) -{ -} - ACE_INLINE -int Dispatch_Command::can_be_deleted (void) const +Dispatcher::~Dispatcher() { - return !dont_delete_; } -ACE_INLINE -void Dispatch_Command::destroy (void) -{ - //@@what if it was allocated thru an allocator? - //may be this should be left as a pure virtual - delete this; -} - -ACE_INLINE -Dispatch_Command::~Dispatch_Command (void) -{ -} - - } diff --git a/Kokyu/Kokyu.mpc b/Kokyu/Kokyu.mpc index 9dafc6ba137..6ebd6c320ed 100644 --- a/Kokyu/Kokyu.mpc +++ b/Kokyu/Kokyu.mpc @@ -1,4 +1,20 @@ -project : acelib, core { - sharedname = Kokyu - dynamicflags = KOKYU_BUILD_DLL +project(Kokyu) : acelib { + sharedname = Kokyu + dllflags += KOKYU_BUILD_DLL + + Source_Files { + Dispatcher_Impl + Kokyu + Default_Dispatcher_Impl + Dispatcher_Task + Kokyu_defs + } + + Template_Files { + Kokyu_dsrt + DSRT_Direct_Dispatcher_Impl_T + DSRT_Dispatcher_Impl_T + DSRT_Dispatch_Item_T + DSRT_Sched_Queue_T + } } diff --git a/Kokyu/Kokyu.mwc b/Kokyu/Kokyu.mwc new file mode 100644 index 00000000000..d418efed75c --- /dev/null +++ b/Kokyu/Kokyu.mwc @@ -0,0 +1,3 @@ +workspace(Kokyu) { + Kokyu.mpc +}
\ No newline at end of file diff --git a/Kokyu/Kokyu_Static.dsp b/Kokyu/Kokyu_Static.dsp index 87dcd65a8f6..fd4cdf8e8b8 100644 --- a/Kokyu/Kokyu_Static.dsp +++ b/Kokyu/Kokyu_Static.dsp @@ -1,25 +1,26 @@ -# Microsoft Developer Studio Project File - Name="Kokyu_Static" - Package Owner=<4>
+# Microsoft Developer Studio Project File - Name="Kokyu LIB" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
-CFG=Kokyu_Static - Win32 Debug
+CFG=Kokyu LIB - Win32 Static Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "Kokyu_static.mak".
-!MESSAGE
+!MESSAGE run the tool that generated this project file and specify the
+!MESSAGE nmake output type. You can then use the following command:
+!MESSAGE
+!MESSAGE NMAKE /f "Kokyu_Static.mak".
+!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "Kokyu_static.mak" CFG="Kokyu_Static - Win32 Debug"
-!MESSAGE
+!MESSAGE
+!MESSAGE NMAKE /f "Kokyu_Static.mak" CFG="Kokyu LIB - Win32 Static Debug"
+!MESSAGE
!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "Kokyu_Static - Win32 Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "Kokyu_Static - Win32 Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE
+!MESSAGE
+!MESSAGE "Kokyu LIB - Win32 Static Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "Kokyu LIB - Win32 Static Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
@@ -28,91 +29,71 @@ CFG=Kokyu_Static - Win32 Debug CPP=cl.exe
RSC=rc.exe
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
+!IF "$(CFG)" == "Kokyu LIB - Win32 Static Release"
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
-# PROP Output_Dir ""
-# PROP Intermediate_Dir "Static\Release"
+# PROP Output_Dir "Static_Release"
+# PROP Intermediate_Dir "Static_Release"
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "ACE_AS_STATIC_LIBS" /FD /c
+LINK32=link.exe -lib
+# ADD CPP /nologo /G5 /W3 /GX /O2 /MD /Zi /GR /I ".." /D NDEBUG=1 /D WIN32=1 /D _WINDOWS=1 /D ACE_AS_STATIC_LIBS=1 /FD /c
# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d NDEBUG=1 /i ".."
BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
+# ADD BSC32 /nologo /o".\Kokyu.bsc"
LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"Kokyus.lib"
+# ADD LIB32 /nologo /out:".\Kokyus.lib"
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
+!ELSEIF "$(CFG)" == "Kokyu LIB - Win32 Static Debug"
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
-# PROP Output_Dir ""
-# PROP Intermediate_Dir "Static\Debug"
+# PROP Output_Dir "Static_Debug"
+# PROP Intermediate_Dir "Static_Debug"
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "ACE_AS_STATIC_LIBS" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
+LINK32=link.exe -lib
+# ADD CPP /nologo /G5 /W3 /Gm /GX /Zi /Od /GR /Gy /MDd /I ".." /D _DEBUG=1 /D WIN32=1 /D _WINDOWS=1 /D ACE_AS_STATIC_LIBS=1 /FD /c
+# SUBTRACT CPP /Fr /YX
+# ADD RSC /l 0x409 /d _DEBUG=1 /i ".."
BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
+# ADD BSC32 /nologo /o".\Kokyu.bsc"
LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /out:"Kokyusd.lib"
+# ADD LIB32 /nologo /out:".\Kokyusd.lib"
-!ENDIF
+!ENDIF
# Begin Target
-# Name "Kokyu_Static - Win32 Release"
-# Name "Kokyu_Static - Win32 Debug"
+# Name "Kokyu LIB - Win32 Static Release"
+# Name "Kokyu LIB - Win32 Static Debug"
# Begin Group "Source Files"
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\Default_Dispatcher_Impl.cpp
-# End Source File
+# PROP Default_Filter "cpp;cxx;c"
# Begin Source File
-SOURCE=.\Dispatcher_Impl.cpp
+SOURCE=.\Default_Dispatcher_Impl
# End Source File
# Begin Source File
-SOURCE=.\Dispatcher_Task.cpp
+SOURCE=.\Dispatcher_Impl
# End Source File
# Begin Source File
-SOURCE=.\DSRT_Dispatcher_Impl.cpp
+SOURCE=.\Dispatcher_Task
# End Source File
# Begin Source File
-SOURCE=.\DSRT_Schedulers.cpp
+SOURCE=.\Kokyu
# End Source File
# Begin Source File
-SOURCE=.\Kokyu.cpp
+SOURCE=.\Kokyu_defs
# End Source File
# End Group
# Begin Group "Header Files"
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# PROP Default_Filter "h;hpp;hxx;hh"
# Begin Source File
SOURCE=.\Default_Dispatcher_Impl.h
@@ -127,11 +108,19 @@ SOURCE=.\Dispatcher_Task.h # End Source File
# Begin Source File
-SOURCE=.\DSRT_Dispatcher_Impl.h
+SOURCE=.\DSRT_Direct_Dispatcher_Impl_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Dispatch_Item_T.h
# End Source File
# Begin Source File
-SOURCE=.\DSRT_Schedulers.h
+SOURCE=.\DSRT_Dispatcher_Impl_T.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DSRT_Sched_Queue_T.h
# End Source File
# Begin Source File
@@ -139,76 +128,76 @@ SOURCE=.\Kokyu.h # End Source File
# Begin Source File
-SOURCE=.\kokyu_export.h
+SOURCE=.\Kokyu_defs.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Kokyu_dsrt.h
# End Source File
# End Group
# Begin Group "Inline Files"
-# PROP Default_Filter ""
+# PROP Default_Filter "i;inl"
# Begin Source File
SOURCE=.\Default_Dispatcher_Impl.i
-
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
-
-# PROP Exclude_From_Build 1
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=.\Dispatcher_Impl.i
-
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
-
-# PROP Exclude_From_Build 1
-
-!ENDIF
-
# End Source File
# Begin Source File
SOURCE=.\Dispatcher_Task.i
+# End Source File
+# Begin Source File
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
-
-# PROP Exclude_From_Build 1
+SOURCE=.\DSRT_Dispatch_Item_T.i
+# End Source File
+# Begin Source File
-!ENDIF
+SOURCE=.\DSRT_Dispatcher_Impl_T.i
+# End Source File
+# Begin Source File
+SOURCE=.\Kokyu.i
# End Source File
# Begin Source File
-SOURCE=.\DSRT_Dispatcher_Impl.i
+SOURCE=.\Kokyu_defs.i
+# End Source File
+# Begin Source File
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
+SOURCE=.\Kokyu_dsrt.i
+# End Source File
+# End Group
+# Begin Group "Template Files"
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
+# PROP Default_Filter ""
+# Begin Source File
+SOURCE=.\DSRT_Direct_Dispatcher_Impl_T
# PROP Exclude_From_Build 1
-
-!ENDIF
-
# End Source File
# Begin Source File
-SOURCE=.\Kokyu.i
-
-!IF "$(CFG)" == "Kokyu_Static - Win32 Release"
-
-!ELSEIF "$(CFG)" == "Kokyu_Static - Win32 Debug"
+SOURCE=.\DSRT_Dispatch_Item_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+SOURCE=.\DSRT_Dispatcher_Impl_T
# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
-!ENDIF
+SOURCE=.\DSRT_Sched_Queue_T
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+SOURCE=.\Kokyu_dsrt
+# PROP Exclude_From_Build 1
# End Source File
# End Group
# End Target
diff --git a/Kokyu/Kokyu_defs.cpp b/Kokyu/Kokyu_defs.cpp new file mode 100644 index 00000000000..030c1da88f6 --- /dev/null +++ b/Kokyu/Kokyu_defs.cpp @@ -0,0 +1,16 @@ +// $Id$ + +#include "Kokyu_defs.h" + +#if ! defined (__ACE_INLINE__) +#include "Kokyu_defs.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, Kokyu_defs, "$Id$") + +namespace Kokyu +{ + Dispatch_Command::~Dispatch_Command (void) + { + } +} diff --git a/Kokyu/Kokyu_defs.h b/Kokyu/Kokyu_defs.h new file mode 100644 index 00000000000..fd6ac4ac09d --- /dev/null +++ b/Kokyu/Kokyu_defs.h @@ -0,0 +1,138 @@ +/* -*- C++ -*- */ +/** + * @file Kokyu_defs.h + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +#ifndef KOKYU_DEFS_H +#define KOKYU_DEFS_H +#include "ace/pre.h" +#include "ace/Array.h" +#include "ace/Time_Value.h" +#include "ace/Auto_Ptr.h" +#include "ace/Message_Block.h" +#include "ace/Sched_Params.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "kokyu_export.h" + +namespace Kokyu +{ + typedef long Priority_t; + typedef ACE_Time_Value Deadline_t; //absolute deadline + typedef ACE_Time_Value Execution_Time_t; //execution time + //typedef int Guid_t; + + enum Dispatching_Type_t + // Defines the type of prioritization strategy + // to be used by a dispatching queue + { + FIFO_DISPATCHING, + DEADLINE_DISPATCHING, + LAXITY_DISPATCHING + }; + + enum Criticality_t + // Defines the criticality of the operation. + // For use with Dynamic Scheduler. + { + VERY_LOW_CRITICALITY, + LOW_CRITICALITY, + MEDIUM_CRITICALITY, + HIGH_CRITICALITY, + VERY_HIGH_CRITICALITY + }; + + enum Importance_t + // Defines the importance of the operation, + // which can be used by the RtecScheduler as a + // "tie-breaker" when other scheduling + // parameters are equal. + { + VERY_LOW_IMPORTANCE, + LOW_IMPORTANCE, + MEDIUM_IMPORTANCE, + HIGH_IMPORTANCE, + VERY_HIGH_IMPORTANCE + }; + + struct ConfigInfo + { + Priority_t preemption_priority_; + + // OS priority of the dispatching thread associated with the queue + Priority_t thread_priority_; + + // type of dispatching queue + Dispatching_Type_t dispatching_type_; + }; + + typedef ACE_Array<ConfigInfo> ConfigInfoSet; + + struct QoSDescriptor + { + Priority_t preemption_priority_; + Deadline_t deadline_; + Execution_Time_t execution_time_; + Importance_t importance_; + }; + + enum Block_Flag_t {BLOCK, UNBLOCK}; + + /* + struct DSRT_QoSDescriptor + { + long importance_; + long criticality_; + Priority_t priority_; + Deadline_t deadline_; + Execution_Time_t exec_time_; + }; + */ + + class Kokyu_Export Dispatch_Command + { + public: + Dispatch_Command(int dont_delete = 0); + + /// Command callback + virtual int execute () = 0; + + int can_be_deleted () const; + + void destroy (void); + protected: + /// Destructor + // only inheritance is possible and object should be on heap, + // since object could be handed over to a different thread. + virtual ~Dispatch_Command (void); + + private: + int dont_delete_; + }; + + class non_copyable + { + protected: + non_copyable (void); + ~non_copyable (void); + private: + non_copyable (const non_copyable&); + const non_copyable& operator= (const non_copyable&); + }; + +} //end of namespace + +#if defined (__ACE_INLINE__) +#include "Kokyu_defs.i" +#endif /* __ACE_INLINE__ */ + +#include "ace/post.h" +#endif /* KOKYU_DEFS_H */ diff --git a/Kokyu/Kokyu_defs.i b/Kokyu/Kokyu_defs.i new file mode 100644 index 00000000000..1613418540d --- /dev/null +++ b/Kokyu/Kokyu_defs.i @@ -0,0 +1,36 @@ +// $Id$ + + +namespace Kokyu +{ + +ACE_INLINE +Dispatch_Command::Dispatch_Command (int dont_delete) + :dont_delete_ (dont_delete) +{ +} + +ACE_INLINE +int Dispatch_Command::can_be_deleted (void) const +{ + return !dont_delete_; +} + +ACE_INLINE +void Dispatch_Command::destroy (void) +{ + //@@what if it was allocated thru an allocator? + //may be this should be left as a pure virtual + delete this; +} + +ACE_INLINE +non_copyable::non_copyable (void) +{ +} + +ACE_INLINE +non_copyable::~non_copyable (void) +{} + +} diff --git a/Kokyu/Kokyu_dsrt.cpp b/Kokyu/Kokyu_dsrt.cpp new file mode 100644 index 00000000000..e46d3952fdb --- /dev/null +++ b/Kokyu/Kokyu_dsrt.cpp @@ -0,0 +1,158 @@ +// $Id$ + +#include "Kokyu_dsrt.h" + +#include "ace/Dynamic_Service.h" +#include "DSRT_Direct_Dispatcher_Impl_T.h" + +#if ! defined (__ACE_INLINE__) +#include "Kokyu.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(Kokyu, Kokyu, "$Id$") + +namespace Kokyu +{ + +template <class DSRT_Scheduler_Traits> +void +DSRT_Dispatcher<DSRT_Scheduler_Traits>::implementation (DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>* impl) +{ + auto_ptr<DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits> > tmp_impl (impl); + dispatcher_impl_ = tmp_impl; +} + +template <class DSRT_Scheduler_Traits> +int +DSRT_Dispatcher<DSRT_Scheduler_Traits>::schedule (Guid_t guid, const DSRT_QoSDescriptor& qos) +{ + return dispatcher_impl_->schedule (guid, qos); +} + +template <class DSRT_Scheduler_Traits> +int +DSRT_Dispatcher<DSRT_Scheduler_Traits>::update_schedule (Guid_t guid, const DSRT_QoSDescriptor& qos) +{ + return dispatcher_impl_->update_schedule (guid, qos); +} + +template <class DSRT_Scheduler_Traits> +int +DSRT_Dispatcher<DSRT_Scheduler_Traits>::update_schedule (Guid_t guid, Kokyu::Block_Flag_t flag) +{ + return dispatcher_impl_->update_schedule (guid, flag); +} + +template <class DSRT_Scheduler_Traits> +int +DSRT_Dispatcher<DSRT_Scheduler_Traits>::cancel_schedule (Guid_t guid) +{ + return dispatcher_impl_->cancel_schedule (guid); +} + +template <class DSRT_Scheduler_Traits> +int DSRT_Dispatcher<DSRT_Scheduler_Traits>::shutdown () +{ + return dispatcher_impl_->shutdown (); +} + +template <class DSRT_Scheduler_Traits> +typename DSRT_Dispatcher_Factory<DSRT_Scheduler_Traits>::DSRT_Dispatcher_Auto_Ptr +DSRT_Dispatcher_Factory<DSRT_Scheduler_Traits>:: +create_DSRT_dispatcher (const DSRT_ConfigInfo& config_info) +{ + ACE_UNUSED_ARG ((config_info)); + + DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>* tmp; + DSRT_Dispatcher<DSRT_Scheduler_Traits>* disp; + DSRT_Dispatcher_Auto_Ptr nil_ptr((DSRT_Dispatcher<DSRT_Scheduler_Traits>*)0); + + //DSRT_Dispatcher_Impl::init_svcs (); + + //ACE_Service_Config::open ("Kokyu", ACE_DEFAULT_LOGGER_KEY, 0); + + //tmp = + // ACE_Dynamic_Service<DSRT_Dispatcher_Impl>::instance ("DSRT_Dispatcher_Impl"); + + ACE_NEW_RETURN (tmp, DSRT_Direct_Dispatcher_Impl<DSRT_Scheduler_Traits>, nil_ptr); + ACE_ASSERT (tmp != 0); + ACE_NEW_RETURN (disp, DSRT_Dispatcher<DSRT_Scheduler_Traits>, nil_ptr); + DSRT_Dispatcher_Auto_Ptr disp_auto_ptr(disp); + disp->implementation (tmp); + tmp->init (config_info); + return disp_auto_ptr; +} + +template <class QoSDescriptor> +int MUF_Comparator<QoSDescriptor>:: +operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2) +{ + if (qos1.criticality_ > qos2.criticality_) + { + return 1; + } + + typename QoSDescriptor::Now now_functor; + Time_t now = now_functor (); + + Time_t exec_time1 = qos1.exec_time_; + Time_t deadline1 = qos1.deadline_; + Time_t laxity1 = deadline1 - now - exec_time1; + Time_t exec_time2 = qos2.exec_time_; + Time_t deadline2 = qos2.deadline_; + Time_t laxity2 = deadline2 - now - exec_time2; + + if (laxity1 < laxity2) + { + return 1; + } + else if (laxity1 == laxity2) + { + return 0; + } + else + { + return -1; + } +} + +template <class QoSDescriptor> +int MIF_Comparator<QoSDescriptor>:: +operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2) +{ + if (qos1.importance_ > qos2.importance_) + { + return 1; + } + else if (qos1.importance_ == qos2.importance_) + { + return 0; + } + else + { + return -1; + } +} + +template <class QoSDescriptor> +int Fixed_Priority_Comparator<QoSDescriptor>:: +operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2) +{ + if (qos1.priority_ > qos2.priority_) + { + return 1; + } + else if (qos1.priority_ == qos2.priority_) + { + return 0; + } + else + { + return -1; + } +} + +} diff --git a/Kokyu/Kokyu_dsrt.h b/Kokyu/Kokyu_dsrt.h new file mode 100644 index 00000000000..df4e36e323a --- /dev/null +++ b/Kokyu/Kokyu_dsrt.h @@ -0,0 +1,187 @@ +/* -*- C++ -*- */ +/** + * @file Kokyu_dsrt.h + * + * $Id$ + * + * @author Venkita Subramonian (venkita@cs.wustl.edu) + * + */ + +#ifndef KOKYU_DSRT_H +#define KOKYU_DSRT_H +#include "ace/pre.h" + +//#if !defined (ACE_LACKS_PRAGMA_ONCE) +//# pragma once +//#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "kokyu_export.h" +#include "Kokyu_defs.h" + +namespace Kokyu +{ + enum DSRT_Sched_Type_t + { + DSRT_FP, + DSRT_MUF, + DSRT_MIF + }; + + struct DSRT_ConfigInfo + { + DSRT_Sched_Type_t sched_strategy_; + }; + + template <class DSRT_Scheduler_Traits> class DSRT_Dispatcher_Impl; + + /** + * @class DSRT_Dispatcher + * + * @brief Interface class for dynamic scheduling of threads + * + * The responsibility of this class is to forward all methods to + * its delegation/implementation class, e.g., + * @c Default_DSRT_Dispatcher_Impl. This class follows the pImpl idiom + * or the bridge pattern to separate the implementation from the interface. + * DSRT_Dispatcher is the class that users will be using to achieve + * dynamic scheduling of threads. + */ + template <class DSRT_Scheduler_Traits> + class Kokyu_Export DSRT_Dispatcher : private non_copyable + { + public: + typedef typename DSRT_Scheduler_Traits::Guid_t Guid_t; + typedef typename DSRT_Scheduler_Traits::QoSDescriptor_t DSRT_QoSDescriptor; + + // = Scheduling methods. + + /// Schedule a thread dynamically based on the qos info supplied. + int schedule (Guid_t guid, const DSRT_QoSDescriptor&); + + /// Update the schedule for a thread. This could alter the current schedule. + int update_schedule (Guid_t guid, const DSRT_QoSDescriptor&); + + /// Inform the scheduler that the caller thread is about to + /// block. This could alter the current schedule. + int update_schedule (Guid_t guid, Kokyu::Block_Flag_t flag); + + /// Cancel the schedule for a thread. This could alter the current schedule. + int cancel_schedule (Guid_t guid); + + /// Supply this interface with an appropriate implementation. + void implementation (DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits>*); + + // = Termination methods. + + /// Shut down the dispatcher. The dispatcher will stop processing requests. + int shutdown (); + + /// Non virtual destructor. Read as <b><i>this class not available + /// for inheritance<i></b>. + ~DSRT_Dispatcher (); + + private: + /// Auto ptr to the implementation. Implementation will be created on the + /// heap and deleted automatically when the dispatcher object is destructed. + auto_ptr<DSRT_Dispatcher_Impl<DSRT_Scheduler_Traits> > dispatcher_impl_; + }; + + + /** + * @class DSRT_Dispatcher_Factory + * + * @brief Factory class to create one of the dispatcher interface + * objects - for events or DSRT threads. + * + * Factory class creates a dispatcher or DSRT dispatcher and configures + * the interface object with the appropriate implementation. + */ + + template <class DSRT_Scheduler_Traits> + class Kokyu_Export DSRT_Dispatcher_Factory : private non_copyable + { + public: + typedef auto_ptr<DSRT_Dispatcher<DSRT_Scheduler_Traits> > DSRT_Dispatcher_Auto_Ptr; + + /** + * Create a dispatcher for dynamic dispatching of threads. + * This will be used to dynamic scheduling of distributable threads for + * DSRTCORBA. The caller is responsible for freeing the memory. + * + * @param config Configuration information for the DSRT dispatcher. + * + * @return Auto pointer to the DSRT dispatcher. + */ + static DSRT_Dispatcher_Auto_Ptr create_DSRT_dispatcher (const DSRT_ConfigInfo&); + }; + + /** + * @class MIF_Sched_Strategy + * + * @brief Strategy class implementing Maximum Importance First + * reordering strategy. + * + */ + template <class QoSDescriptor> + class MIF_Comparator + { + public: + typedef typename QoSDescriptor::Importance_t Importance_t; + + int operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2); + }; + + /** + * @class Fixed_Priority_Sched_Strategy + * + * @brief Strategy class implementing Fixed Priority reordering + * strategy. + * + */ + template <class QoSDescriptor> + class Fixed_Priority_Comparator + { + public: + typedef typename QoSDescriptor::Priority_t Priority_t; + + int operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2); + }; + + /** + * @class MUF_Sched_Strategy + * + * @brief Strategy class implementing Maximum Urgency First + * reordering strategy. + * + */ + template <class QoSDescriptor> + class MUF_Comparator + { + public: + typedef typename QoSDescriptor::Criticality_t Criticality_t; + typedef typename QoSDescriptor::Time_t Time_t; + + int operator ()(const QoSDescriptor& qos1, + const QoSDescriptor& qos2); + }; + + +} //end of namespace + +#if defined (__ACE_INLINE__) +#include "Kokyu_dsrt.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Kokyu_dsrt.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Kokyu_dsrt.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include "ace/post.h" +#endif /* KOKYU_DSRT_H */ diff --git a/Kokyu/Kokyu_dsrt.i b/Kokyu/Kokyu_dsrt.i new file mode 100644 index 00000000000..1f9caf3c234 --- /dev/null +++ b/Kokyu/Kokyu_dsrt.i @@ -0,0 +1,11 @@ +// $Id$ + +namespace Kokyu +{ +template <class DSRT_Scheduler_Traits> +ACE_INLINE +DSRT_Dispatcher<DSRT_Scheduler_Traits>::~DSRT_Dispatcher() +{ +} +} + diff --git a/Kokyu/Makefile b/Kokyu/Makefile index 38c133d2a9e..975a19a51ad 100644 --- a/Kokyu/Makefile +++ b/Kokyu/Makefile @@ -1,584 +1,15 @@ -#---------------------------------------------------------------------------- -# # $Id$ -# -#---------------------------------------------------------------------------- - -MAKEFILE = Makefile -LIBNAME = libKokyu -LIB = $(LIBNAME).a -SHLIB = $(LIBNAME).$(SOEXT) - -CPP_SRCS += \ - Kokyu \ - Dispatcher_Impl \ - Dispatcher_Task \ - Default_Dispatcher_Impl \ - DSRT_Dispatcher_Impl \ - DSRT_Schedulers - -FILES = $(CPP_SRCS) -DEFS = $(addsuffix .h,$(FILES)) -LSRC = $(addsuffix .cpp,$(FILES)) -LIBS=$(ACELIB) #---------------------------------------------------------------------------- -# Include macros and targets +# GNU Workspace #---------------------------------------------------------------------------- -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU +TARGETS_NESTED := $(TARGETS_NESTED:.nested=) -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -ifeq ($(shared_libs),1) -ifneq ($(SHLIB),) -CPPFLAGS += -DKOKYU_BUILD_DLL -endif -endif -ifeq ($(static_libs),1) -ifneq ($(LIB),) -CPPFLAGS += -DACE_AS_STATIC_LIBS +$(TARGETS_NESTED): +ifneq (Windows,$(findstring Windows,$(OS))) + @$(MAKE) -f Makefile.Kokyu -C . $(@); +else + -@cmd /c "$(MAKE) -f Makefile.Kokyu -C . $(@)" endif -endif - - - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - - - -# DO NOT DELETE THIS LINE -- g++dep uses it. -# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. - - -.obj/Kokyu.o .obj/Kokyu.so .shobj/Kokyu.o .shobj/Kokyu.so: Kokyu.cpp Kokyu.h \ - $(ACE_ROOT)/ace/pre.h \ - $(ACE_ROOT)/ace/Auto_Ptr.h \ - $(ACE_ROOT)/ace/post.h \ - $(ACE_ROOT)/ace/ace_wchar.h \ - $(ACE_ROOT)/ace/ace_wchar.inl \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/ACE_export.h \ - $(ACE_ROOT)/ace/Global_Macros.h \ - $(ACE_ROOT)/ace/OS_Export.h \ - $(ACE_ROOT)/ace/Auto_Ptr.i \ - $(ACE_ROOT)/ace/Auto_Ptr.cpp \ - kokyu_export.h Kokyu.i Default_Dispatcher_Impl.h \ - $(ACE_ROOT)/ace/Task.h \ - $(ACE_ROOT)/ace/Service_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.h \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/OS_Dirent.h \ - $(ACE_ROOT)/ace/OS_Errno.h \ - $(ACE_ROOT)/ace/OS_Errno.inl \ - $(ACE_ROOT)/ace/OS_Dirent.inl \ - $(ACE_ROOT)/ace/OS_String.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS_String.inl \ - $(ACE_ROOT)/ace/OS_Memory.h \ - $(ACE_ROOT)/ace/OS_Memory.inl \ - $(ACE_ROOT)/ace/OS_TLI.h \ - $(ACE_ROOT)/ace/OS_TLI.inl \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/Time_Value.inl \ - $(ACE_ROOT)/ace/Default_Constants.h \ - $(ACE_ROOT)/ace/Min_Max.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Shared_Object.i \ - $(ACE_ROOT)/ace/Svc_Conf_Tokens.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/DLL.h \ - $(ACE_ROOT)/ace/Service_Object.i \ - $(ACE_ROOT)/ace/Thread_Manager.h \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread_Adapter.h \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.inl \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Thread_Exit.h \ - $(ACE_ROOT)/ace/Thread_Control.h \ - $(ACE_ROOT)/ace/Thread_Control.inl \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Synch_T.cpp \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Unbounded_Queue.h \ - $(ACE_ROOT)/ace/Node.h \ - $(ACE_ROOT)/ace/Node.cpp \ - $(ACE_ROOT)/ace/Unbounded_Queue.inl \ - $(ACE_ROOT)/ace/Unbounded_Queue.cpp \ - $(ACE_ROOT)/ace/Malloc_Base.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Containers_T.h \ - $(ACE_ROOT)/ace/Array_Base.h \ - $(ACE_ROOT)/ace/Array_Base.inl \ - $(ACE_ROOT)/ace/Array_Base.cpp \ - $(ACE_ROOT)/ace/Unbounded_Set.h \ - $(ACE_ROOT)/ace/Unbounded_Set.inl \ - $(ACE_ROOT)/ace/Unbounded_Set.cpp \ - $(ACE_ROOT)/ace/Containers_T.i \ - $(ACE_ROOT)/ace/Containers_T.cpp \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Free_List.cpp \ - $(ACE_ROOT)/ace/Singleton.h \ - $(ACE_ROOT)/ace/Singleton.i \ - $(ACE_ROOT)/ace/Singleton.cpp \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Managed_Object.cpp \ - $(ACE_ROOT)/ace/Framework_Component.h \ - $(ACE_ROOT)/ace/Framework_Component.inl \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/Flag_Manip.h \ - $(ACE_ROOT)/ace/Flag_Manip.i \ - $(ACE_ROOT)/ace/Handle_Ops.h \ - $(ACE_ROOT)/ace/Handle_Ops.i \ - $(ACE_ROOT)/ace/Lib_Find.h \ - $(ACE_ROOT)/ace/Lib_Find.i \ - $(ACE_ROOT)/ace/Init_ACE.h \ - $(ACE_ROOT)/ace/Init_ACE.i \ - $(ACE_ROOT)/ace/Sock_Connect.h \ - $(ACE_ROOT)/ace/Sock_Connect.i \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Framework_Component_T.h \ - $(ACE_ROOT)/ace/Framework_Component_T.inl \ - $(ACE_ROOT)/ace/Framework_Component_T.cpp \ - $(ACE_ROOT)/ace/Thread_Manager.i \ - $(ACE_ROOT)/ace/Task.i \ - $(ACE_ROOT)/ace/Task_T.h \ - $(ACE_ROOT)/ace/Message_Queue.h \ - $(ACE_ROOT)/ace/Message_Block.h \ - $(ACE_ROOT)/ace/Message_Block.i \ - $(ACE_ROOT)/ace/Message_Block_T.h \ - $(ACE_ROOT)/ace/Message_Block_T.i \ - $(ACE_ROOT)/ace/Message_Block_T.cpp \ - $(ACE_ROOT)/ace/IO_Cntl_Msg.h \ - $(ACE_ROOT)/ace/Message_Queue_T.h \ - $(ACE_ROOT)/ace/Message_Queue_T.i \ - $(ACE_ROOT)/ace/Message_Queue_T.cpp \ - $(ACE_ROOT)/ace/Notification_Strategy.h \ - $(ACE_ROOT)/ace/Notification_Strategy.inl \ - $(ACE_ROOT)/ace/Message_Queue.i \ - $(ACE_ROOT)/ace/Task_T.i \ - $(ACE_ROOT)/ace/Task_T.cpp \ - $(ACE_ROOT)/ace/Module.h \ - $(ACE_ROOT)/ace/Module.i \ - $(ACE_ROOT)/ace/Module.cpp \ - $(ACE_ROOT)/ace/Stream_Modules.h \ - $(ACE_ROOT)/ace/Stream_Modules.cpp \ - Dispatcher_Impl.h Dispatcher_Impl.i Dispatcher_Task.h \ - Dispatcher_Task.i Default_Dispatcher_Impl.i - -.obj/Dispatcher_Impl.o .obj/Dispatcher_Impl.so .shobj/Dispatcher_Impl.o .shobj/Dispatcher_Impl.so: Dispatcher_Impl.cpp Dispatcher_Impl.h \ - $(ACE_ROOT)/ace/pre.h \ - $(ACE_ROOT)/ace/Task.h \ - $(ACE_ROOT)/ace/Service_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.h \ - $(ACE_ROOT)/ace/ACE_export.h \ - $(ACE_ROOT)/ace/post.h \ - $(ACE_ROOT)/ace/ace_wchar.h \ - $(ACE_ROOT)/ace/ace_wchar.inl \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/OS_Dirent.h \ - $(ACE_ROOT)/ace/OS_Export.h \ - $(ACE_ROOT)/ace/OS_Errno.h \ - $(ACE_ROOT)/ace/OS_Errno.inl \ - $(ACE_ROOT)/ace/OS_Dirent.inl \ - $(ACE_ROOT)/ace/OS_String.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS_String.inl \ - $(ACE_ROOT)/ace/OS_Memory.h \ - $(ACE_ROOT)/ace/OS_Memory.inl \ - $(ACE_ROOT)/ace/OS_TLI.h \ - $(ACE_ROOT)/ace/OS_TLI.inl \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/Time_Value.inl \ - $(ACE_ROOT)/ace/Default_Constants.h \ - $(ACE_ROOT)/ace/Global_Macros.h \ - $(ACE_ROOT)/ace/Min_Max.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Shared_Object.i \ - $(ACE_ROOT)/ace/Svc_Conf_Tokens.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/DLL.h \ - $(ACE_ROOT)/ace/Service_Object.i \ - $(ACE_ROOT)/ace/Thread_Manager.h \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread_Adapter.h \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.inl \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Thread_Exit.h \ - $(ACE_ROOT)/ace/Thread_Control.h \ - $(ACE_ROOT)/ace/Thread_Control.inl \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Synch_T.cpp \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Unbounded_Queue.h \ - $(ACE_ROOT)/ace/Node.h \ - $(ACE_ROOT)/ace/Node.cpp \ - $(ACE_ROOT)/ace/Unbounded_Queue.inl \ - $(ACE_ROOT)/ace/Unbounded_Queue.cpp \ - $(ACE_ROOT)/ace/Malloc_Base.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Containers_T.h \ - $(ACE_ROOT)/ace/Array_Base.h \ - $(ACE_ROOT)/ace/Array_Base.inl \ - $(ACE_ROOT)/ace/Array_Base.cpp \ - $(ACE_ROOT)/ace/Unbounded_Set.h \ - $(ACE_ROOT)/ace/Unbounded_Set.inl \ - $(ACE_ROOT)/ace/Unbounded_Set.cpp \ - $(ACE_ROOT)/ace/Containers_T.i \ - $(ACE_ROOT)/ace/Containers_T.cpp \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Free_List.cpp \ - $(ACE_ROOT)/ace/Singleton.h \ - $(ACE_ROOT)/ace/Singleton.i \ - $(ACE_ROOT)/ace/Singleton.cpp \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Managed_Object.cpp \ - $(ACE_ROOT)/ace/Framework_Component.h \ - $(ACE_ROOT)/ace/Framework_Component.inl \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/Flag_Manip.h \ - $(ACE_ROOT)/ace/Flag_Manip.i \ - $(ACE_ROOT)/ace/Handle_Ops.h \ - $(ACE_ROOT)/ace/Handle_Ops.i \ - $(ACE_ROOT)/ace/Lib_Find.h \ - $(ACE_ROOT)/ace/Lib_Find.i \ - $(ACE_ROOT)/ace/Init_ACE.h \ - $(ACE_ROOT)/ace/Init_ACE.i \ - $(ACE_ROOT)/ace/Sock_Connect.h \ - $(ACE_ROOT)/ace/Sock_Connect.i \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Framework_Component_T.h \ - $(ACE_ROOT)/ace/Framework_Component_T.inl \ - $(ACE_ROOT)/ace/Framework_Component_T.cpp \ - $(ACE_ROOT)/ace/Thread_Manager.i \ - $(ACE_ROOT)/ace/Task.i \ - $(ACE_ROOT)/ace/Task_T.h \ - $(ACE_ROOT)/ace/Message_Queue.h \ - $(ACE_ROOT)/ace/Message_Block.h \ - $(ACE_ROOT)/ace/Message_Block.i \ - $(ACE_ROOT)/ace/Message_Block_T.h \ - $(ACE_ROOT)/ace/Message_Block_T.i \ - $(ACE_ROOT)/ace/Message_Block_T.cpp \ - $(ACE_ROOT)/ace/IO_Cntl_Msg.h \ - $(ACE_ROOT)/ace/Message_Queue_T.h \ - $(ACE_ROOT)/ace/Message_Queue_T.i \ - $(ACE_ROOT)/ace/Message_Queue_T.cpp \ - $(ACE_ROOT)/ace/Notification_Strategy.h \ - $(ACE_ROOT)/ace/Notification_Strategy.inl \ - $(ACE_ROOT)/ace/Message_Queue.i \ - $(ACE_ROOT)/ace/Task_T.i \ - $(ACE_ROOT)/ace/Task_T.cpp \ - $(ACE_ROOT)/ace/Module.h \ - $(ACE_ROOT)/ace/Module.i \ - $(ACE_ROOT)/ace/Module.cpp \ - $(ACE_ROOT)/ace/Stream_Modules.h \ - $(ACE_ROOT)/ace/Stream_Modules.cpp \ - $(ACE_ROOT)/ace/Auto_Ptr.h \ - $(ACE_ROOT)/ace/Auto_Ptr.i \ - $(ACE_ROOT)/ace/Auto_Ptr.cpp \ - kokyu_export.h Kokyu.h Kokyu.i Dispatcher_Impl.i - -.obj/Dispatcher_Task.o .obj/Dispatcher_Task.so .shobj/Dispatcher_Task.o .shobj/Dispatcher_Task.so: Dispatcher_Task.cpp Dispatcher_Task.h \ - $(ACE_ROOT)/ace/pre.h \ - $(ACE_ROOT)/ace/Task.h \ - $(ACE_ROOT)/ace/Service_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.h \ - $(ACE_ROOT)/ace/ACE_export.h \ - $(ACE_ROOT)/ace/post.h \ - $(ACE_ROOT)/ace/ace_wchar.h \ - $(ACE_ROOT)/ace/ace_wchar.inl \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/OS_Dirent.h \ - $(ACE_ROOT)/ace/OS_Export.h \ - $(ACE_ROOT)/ace/OS_Errno.h \ - $(ACE_ROOT)/ace/OS_Errno.inl \ - $(ACE_ROOT)/ace/OS_Dirent.inl \ - $(ACE_ROOT)/ace/OS_String.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS_String.inl \ - $(ACE_ROOT)/ace/OS_Memory.h \ - $(ACE_ROOT)/ace/OS_Memory.inl \ - $(ACE_ROOT)/ace/OS_TLI.h \ - $(ACE_ROOT)/ace/OS_TLI.inl \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/Time_Value.inl \ - $(ACE_ROOT)/ace/Default_Constants.h \ - $(ACE_ROOT)/ace/Global_Macros.h \ - $(ACE_ROOT)/ace/Min_Max.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Shared_Object.i \ - $(ACE_ROOT)/ace/Svc_Conf_Tokens.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/DLL.h \ - $(ACE_ROOT)/ace/Service_Object.i \ - $(ACE_ROOT)/ace/Thread_Manager.h \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread_Adapter.h \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.inl \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Thread_Exit.h \ - $(ACE_ROOT)/ace/Thread_Control.h \ - $(ACE_ROOT)/ace/Thread_Control.inl \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Synch_T.cpp \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Unbounded_Queue.h \ - $(ACE_ROOT)/ace/Node.h \ - $(ACE_ROOT)/ace/Node.cpp \ - $(ACE_ROOT)/ace/Unbounded_Queue.inl \ - $(ACE_ROOT)/ace/Unbounded_Queue.cpp \ - $(ACE_ROOT)/ace/Malloc_Base.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Containers_T.h \ - $(ACE_ROOT)/ace/Array_Base.h \ - $(ACE_ROOT)/ace/Array_Base.inl \ - $(ACE_ROOT)/ace/Array_Base.cpp \ - $(ACE_ROOT)/ace/Unbounded_Set.h \ - $(ACE_ROOT)/ace/Unbounded_Set.inl \ - $(ACE_ROOT)/ace/Unbounded_Set.cpp \ - $(ACE_ROOT)/ace/Containers_T.i \ - $(ACE_ROOT)/ace/Containers_T.cpp \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Free_List.cpp \ - $(ACE_ROOT)/ace/Singleton.h \ - $(ACE_ROOT)/ace/Singleton.i \ - $(ACE_ROOT)/ace/Singleton.cpp \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Managed_Object.cpp \ - $(ACE_ROOT)/ace/Framework_Component.h \ - $(ACE_ROOT)/ace/Framework_Component.inl \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/Flag_Manip.h \ - $(ACE_ROOT)/ace/Flag_Manip.i \ - $(ACE_ROOT)/ace/Handle_Ops.h \ - $(ACE_ROOT)/ace/Handle_Ops.i \ - $(ACE_ROOT)/ace/Lib_Find.h \ - $(ACE_ROOT)/ace/Lib_Find.i \ - $(ACE_ROOT)/ace/Init_ACE.h \ - $(ACE_ROOT)/ace/Init_ACE.i \ - $(ACE_ROOT)/ace/Sock_Connect.h \ - $(ACE_ROOT)/ace/Sock_Connect.i \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Framework_Component_T.h \ - $(ACE_ROOT)/ace/Framework_Component_T.inl \ - $(ACE_ROOT)/ace/Framework_Component_T.cpp \ - $(ACE_ROOT)/ace/Thread_Manager.i \ - $(ACE_ROOT)/ace/Task.i \ - $(ACE_ROOT)/ace/Task_T.h \ - $(ACE_ROOT)/ace/Message_Queue.h \ - $(ACE_ROOT)/ace/Message_Block.h \ - $(ACE_ROOT)/ace/Message_Block.i \ - $(ACE_ROOT)/ace/Message_Block_T.h \ - $(ACE_ROOT)/ace/Message_Block_T.i \ - $(ACE_ROOT)/ace/Message_Block_T.cpp \ - $(ACE_ROOT)/ace/IO_Cntl_Msg.h \ - $(ACE_ROOT)/ace/Message_Queue_T.h \ - $(ACE_ROOT)/ace/Message_Queue_T.i \ - $(ACE_ROOT)/ace/Message_Queue_T.cpp \ - $(ACE_ROOT)/ace/Notification_Strategy.h \ - $(ACE_ROOT)/ace/Notification_Strategy.inl \ - $(ACE_ROOT)/ace/Message_Queue.i \ - $(ACE_ROOT)/ace/Task_T.i \ - $(ACE_ROOT)/ace/Task_T.cpp \ - $(ACE_ROOT)/ace/Module.h \ - $(ACE_ROOT)/ace/Module.i \ - $(ACE_ROOT)/ace/Module.cpp \ - $(ACE_ROOT)/ace/Stream_Modules.h \ - $(ACE_ROOT)/ace/Stream_Modules.cpp \ - kokyu_export.h Kokyu.h \ - $(ACE_ROOT)/ace/Auto_Ptr.h \ - $(ACE_ROOT)/ace/Auto_Ptr.i \ - $(ACE_ROOT)/ace/Auto_Ptr.cpp Kokyu.i \ - Dispatcher_Task.i - -.obj/Default_Dispatcher_Impl.o .obj/Default_Dispatcher_Impl.so .shobj/Default_Dispatcher_Impl.o .shobj/Default_Dispatcher_Impl.so: Default_Dispatcher_Impl.cpp \ - Default_Dispatcher_Impl.h \ - $(ACE_ROOT)/ace/pre.h \ - $(ACE_ROOT)/ace/Task.h \ - $(ACE_ROOT)/ace/Service_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.h \ - $(ACE_ROOT)/ace/ACE_export.h \ - $(ACE_ROOT)/ace/post.h \ - $(ACE_ROOT)/ace/ace_wchar.h \ - $(ACE_ROOT)/ace/ace_wchar.inl \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/OS_Dirent.h \ - $(ACE_ROOT)/ace/OS_Export.h \ - $(ACE_ROOT)/ace/OS_Errno.h \ - $(ACE_ROOT)/ace/OS_Errno.inl \ - $(ACE_ROOT)/ace/OS_Dirent.inl \ - $(ACE_ROOT)/ace/OS_String.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS_String.inl \ - $(ACE_ROOT)/ace/OS_Memory.h \ - $(ACE_ROOT)/ace/OS_Memory.inl \ - $(ACE_ROOT)/ace/OS_TLI.h \ - $(ACE_ROOT)/ace/OS_TLI.inl \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/Time_Value.inl \ - $(ACE_ROOT)/ace/Default_Constants.h \ - $(ACE_ROOT)/ace/Global_Macros.h \ - $(ACE_ROOT)/ace/Min_Max.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Shared_Object.i \ - $(ACE_ROOT)/ace/Svc_Conf_Tokens.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/DLL.h \ - $(ACE_ROOT)/ace/Service_Object.i \ - $(ACE_ROOT)/ace/Thread_Manager.h \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread_Adapter.h \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ - $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.inl \ - $(ACE_ROOT)/ace/Base_Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread_Adapter.inl \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Thread_Exit.h \ - $(ACE_ROOT)/ace/Thread_Control.h \ - $(ACE_ROOT)/ace/Thread_Control.inl \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Synch_T.cpp \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Unbounded_Queue.h \ - $(ACE_ROOT)/ace/Node.h \ - $(ACE_ROOT)/ace/Node.cpp \ - $(ACE_ROOT)/ace/Unbounded_Queue.inl \ - $(ACE_ROOT)/ace/Unbounded_Queue.cpp \ - $(ACE_ROOT)/ace/Malloc_Base.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Containers_T.h \ - $(ACE_ROOT)/ace/Array_Base.h \ - $(ACE_ROOT)/ace/Array_Base.inl \ - $(ACE_ROOT)/ace/Array_Base.cpp \ - $(ACE_ROOT)/ace/Unbounded_Set.h \ - $(ACE_ROOT)/ace/Unbounded_Set.inl \ - $(ACE_ROOT)/ace/Unbounded_Set.cpp \ - $(ACE_ROOT)/ace/Containers_T.i \ - $(ACE_ROOT)/ace/Containers_T.cpp \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Free_List.cpp \ - $(ACE_ROOT)/ace/Singleton.h \ - $(ACE_ROOT)/ace/Singleton.i \ - $(ACE_ROOT)/ace/Singleton.cpp \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Managed_Object.cpp \ - $(ACE_ROOT)/ace/Framework_Component.h \ - $(ACE_ROOT)/ace/Framework_Component.inl \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/Flag_Manip.h \ - $(ACE_ROOT)/ace/Flag_Manip.i \ - $(ACE_ROOT)/ace/Handle_Ops.h \ - $(ACE_ROOT)/ace/Handle_Ops.i \ - $(ACE_ROOT)/ace/Lib_Find.h \ - $(ACE_ROOT)/ace/Lib_Find.i \ - $(ACE_ROOT)/ace/Init_ACE.h \ - $(ACE_ROOT)/ace/Init_ACE.i \ - $(ACE_ROOT)/ace/Sock_Connect.h \ - $(ACE_ROOT)/ace/Sock_Connect.i \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Framework_Component_T.h \ - $(ACE_ROOT)/ace/Framework_Component_T.inl \ - $(ACE_ROOT)/ace/Framework_Component_T.cpp \ - $(ACE_ROOT)/ace/Thread_Manager.i \ - $(ACE_ROOT)/ace/Task.i \ - $(ACE_ROOT)/ace/Task_T.h \ - $(ACE_ROOT)/ace/Message_Queue.h \ - $(ACE_ROOT)/ace/Message_Block.h \ - $(ACE_ROOT)/ace/Message_Block.i \ - $(ACE_ROOT)/ace/Message_Block_T.h \ - $(ACE_ROOT)/ace/Message_Block_T.i \ - $(ACE_ROOT)/ace/Message_Block_T.cpp \ - $(ACE_ROOT)/ace/IO_Cntl_Msg.h \ - $(ACE_ROOT)/ace/Message_Queue_T.h \ - $(ACE_ROOT)/ace/Message_Queue_T.i \ - $(ACE_ROOT)/ace/Message_Queue_T.cpp \ - $(ACE_ROOT)/ace/Notification_Strategy.h \ - $(ACE_ROOT)/ace/Notification_Strategy.inl \ - $(ACE_ROOT)/ace/Message_Queue.i \ - $(ACE_ROOT)/ace/Task_T.i \ - $(ACE_ROOT)/ace/Task_T.cpp \ - $(ACE_ROOT)/ace/Module.h \ - $(ACE_ROOT)/ace/Module.i \ - $(ACE_ROOT)/ace/Module.cpp \ - $(ACE_ROOT)/ace/Stream_Modules.h \ - $(ACE_ROOT)/ace/Stream_Modules.cpp \ - $(ACE_ROOT)/ace/Auto_Ptr.h \ - $(ACE_ROOT)/ace/Auto_Ptr.i \ - $(ACE_ROOT)/ace/Auto_Ptr.cpp \ - kokyu_export.h Kokyu.h Kokyu.i Dispatcher_Impl.h Dispatcher_Impl.i \ - Dispatcher_Task.h Dispatcher_Task.i Default_Dispatcher_Impl.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/Kokyu/Makefile.Kokyu b/Kokyu/Makefile.Kokyu new file mode 100644 index 00000000000..51cbc570f66 --- /dev/null +++ b/Kokyu/Makefile.Kokyu @@ -0,0 +1,48 @@ +#---------------------------------------------------------------------------- +# GNU Makefile +#---------------------------------------------------------------------------- + +MAKEFILE = Makefile.Kokyu +DEPENDENCY_FILE = .depend.Makefile.Kokyu +LIB_UNCHECKED = libKokyu.a +SHLIB_UNCHECKED = libKokyu.$(SOEXT) + + + +FILES = \ + Dispatcher_Impl \ + Kokyu \ + Default_Dispatcher_Impl \ + Dispatcher_Task \ + Kokyu_defs + +LIB = $(LIB_UNCHECKED) +SHLIB = $(SHLIB_UNCHECKED) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +LSRC = $(addsuffix .cpp, $(FILES)) +ACELIB = -lACE + +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +CPPFLAGS += -I.. +LDFLAGS += -L../ace + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/Kokyu/Makefile.Kokyu.bor b/Kokyu/Makefile.Kokyu.bor new file mode 100644 index 00000000000..ca22062ceef --- /dev/null +++ b/Kokyu/Makefile.Kokyu.bor @@ -0,0 +1,64 @@ +# Makefile for building the Kokyu library with Borland C++ Builder + +NAME = Kokyu + +OBJFILES = \ + $(OBJDIR)\Default_Dispatcher_Impl.obj \ + $(OBJDIR)\Dispatcher_Impl.obj \ + $(OBJDIR)\Dispatcher_Task.obj \ + $(OBJDIR)\Kokyu.obj \ + $(OBJDIR)\Kokyu_defs.obj + +EXTERNAL_LIBS = + +LFLAGS = \ + -L..\ace\$(CONFIG_SUBDIR) -L..\ace \ + -L$(CORE_BINDIR) + +LIBFILES = \ + ACE$(LIB_DECORATOR).lib \ + $(EXTERNAL_LIBS) + +!ifdef STATIC +LIB_FLAGS = -DACE_AS_STATIC_LIBS=1 +DLL_FLAGS = +!else +LIB_FLAGS = +DLL_FLAGS = -DKOKYU_BUILD_DLL=1 +!endif + +CFLAGS = \ + -I.. \ + $(LIB_FLAGS) \ + $(DLL_FLAGS) + +CPPDIR = . + +INCLUDES = \ + DSRT_Direct_Dispatcher_Impl_T.h \ + DSRT_Dispatch_Item_T.h \ + DSRT_Dispatcher_Impl_T.h \ + DSRT_Sched_Queue_T.h \ + Default_Dispatcher_Impl.h \ + Dispatcher_Impl.h \ + Dispatcher_Task.h \ + Kokyu.h \ + Kokyu_defs.h \ + Kokyu_dsrt.h \ + DSRT_Direct_Dispatcher_Impl_T \ + DSRT_Dispatch_Item_T \ + DSRT_Dispatcher_Impl_T \ + DSRT_Sched_Queue_T \ + Kokyu_dsrt \ + DSRT_Dispatch_Item_T.i \ + DSRT_Dispatcher_Impl_T.i \ + Default_Dispatcher_Impl.i \ + Dispatcher_Impl.i \ + Dispatcher_Task.i \ + Kokyu.i \ + Kokyu_defs.i \ + Kokyu_dsrt.i + +BASE_BINDIR = ..\bin + +!include <$(ACE_ROOT)\include\makeinclude\build_library.bor> diff --git a/Kokyu/Makefile.bor b/Kokyu/Makefile.bor new file mode 100644 index 00000000000..43cc1a9834d --- /dev/null +++ b/Kokyu/Makefile.bor @@ -0,0 +1,20 @@ +#---------------------------------------------------------------------------- +# Borland Workspace +#---------------------------------------------------------------------------- + +!include <$(ACE_ROOT)\include\makeinclude\make_flags.bor> + +all: + $(MAKE) -$(MAKEFLAGS) $(MAKE_FLAGS) -f Makefile.Kokyu.bor all + +clean: + $(MAKE) -$(MAKEFLAGS) $(MAKE_FLAGS) -f Makefile.Kokyu.bor clean + +realclean: + $(MAKE) -$(MAKEFLAGS) $(MAKE_FLAGS) -f Makefile.Kokyu.bor realclean + +install: + $(MAKE) -$(MAKEFLAGS) $(MAKE_FLAGS) -f Makefile.Kokyu.bor install + +regenerate: + perl /home/venkita/DSRT_work/ACE_wrappers/bin/mwc.pl -type borland Kokyu.mwc diff --git a/Kokyu/tests/DSRT_MIF/MIF.cpp b/Kokyu/tests/DSRT_MIF/MIF.cpp index 136523c8aaa..620718aa07e 100644 --- a/Kokyu/tests/DSRT_MIF/MIF.cpp +++ b/Kokyu/tests/DSRT_MIF/MIF.cpp @@ -2,20 +2,55 @@ #include "ace/Auto_Ptr.h" -#include "Kokyu.h" +#include "Kokyu_dsrt.h" #include "ace/Task.h" #include "ace/Sched_Params.h" +#include "ace/Atomic_Op.h" + +ACE_Atomic_Op<ACE_Thread_Mutex, long> guid=0; + +struct mif_scheduler_traits +{ + typedef int Guid_t; + + struct QoSDescriptor_t + { + typedef long Importance_t; + + long importance_; + }; + + /* + static Time_t now() + { + ACE_Time_Value now = ACE_OS::gettimeofday (); + return now.sec () * 10000000 + now.usec () * 10; + } + */ + + typedef Kokyu::MIF_Comparator<QoSDescriptor_t> QoSComparator_t; + + struct Guid_Hash + { + u_long operator () (const Guid_t& guid) + { + return guid; + } + }; +}; + class MyTask : public ACE_Task_Base { public: MyTask (ACE_Barrier& barrier, - Kokyu::DSRT_Dispatcher* dispatcher, - Kokyu::DSRT_QoSDescriptor& qos) + Kokyu::DSRT_Dispatcher<mif_scheduler_traits>* dispatcher, + mif_scheduler_traits::QoSDescriptor_t& qos) :barrier_ (barrier), dispatcher_ (dispatcher), - qos_ (qos) + qos_ (qos), + guid_ (++guid) {} int svc (void) @@ -24,8 +59,8 @@ public: ACE_Thread::self (thr_handle); int prio; - prio = dispatcher_->schedule (0, qos_); - ACE_Thread::setprio (thr_handle, prio); + ACE_ASSERT (dispatcher_ != 0); + prio = dispatcher_->schedule (guid_, qos_); barrier_.wait (); if (ACE_Thread::getprio (thr_handle, prio) == -1) @@ -43,15 +78,16 @@ public: -1); } - ACE_DEBUG ((LM_DEBUG, "(%t) Thread prio is %d\n", prio)); + ACE_DEBUG ((LM_DEBUG, "(%t) Thread prio=%d, guid=%d, qos_.importance=%d \n", prio, guid_, qos_.importance_)); + dispatcher_->cancel_schedule (this->guid_); return 0; } private: ACE_Barrier& barrier_; - Kokyu::DSRT_Dispatcher* dispatcher_; - Kokyu::DSRT_QoSDescriptor& qos_; - + Kokyu::DSRT_Dispatcher<mif_scheduler_traits>* dispatcher_; + mif_scheduler_traits::QoSDescriptor_t qos_; + mif_scheduler_traits::Guid_t guid_; }; int main (int,char**) @@ -63,18 +99,22 @@ int main (int,char**) ACE_Barrier barrier (3); ACE_DEBUG ((LM_DEBUG, "before create_dispatcher\n" )); - auto_ptr<Kokyu::DSRT_Dispatcher> - disp (Kokyu::Dispatcher_Factory::create_DSRT_dispatcher (config_info)); + + config_info.sched_strategy_ = Kokyu::DSRT_MIF; + + Kokyu::DSRT_Dispatcher_Factory<mif_scheduler_traits>::DSRT_Dispatcher_Auto_Ptr + disp (Kokyu::DSRT_Dispatcher_Factory<mif_scheduler_traits>:: + create_DSRT_dispatcher (config_info)); ACE_DEBUG ((LM_DEBUG, "after create_dispatcher\n" )); ACE_ASSERT (disp.get () != 0); - Kokyu::DSRT_QoSDescriptor qos1, qos2, qos3; + mif_scheduler_traits::QoSDescriptor_t qos1, qos2, qos3; qos1.importance_ = 1; qos2.importance_ = 2; - qos3.importance_ = 3; + qos3.importance_ = 1; MyTask mytask1 (barrier, disp.get (), qos1); MyTask mytask2 (barrier, disp.get (), qos2); @@ -106,7 +146,13 @@ int main (int,char**) "EC (%P|%t) cannot activate task\n")); } - while(1){} + ACE_OS::sleep (5); + + disp->shutdown (); + + ACE_OS::sleep (5); + + ACE_DEBUG ((LM_DEBUG, "main thread exiting\n")); return 0; } |