From ec84480e2d1aa8efc9d87f10e205ed4855dc4fde Mon Sep 17 00:00:00 2001 From: elvez Date: Sat, 16 Sep 2006 17:04:20 +0000 Subject: [PATCH] - Another bit of auditing git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1202 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_environment.hh | 88 ++++++++----------- src/backend/concrete_history.hh | 32 +++---- src/backend/dynamic_process.cc | 12 +-- src/backend/dynamic_request.hh | 30 ++++--- src/backend/dynamic_sub_request.cc | 17 ++-- src/backend/policy_parameters.cc | 43 +++++++-- src/backend/sgpemv2/policy_parameters.hh | 6 +- src/backend/sgpemv2/process_statistics.hh | 43 ++++----- src/backend/sgpemv2/resource_policy.hh | 31 ++++--- src/backend/sgpemv2/serializers_gatekeeper.hh | 25 ++++-- src/backend/statistics.cc | 7 +- 11 files changed, 176 insertions(+), 158 deletions(-) diff --git a/src/backend/concrete_environment.hh b/src/backend/concrete_environment.hh index a270f77..d695e59 100644 --- a/src/backend/concrete_environment.hh +++ b/src/backend/concrete_environment.hh @@ -21,20 +21,23 @@ #ifndef CONCRETE_ENVIRONMENT_HH #define CONCRETE_ENVIRONMENT_HH 1 +namespace sgpem +{ + class ConcreteEnvironment; + class SerializeVisitor; +} + +#include "dynamic_process.hh" +#include "dynamic_request.hh" #include #include -#include "dynamic_process.hh" -#include "dynamic_request.hh" #include - namespace sgpem { - class SerializeVisitor; - - - /// \brief An implementation of the Environment class + /// \brief An implementation of the Environment class. + /// /// Class ConcreteEnvironment implements the Environment /// abstract class. /// @@ -45,18 +48,26 @@ namespace sgpem /// \see Environment class SG_DLLLOCAL ConcreteEnvironment : public Environment { - public: + typedef std::map SubRequestQueues; + /// \brief Standard constructor. + /// /// Builds an empty environment. ConcreteEnvironment(); /// \brief Copy constructor. + /// /// Performs a deep copy of all structures. ConcreteEnvironment(const ConcreteEnvironment& c); + /// \brief The standard virtual destructor. + /// + /// The standard virtual destructor. + virtual ~ConcreteEnvironment(); /// \brief Returns an indexed set of snapshots of the processes + /// /// Returns a standard vector of Process objects describing /// all the processes of the simulated environment at the /// considered instant. @@ -66,21 +77,16 @@ namespace sgpem /// always safe. /// /// \return a constant set of snapshots of processes - virtual const Processes& - get_processes() const; - - + virtual const Processes& get_processes() const; /// \brief Non-constant version of get_processes() /// /// \return a set of snapshots of processes /// \see get_processes() - virtual Processes& - get_processes(); - - + virtual Processes& get_processes(); /// \brief Returns an indexed set of snapshots of the resources + /// /// Returns a standard map of \code int \endcode to Resource /// objects describing the all resources of the simulated environment /// at the considered instant. @@ -98,21 +104,16 @@ namespace sgpem /// /// \return a indexed constant set of snapshot of resources. /// \see DynamicSybrequest::get_resource() - virtual const Resources& - get_resources() const; - - + virtual const Resources& get_resources() const; /// \brief Non-constant version of get_resources() /// /// \return an indexed set of snapshots of resources /// \see get_resources() - virtual Resources& - get_resources(); - - + virtual Resources& get_resources(); /// \brief Returns a snapshot of the current request queue for a resource. + /// /// Returns a standard vector of Request objects /// representing the queue of ready requests of threads which /// are waiting for getting control of a limited-access resource. @@ -123,72 +124,55 @@ namespace sgpem /// /// \param resource The resource the requests are for /// \return The current ready requests queue. - virtual const SubRequestQueue& - get_request_queue(resource_key_t resource_key) const; - - SubRequestQueue& - get_request_queue(resource_key_t resource_key); - - - - typedef std::map SubRequestQueues; + virtual const SubRequestQueue& get_request_queue(resource_key_t resource_key) const; + SubRequestQueue& get_request_queue(resource_key_t resource_key); /// \brief Returns the set of request queues. + /// /// Returns a reference to the map from resources to subreuqest queues. /// It is needed by history to delete the queue associated to a deleted /// resource. - - SubRequestQueues& - get_subrequest_queues(); + SubRequestQueues& get_subrequest_queues(); /// \brief Returns a snapshot of the current scheduler's ready queue. + /// /// Returns a ReadyQueue object representing the queue /// of ready processes or ready threads, depending on the /// scheduling policy, which are waiting for getting control /// of the CPU. /// /// \return the current ready queue (constant). - virtual const ReadyQueue& - get_sorted_queue() const; - - + virtual const ReadyQueue& get_sorted_queue() const; /// \brief Non-constant version of get_sorted_queue() /// /// \return the current ready queue. /// \see get_sorted_queue() - virtual ReadyQueue& - get_sorted_queue(); - - - - /// \brief The standard virtual destructor. - /// The standard virtual destructor. - virtual - ~ConcreteEnvironment(); - + virtual ReadyQueue& get_sorted_queue(); private: /// \brief The container of all Resource objecs. + /// /// Actually contains only DynamicResource objects. // resources come before processes because of // destruction order. See destructor implementation Resources _resources; /// \brief The container of all Process objecs. + /// /// Actually contains only DynamicProcess objects. Processes _processes; /// \brief The queue of the ready schedulables + /// /// Does not contain the running process. ReadyQueue _sched_queue; SubRequestQueues _sreq_queues; - } - ; //~ class ConcreteEnvironment + }; //~ class ConcreteEnvironment } //~ namespace sgpem diff --git a/src/backend/concrete_history.hh b/src/backend/concrete_history.hh index bfbd392..0afb07d 100644 --- a/src/backend/concrete_history.hh +++ b/src/backend/concrete_history.hh @@ -21,7 +21,10 @@ #ifndef CONCRETE_HISTORY_HH #define CONCRETE_HISTORY_HH 1 - +namespace sgpem +{ + class ConcreteHistory; +} #include "concrete_environment.hh" #include "dynamic_process.hh" @@ -29,6 +32,7 @@ #include "dynamic_resource.hh" #include "dynamic_sub_request.hh" #include "dynamic_thread.hh" + #include #include @@ -40,8 +44,6 @@ namespace sgpem { - class ConcreteHistory; - class SG_DLLLOCAL ConcreteHistory : public History { public: @@ -63,15 +65,15 @@ namespace sgpem virtual void clear(); virtual ResourcePair add_resource(const Glib::ustring& name, - bool preemptable = false, - size_t places = 1, - size_t availability = 0); + bool preemptable = false, + size_t places = 1, + size_t availability = 0); - virtual void edit_resource(Resource& resource, - const Glib::ustring& name, - bool preemptable = false, - size_t places = 1, - size_t availability = 0); + virtual void edit_resource(Resource& resource, + const Glib::ustring& name, + bool preemptable = false, + size_t places = 1, + size_t availability = 0); virtual DynamicProcess& add_process(const Glib::ustring& name, time_t arrival_time, @@ -112,10 +114,10 @@ namespace sgpem // sets the front to position p virtual void set_front(position p); - bool is_sealed() const; + bool is_sealed() const; - // (Returns if the History was sealed before this call) - bool seal(); + // (Returns if the History was sealed before this call) + bool seal(); void reset(); // Implements a virtual method @@ -127,7 +129,7 @@ namespace sgpem // Disable assignment, implement it only if needed ConcreteHistory& operator=(const ConcreteHistory& op2); - bool _sealed; + bool _sealed; } ; //~ class ConcreteHistory diff --git a/src/backend/dynamic_process.cc b/src/backend/dynamic_process.cc index 95435c6..0560081 100644 --- a/src/backend/dynamic_process.cc +++ b/src/backend/dynamic_process.cc @@ -21,8 +21,8 @@ #include "dynamic_process.hh" #include "static_process.hh" #include "dynamic_thread.hh" -#include +#include #include #include @@ -54,7 +54,8 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) : DynamicProcess::~DynamicProcess() { - for_each(_dynamic_threads.begin(), _dynamic_threads.end(), + for_each(_dynamic_threads.begin(), + _dynamic_threads.end(), memory::deletor()); } @@ -73,7 +74,7 @@ DynamicProcess::get_threads() const Schedulable::state DynamicProcess::get_state() const { - static const int uninitialized = -1; + const int uninitialized = -1; state result = state_terminated; int next_thread_starts_at = uninitialized; @@ -99,7 +100,7 @@ DynamicProcess::get_state() const for(Iseq seq = iseq(_dynamic_threads); seq; ++seq) { - state thread_state = (*seq)->get_state(); + const state thread_state = (*seq)->get_state(); switch(thread_state) { @@ -133,7 +134,8 @@ DynamicProcess::get_state() const // the next thread to start, e.g. the one with the least arrival_time, // has start time greater than the current process elapsed time, then // pass from state_future to state_terminated: - if (result == state_future && next_thread_starts_at > static_cast(get_elapsed_time())) + if (result == state_future && + next_thread_starts_at > static_cast(get_elapsed_time())) return state_terminated; return result; diff --git a/src/backend/dynamic_request.hh b/src/backend/dynamic_request.hh index 9bb06a5..803aae9 100644 --- a/src/backend/dynamic_request.hh +++ b/src/backend/dynamic_request.hh @@ -21,23 +21,27 @@ #ifndef DYNAMIC_REQUEST_HH #define DYNAMIC_REQUEST_HH 1 - - -#include -#include "static_request.hh" -#include "dynamic_thread.hh" - -#include - -#include - namespace sgpem { class DynamicRequest; class SerializeVisitor; class SubRequest; class DynamicSubRequest; +} +#include "static_request.hh" +#include "dynamic_thread.hh" + +#include +#include + +#include + +namespace sgpem +{ + /** \brief A "dynamic" request, which represents the state + * of a request at a particular temporal instant + */ class SG_DLLLOCAL DynamicRequest : public Request { public: @@ -60,9 +64,9 @@ namespace sgpem StaticRequest& get_core(); const StaticRequest& get_core() const; - // Since this method is visible only by the backend, - // return directly a reference that lets us to - // add and remove subrequests at will. + /// \internal Since this method is visible only by the backend, + /// return directly a reference that lets us to + /// add and remove subrequests at will. std::vector& get_dynamic_subrequests(); private: diff --git a/src/backend/dynamic_sub_request.cc b/src/backend/dynamic_sub_request.cc index aeb9ace..f1e60ce 100644 --- a/src/backend/dynamic_sub_request.cc +++ b/src/backend/dynamic_sub_request.cc @@ -20,9 +20,9 @@ #include "dynamic_sub_request.hh" #include "dynamic_request.hh" + #include #include - #include #include @@ -38,8 +38,9 @@ DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core, { assert(core != NULL); assert(owner != NULL); -// Leave this line: it helps us with a compiler warning if -// the get_dynamic* method signature changes: + + // Leave this line: it helps us with a compiler warning if + // the get_dynamic* method signature changes: std::vector& siblings = owner->get_dynamic_subrequests(); siblings.push_back(this); } @@ -52,8 +53,8 @@ DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other, { assert(owner != NULL); -// Leave this line: it helps us with a compiler warning if -// the get_dynamic* method signature changes: + // Leave this line: it helps us with a compiler warning if + // the get_dynamic* method signature changes: std::vector& siblings = owner->get_dynamic_subrequests(); siblings.push_back(this); } @@ -61,11 +62,11 @@ DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other, DynamicSubRequest::~DynamicSubRequest() {} - bool DynamicSubRequest::operator==(const SubRequest& op2) const { - return _static_subrequest == down_cast(op2)._static_subrequest; + return _static_subrequest == + down_cast(op2)._static_subrequest; } @@ -75,7 +76,6 @@ DynamicSubRequest::get_resource_key() const return _static_subrequest->get_resource_key(); } - unsigned int DynamicSubRequest::get_length() const { @@ -129,6 +129,7 @@ unsigned int DynamicSubRequest::decrease_remaining_time() { assert(_state == Request::state_allocated); + unsigned int temp = get_remaining_time(); if (temp > 0) _ran_for++; diff --git a/src/backend/policy_parameters.cc b/src/backend/policy_parameters.cc index 01ca3ea..9b6d729 100644 --- a/src/backend/policy_parameters.cc +++ b/src/backend/policy_parameters.cc @@ -27,7 +27,8 @@ using Glib::ustring; // instantiate Parameter template for use outside this DSO -namespace sgpem { +namespace sgpem +{ template class SG_DLLEXPORT PolicyParameters::Parameter; template class SG_DLLEXPORT PolicyParameters::Parameter; template class SG_DLLEXPORT PolicyParameters::Parameter; @@ -39,14 +40,23 @@ namespace sgpem { If there is a parameter with the same name and type it will be overwritten. */ void -PolicyParameters::register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value) +PolicyParameters::register_int(Glib::ustring name, + const int& lower_bound, + const int& upper_bound, + const bool& required, + const int& default_value) { //there is a parameter with the same name!! map >::iterator i = int_map.find(name); if (i != int_map.end()) int_map.erase(i); - map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + map >::value_type v(name, Parameter(name, + default_value, + lower_bound, + upper_bound, + required, + default_value)); int_map.insert(v); } @@ -56,14 +66,24 @@ PolicyParameters::register_int(Glib::ustring name, const int& lower_bound, const If there is a parameter with the same name and type it will be overwritten. */ void -PolicyParameters::register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value) +PolicyParameters::register_float(Glib::ustring name, + const float& lower_bound, + const float& upper_bound, + const bool& required, + const float& default_value) { //there is a parameter with the same name!! map >::iterator i = float_map.find(name); if (i != float_map.end()) float_map.erase(i); - map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + map >::value_type v(name, Parameter(name, + default_value, + lower_bound, + upper_bound, + required, + default_value)); + float_map.insert(v); } @@ -79,7 +99,12 @@ PolicyParameters::register_string(Glib::ustring name, const bool& required, cons if (i != string_map.end()) string_map.erase(i); - map >::value_type v(name, Parameter(name, default_value, "", "", required, default_value)); + map >::value_type v(name, Parameter(name, + default_value, + "", + "", + required, + default_value)); string_map.insert(v); } @@ -189,7 +214,7 @@ PolicyParameters::set_string(ustring name, const ustring& value) \throws A PolicyParametersException if the parameter has not been found. */ int -PolicyParameters::get_int(ustring name) const +PolicyParameters::get_int(ustring name) const throw(PolicyParametersException) { map >::const_iterator i = int_map.find(name); if (i == int_map.end()) @@ -205,7 +230,7 @@ PolicyParameters::get_int(ustring name) const \throws A PolicyParametersException if the parameter has not been found. */ float -PolicyParameters::get_float(ustring name) const +PolicyParameters::get_float(ustring name) const throw(PolicyParametersException) { map >::const_iterator i = float_map.find(name); if (i == float_map.end()) @@ -221,7 +246,7 @@ PolicyParameters::get_float(ustring name) const \throws A PolicyParametersException if the parameter has not been found. */ ustring -PolicyParameters::get_string(ustring name) const +PolicyParameters::get_string(ustring name) const throw(PolicyParametersException) { map >::const_iterator i = string_map.find(name); if (i == string_map.end()) diff --git a/src/backend/sgpemv2/policy_parameters.hh b/src/backend/sgpemv2/policy_parameters.hh index 8fe2411..ff70af5 100644 --- a/src/backend/sgpemv2/policy_parameters.hh +++ b/src/backend/sgpemv2/policy_parameters.hh @@ -229,19 +229,19 @@ namespace sgpem \returns the INTEGER value of the parameter named \e name \throws PolicyParametersException if the parameter named \e name has not been registered */ - int get_int(Glib::ustring name) const; + int get_int(Glib::ustring name) const throw(PolicyParametersException); /** \brief Returns the value of an FLOAT parameter \returns the FLOAT value of the parameter named \e name \throws PolicyParametersException if the parameter named \e name has not been registered */ - float get_float(Glib::ustring name) const; + float get_float(Glib::ustring name) const throw(PolicyParametersException); /** \brief Returns the value of an STRING parameter \returns the STRING value of the parameter named \e name \throws PolicyParametersException if the parameter named \e name has not been registered */ - Glib::ustring get_string(Glib::ustring name) const; + Glib::ustring get_string(Glib::ustring name) const throw(PolicyParametersException); diff --git a/src/backend/sgpemv2/process_statistics.hh b/src/backend/sgpemv2/process_statistics.hh index faef4d5..68a4a78 100644 --- a/src/backend/sgpemv2/process_statistics.hh +++ b/src/backend/sgpemv2/process_statistics.hh @@ -1,4 +1,4 @@ -// src/backend/process_statistics.hh - Copyright 2005, 2006, University +// src/backend/sgpemv2/process_statistics.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -21,41 +21,32 @@ #ifndef PROCESS_STATISTICS_HH #define PROCESS_STATISTICS_HH 1 -#include +#include "thread_statistics.hh" +#include #include #include #include -#include "thread_statistics.hh" -#include #include +#include namespace sgpem { - class ProcessStatistics : public SchedulableStatistics - { - public: - ~ProcessStatistics(); - - int get_execution_time() const =0; - int get_execution_progress() const =0; - int get_total_inactivity() const =0; - int get_response_time() const =0; - virtual float get_average_response_time() const =0; - int get_turn_around() const =0; - int get_efficiency() const =0; - int get_resource_usage_time() const =0; - int get_resource_waitings_time() const =0; - - const Process* get_core() const =0; - - virtual std::vector get_threads_statistics() const =0; - - protected: - ProcessStatistics(); - }; + class ProcessStatistics : public SchedulableStatistics + { + public: + ~ProcessStatistics(); + + virtual float get_average_response_time() const = 0; + virtual const Process* get_core() const = 0; + + virtual std::vector get_threads_statistics() const = 0; + + protected: + ProcessStatistics(); + }; } #endif diff --git a/src/backend/sgpemv2/resource_policy.hh b/src/backend/sgpemv2/resource_policy.hh index c20c0fb..85abed7 100644 --- a/src/backend/sgpemv2/resource_policy.hh +++ b/src/backend/sgpemv2/resource_policy.hh @@ -1,4 +1,4 @@ -// src/backend/resource_policy.hh - Copyright 2005, 2006, University +// src/backend/sgpemv2/resource_policy.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -21,31 +21,34 @@ #ifndef RESOURCE_POLICY_HH #define RESOURCE_POLICY_HH 1 -#include +namespace sgpem +{ + class ResourcePolicy; +} + #include "gettext.h" -#include "glibmm/ustring.h" - +#include #include #include #include #include +#include + namespace sgpem { - class ResourcePolicy; - - /** \brief - It's a Strategy wich stay for a resource allocating algorithm. - It implements the related resource allocation policy. - */ + /** \brief It's a Strategy wich stay for a resource allocating algorithm. + + It implements the related resource allocation policy. + */ class SG_DLLEXPORT ResourcePolicy { public: virtual ~ResourcePolicy(); /** - Initialize the inner components of the policy. + \brief Initialize the inner components of the policy. Because it's a pure virtual method, must be re-implemented in concrete derived classes. @@ -53,7 +56,7 @@ namespace sgpem virtual void configure() throw(UserInterruptException) = 0; /** - Allocate resources to the threads + \brief Allocate resources to the threads Because it's a pure virtual method, must be re-implemented in concrete derived classes. @@ -61,7 +64,7 @@ namespace sgpem virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) throw(UserInterruptException) = 0; /** - Gets a string description of the policy. + \brief Gets a string description of the policy. Because it's a pure virtual method, must be re-implemented in concrete derived classes. @@ -76,7 +79,7 @@ namespace sgpem virtual void deactivate() = 0; /** - Gets the parameters related with this policy. + \brief Gets the parameters related with this policy. \return The policy parameters. */ diff --git a/src/backend/sgpemv2/serializers_gatekeeper.hh b/src/backend/sgpemv2/serializers_gatekeeper.hh index 9eee5ab..1ba2493 100644 --- a/src/backend/sgpemv2/serializers_gatekeeper.hh +++ b/src/backend/sgpemv2/serializers_gatekeeper.hh @@ -1,4 +1,4 @@ -// src/backend/serializers_gatekeeper.hh - Copyright 2005, 2006, University +// src/backend/sgpemv2/serializers_gatekeeper.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -24,23 +24,23 @@ namespace sgpem { class Serializer; + class SerializersGatekeeper; } #include +#include #include -#include - namespace sgpem { - class SerializersGatekeeper; - - /** \brief FIXME document me - + /** \brief Manages instances of Serializer subclasses + * + * Normally you will use only the get_registered method, since + * the Serializer base class automatically registers/unregisters + * himself when appropriate. */ - class SG_DLLEXPORT SerializersGatekeeper : public Singleton { friend class Singleton; @@ -48,8 +48,15 @@ namespace sgpem public: std::vector get_registered() const; + /** \brief Registers a serializer + * \param serializer The serializer, cannot be NULL + */ void register_serializer(Serializer* serializer); - + + /** \brief Unregisters a serializer + * \param serializer The serializer, cannot be NULL. If the serializer + * wasn't previously registered, this method is a no-op. + */ void unregister_serializer(Serializer* serializer); private: diff --git a/src/backend/statistics.cc b/src/backend/statistics.cc index 1e0a42a..c03a40a 100644 --- a/src/backend/statistics.cc +++ b/src/backend/statistics.cc @@ -18,11 +18,10 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#include #include "concrete_statistics.hh" -// Do not include in header file: -#include "sgpemv2/templates/singleton.tcc" +#include +#include using namespace sgpem; @@ -35,7 +34,7 @@ Statistics::Statistics() Statistics& Statistics::get_instance() { - return Singleton::get_instance(); + return Singleton::get_instance(); }