OpenASIP 2.2
Loading...
Searching...
No Matches
PSocketResource.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file PSocketResource.cc
26 *
27 * Implementation of prototype of Resource Model:
28 * implementation of the abstract PSocketResource.
29 *
30 * @author Vladimir Guzma 2006 (vladimir.guzma-no.spam-tut.fi)
31 * @note rating: red
32 */
33#include <iostream>
34#include "PSocketResource.hh"
35#include "MapTools.hh"
36#include "Conversion.hh"
37#include "MoveNode.hh"
38#include "MoveGuard.hh"
39#include "Guard.hh"
40#include "Move.hh"
41
42/**
43 * Constructor defining name of resource
44 * @param name Name of resource
45 */
46PSocketResource::PSocketResource(const std::string& name, unsigned int initiationInterval) :
47 SchedulingResource(name, initiationInterval) {}
48
49/**
50 * Empty constructor
51 */
53
54/**
55 * Test if resource PSocketResource is used in given cycle
56 *
57 * The PSocket is inUse if it is read from or written to at
58 * least once.
59 *
60 * @param cycle Cycle which to test
61 * @return True if p-socket is already used in cycle
62 */
63bool
64PSocketResource::isInUse(const int cycle) const {
65 ResourceRecordType::const_iterator iter =
67 if (iter != resourceRecord_.end() && iter->second.size() > 0) {
68 return true;
69 }
70 return false;
71}
72
73/**
74 * Test if resource PSocketResource is available
75 *
76 * @param cycle Cycle which to test
77 * @return True if p-socket is available in cycle
78 */
79bool
80PSocketResource::isAvailable(const int cycle) const {
81 ResourceRecordType::const_iterator iter =
83 if (iter != resourceRecord_.end() && iter->second.size() > 0) {
84 const std::set<MoveNode*>& movesInCycle = iter->second;
85 for (std::set<MoveNode*>::const_iterator i = movesInCycle.begin();
86 i != movesInCycle.end(); i++) {
87 if ((*i)->move().isUnconditional()) {
88 return false;
89 }
90 }
91 }
92 return true;
93}
94
95/**
96 * Assign resource to given node for given cycle.
97 *
98 * @param cycle Cycle to assign
99 * @param node MoveNode to assign
100 * @throw In case PSocket can not be assigned
101 * @note Exception is internal error, resource should be tested
102 * with canAssign() before assign() is called.
103 */
104void
106{
107 resourceRecord_[instructionIndex(cycle)].insert(&mn);
109 return;
110}
111
112/**
113 * Unassign resource from given node for given cycle.
114 *
115 * @param cycle Cycle to remove assignment from
116 * @param node MoveNode to remove assignment from
117 * @throw In case the PSocket was not assigned before.
118 */
119void
121{
122 if (isInUse(cycle)) {
123 resourceRecord_[instructionIndex(cycle)].erase(&mn);
125 return;
126 }
127 std::string msg = "PSocket was not assigned so it can not be unassigned!";
128 throw InvalidData(__FILE__, __LINE__, __func__, msg);
129}
130
131/**
132 * Return true if resource can be assigned for given resource in given cycle.
133 *
134 * @param cycle Cycle to test
135 * @param node MoveNode to test
136 * @return true if node can be assigned to cycle
137 */
138bool
139PSocketResource::canAssign(const int cycle, const MoveNode& node) const {
140
141 ResourceRecordType::const_iterator iter = resourceRecord_.find(cycle);
142 if (iter != resourceRecord_.end()) {
143 const std::set<MoveNode*>& movesInCycle = iter->second;
144 for (std::set<MoveNode*>::const_iterator i = movesInCycle.begin();
145 i != movesInCycle.end(); i++) {
146 MoveNode* mn = *i;
147#ifdef NO_OVERCOMMIT
148 return false;
149#else
150 if (node.move().isUnconditional() ||
151 mn->move().isUnconditional()) {
152 return false;
153 }
154 if (!node.move().guard().guard().isOpposite(
155 mn->move().guard().guard())) {
156 return false;
157 }
158#endif
159 }
160 }
161 return true;
162}
163
164/**
165 * Clears bookkeeping of the scheduling resource.
166 *
167 * After this call the state of the resource should be identical to a
168 * newly-created and initialized resource.
169 */
170void
#define __func__
TTAProgram::Move & move()
virtual bool canAssign(const int cycle, const MoveNode &node) const override
virtual ~PSocketResource()
virtual bool isInUse(const int cycle) const override
void clear() override
PSocketResource(const std::string &name, unsigned int initiationInterval=0)
virtual bool isAvailable(const int cycle) const override
ResourceRecordType resourceRecord_
virtual void assign(const int cycle, MoveNode &node) override
virtual void unassign(const int cycle, MoveNode &node) override
virtual void increaseUseCount()
int instructionIndex(int cycle) const
virtual void decreaseUseCount()
virtual bool isOpposite(const Guard &guard) const =0
const TTAMachine::Guard & guard() const
Definition MoveGuard.cc:86
MoveGuard & guard() const
Definition Move.cc:345
bool isUnconditional() const
Definition Move.cc:154