diff --git a/src/backend/dynamic_process.cc b/src/backend/dynamic_process.cc index 779197b..45a376b 100644 --- a/src/backend/dynamic_process.cc +++ b/src/backend/dynamic_process.cc @@ -30,27 +30,28 @@ using namespace sgpem; using namespace std; -DynamicProcess::DynamicProcess(StaticProcess* core) - : DynamicSchedulable(), _core(core) -{} +DynamicProcess::DynamicProcess(StaticProcess* core) : + DynamicSchedulable(), _core(core) +{ + assert(core != NULL); +} DynamicProcess::DynamicProcess(const DynamicProcess &other) : - Schedulable(), DynamicSchedulable(other), Process() + Schedulable(), DynamicSchedulable(other), Process() { typedef vector::const_iterator ThreadIt; const vector& other_threads = other._dynamic_threads; for(ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it) - _dynamic_threads.push_back(new DynamicThread(*(*it))); + new DynamicThread(*(*it), this); } DynamicProcess::~DynamicProcess() { - for_each(_dynamic_threads.begin(), _dynamic_threads.end(), ptr_fun(operator delete)); + for_each(_dynamic_threads.begin(), _dynamic_threads.end(), ptr_fun(operator delete)); } - std::vector DynamicProcess::get_threads() { diff --git a/src/backend/dynamic_request.cc b/src/backend/dynamic_request.cc index 5653b82..267f799 100644 --- a/src/backend/dynamic_request.cc +++ b/src/backend/dynamic_request.cc @@ -46,6 +46,28 @@ DynamicRequest::DynamicRequest(StaticRequest *core, siblings.push_back(this); } +DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner) : + _static_request(other._static_request), _dynamic_thread(owner), + _state(other._state) +{ + typedef vector SubReqVec; + + assert(owner != NULL); + + const SubReqVec& other_subs = other._dynamic_subrequests; + + // Not sure of this, but the constructor of DynamicSubRequest should take care + // of adding itself to the vector of sub requests. This is only my opinion, + // but I think this is a complicated way of doing things... + for(SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it) + new DynamicSubRequest(*(*it), this); + + // Leave this line: it helps us with a compiler warning if + // the get_dynamic* method signature changes: + std::vector& siblings = owner->get_dynamic_requests(); + siblings.push_back(this); +} + DynamicRequest::~DynamicRequest() { diff --git a/src/backend/dynamic_request.hh b/src/backend/dynamic_request.hh index ac6381f..f7ca984 100644 --- a/src/backend/dynamic_request.hh +++ b/src/backend/dynamic_request.hh @@ -42,6 +42,7 @@ namespace sgpem { public: DynamicRequest(StaticRequest *core, DynamicThread* owner); + DynamicRequest(const DynamicRequest& other, DynamicThread* owner); ~DynamicRequest(); virtual bool operator==(const Request& op2) const; @@ -66,6 +67,9 @@ namespace sgpem std::vector& get_dynamic_subrequests(); private: + // Undefined + DynamicRequest(const DynamicRequest& other); + memory::smart_ptr _static_request; DynamicThread* _dynamic_thread; state _state; diff --git a/src/backend/dynamic_sub_request.cc b/src/backend/dynamic_sub_request.cc index 6c96e44..a2b6874 100644 --- a/src/backend/dynamic_sub_request.cc +++ b/src/backend/dynamic_sub_request.cc @@ -35,12 +35,25 @@ DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core, _queue_position(-1) { assert(core != NULL); + assert(owner != NULL); // 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); } +DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other, + DynamicRequest* owner) : + _static_subrequest(other._static_subrequest), _owner(owner), + _queue_position(other._queue_position) +{ + assert(owner != NULL); + + // 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); +} DynamicSubRequest::~DynamicSubRequest() { diff --git a/src/backend/dynamic_sub_request.hh b/src/backend/dynamic_sub_request.hh index 0e5ba34..01a09c9 100644 --- a/src/backend/dynamic_sub_request.hh +++ b/src/backend/dynamic_sub_request.hh @@ -41,6 +41,7 @@ namespace sgpem public: DynamicSubRequest(StaticSubRequest* core, DynamicRequest* owner); + DynamicSubRequest(const DynamicSubRequest& other, DynamicRequest* owner); virtual ~DynamicSubRequest(); @@ -63,6 +64,9 @@ namespace sgpem const StaticSubRequest& get_core() const; private: + // Undefined + DynamicSubRequest(const DynamicSubRequest&); + memory::smart_ptr _static_subrequest; DynamicRequest* _owner; int _queue_position; diff --git a/src/backend/dynamic_thread.cc b/src/backend/dynamic_thread.cc index 37f2b95..511107b 100644 --- a/src/backend/dynamic_thread.cc +++ b/src/backend/dynamic_thread.cc @@ -37,24 +37,33 @@ DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) : DynamicSchedulable(), _core(core), _state(state_future), _parent(parent), _ran_for(0), _last_acquisition(-1), _last_release(-1) { + assert(core != NULL); + assert(parent != NULL); + // Leave this line: it helps us with a compiler warning if // the get_dynamic* method signature changes: std::vector& siblings = parent->get_dynamic_threads(); siblings.push_back(this); } -DynamicThread::DynamicThread(const DynamicThread &other) : - Schedulable(), DynamicSchedulable(other), Thread() +DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) : + Schedulable(), DynamicSchedulable(other), Thread(), + _state(other._state), _parent(parent), _ran_for(other._ran_for), + _last_acquisition(other._last_acquisition), _last_release(other._last_release) { typedef vector::const_iterator ReqIt; + assert(parent != NULL); + const vector& other_req = other._dynamic_requests; - _state = other._state; - _parent = other._parent; - for(ReqIt it = other_req.begin(); it != other_req.end(); ++it) - _dynamic_requests.push_back(new DynamicRequest(*(*it))); + new DynamicRequest(*(*it), this); + + // Leave this line: it helps us with a compiler warning if + // the get_dynamic* method signature changes: + std::vector& siblings = parent->get_dynamic_threads(); + siblings.push_back(this); } DynamicThread::~DynamicThread() diff --git a/src/backend/dynamic_thread.hh b/src/backend/dynamic_thread.hh index a9de32d..21573ca 100644 --- a/src/backend/dynamic_thread.hh +++ b/src/backend/dynamic_thread.hh @@ -44,8 +44,8 @@ namespace sgpem { public: DynamicThread(StaticThread* core, DynamicProcess* parent); - DynamicThread(const DynamicThread &other); - virtual ~DynamicThread(); + DynamicThread(const DynamicThread &other, DynamicProcess* parent); + virtual ~DynamicThread(); DynamicProcess& get_process(); @@ -65,14 +65,17 @@ namespace sgpem void serialize(SerializeVisitor& translator) const; - virtual StaticThread& get_core(); - virtual const StaticThread& get_core() const; + virtual StaticThread& get_core(); + virtual const StaticThread& get_core() const; - // Does also the job of "add_request" and "remove_request" - std::vector& get_dynamic_requests(); + // Does also the job of "add_request" and "remove_request" + std::vector& get_dynamic_requests(); private: - memory::smart_ptr _core; + // Undefined + DynamicThread(const DynamicThread &other); + + memory::smart_ptr _core; state _state; std::vector _dynamic_requests; DynamicProcess* _parent;