Implement pool removal.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/main.c b/main.c
index 2182630..a97f60c 100644
--- a/main.c
+++ b/main.c
@@ -1441,6 +1441,30 @@ static void display_pool_summary(struct pool *pool)
wprintw(logwin, " Submitting work remotely delay occasions: %d\n\n", pool->remotefail_occasions);
}
+/* We can't remove the memory used for this struct pool because there may
+ * still be work referencing it. We just remove it from the pools list */
+static void remove_pool(struct pool *pool)
+{
+ int i, last_pool = total_pools - 1;
+ struct pool *other;
+
+ /* Boost priority of any lower prio than this one */
+ for (i = 0; i < total_pools; i++) {
+ other = pools[i];
+ if (other->prio > pool->prio)
+ other->prio--;
+ }
+
+ if (pool->pool_no < last_pool) {
+ /* Swap the last pool for this one */
+ (pools[last_pool])->pool_no = pool->pool_no;
+ pools[pool->pool_no] = pools[last_pool];
+ }
+ /* Give it an invalid number */
+ pool->pool_no = total_pools;
+ total_pools--;
+}
+
static void display_pools(void)
{
struct pool *pool;
@@ -1481,6 +1505,26 @@ retry:
if (!strncasecmp(&input, "a", 1)) {
input_pool(true);
goto updated;
+ } else if (!strncasecmp(&input, "r", 1)) {
+ if (active_pools() <= 1) {
+ wprintw(logwin, "Cannot remove last pool");
+ goto retry;
+ }
+ selected = curses_int("Select pool number");
+ if (selected < 0 || selected >= total_pools) {
+ wprintw(logwin, "Invalid selection\n");
+ goto retry;
+ }
+ pool = pools[selected];
+ if (pool == current_pool())
+ switch_pools(NULL);
+ if (pool == current_pool()) {
+ wprintw(logwin, "Unable to remove pool due to activity\n");
+ goto retry;
+ }
+ pool->enabled = false;
+ remove_pool(pool);
+ goto updated;
} else if (!strncasecmp(&input, "s", 1)) {
selected = curses_int("Select pool number");
if (selected < 0 || selected >= total_pools) {