summaryrefslogtreecommitdiff
path: root/src/dist.cpp
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 /src/dist.cpp
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>
Diffstat (limited to 'src/dist.cpp')
-rw-r--r--src/dist.cpp34
1 files changed, 27 insertions, 7 deletions
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_)