summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-03-08 09:43:04 +0100
committerMartin Sustrik <sustrik@250bpm.com>2012-03-08 09:43:04 +0100
commit1c4afc25e2fb9e081013edbaadcacb361c998bec (patch)
treef4cb1bfb59b23007466a01b5a5a14583ee1c5fb7
parentac4335a87197369c9a3fe5e4a2fcc68de85e0a27 (diff)
Removal of pipe from dist_t fixed
Removing the pipe may have caused problems with matching, active and eligible pipes. Some pipes may have moved from one category to another without any reason. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/array.hpp4
-rw-r--r--src/dist.cpp34
2 files changed, 28 insertions, 10 deletions
diff --git a/src/array.hpp b/src/array.hpp
index 1cc45f4..795760b 100644
--- a/src/array.hpp
+++ b/src/array.hpp
@@ -72,12 +72,10 @@ namespace xs
template <typename T, int ID = 0> class array_t
{
- private:
+ public:
typedef array_item_t <ID> item_t;
- public:
-
typedef typename std::vector <T*>::size_type size_type;
inline array_t ()
diff --git a/src/dist.cpp b/src/dist.cpp
index 26a0c81..4e94276 100644
--- a/src/dist.cpp
+++ b/src/dist.cpp
@@ -80,13 +80,33 @@ void xs::dist_t::terminated (pipe_t *pipe_)
{
// Remove the pipe from the list; adjust number of matching, active and/or
// eligible pipes accordingly.
- if (pipes.index (pipe_) < matching)
- matching--;
- if (pipes.index (pipe_) < active)
- active--;
- if (pipes.index (pipe_) < eligible)
- eligible--;
- pipes.erase (pipe_);
+
+ int i = pipes.index (pipe_);
+ if (i < (int) matching) {
+ pipes [i] = pipes [matching - 1];
+ pipes [matching - 1] = NULL;
+ if (pipes [i])
+ ((pipes_t::item_t*) pipes [i])->set_array_index (i);
+ --matching;
+ i = matching;
+ }
+ if (i < (int) active) {
+ pipes [i] = pipes [active - 1];
+ pipes [active - 1] = NULL;
+ if (pipes [i])
+ ((pipes_t::item_t*) pipes [i])->set_array_index (i);
+ --active;
+ i = active;
+ }
+ if (i < (int) eligible) {
+ pipes [i] = pipes [eligible - 1];
+ pipes [eligible - 1] = NULL;
+ if (pipes [i])
+ ((pipes_t::item_t*) pipes [i])->set_array_index (i);
+ --eligible;
+ i = eligible;
+ }
+ pipes.erase (i);
}
void xs::dist_t::activated (pipe_t *pipe_)