From 1c4afc25e2fb9e081013edbaadcacb361c998bec Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 8 Mar 2012 09:43:04 +0100 Subject: 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 --- src/array.hpp | 4 +--- src/dist.cpp | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') 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 class array_t { - private: + public: typedef array_item_t item_t; - public: - typedef typename std::vector ::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_) -- cgit v1.2.3