Willy Tarreau | 81f38d6 | 2015-04-13 17:11:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Functions managing applets |
| 3 | * |
| 4 | * Copyright 2000-2015 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | |
| 16 | #include <common/config.h> |
| 17 | #include <common/mini-clist.h> |
| 18 | #include <proto/applet.h> |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 19 | #include <proto/stream.h> |
| 20 | #include <proto/stream_interface.h> |
Willy Tarreau | 81f38d6 | 2015-04-13 17:11:11 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 64bca9d | 2015-09-25 17:39:23 +0200 | [diff] [blame] | 22 | struct list applet_active_queue = LIST_HEAD_INIT(applet_active_queue); |
Willy Tarreau | 9994238 | 2015-09-25 17:56:16 +0200 | [diff] [blame] | 23 | struct list applet_run_queue = LIST_HEAD_INIT(applet_run_queue); |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 24 | |
| 25 | void applet_run_active() |
| 26 | { |
Willy Tarreau | 9994238 | 2015-09-25 17:56:16 +0200 | [diff] [blame] | 27 | struct appctx *curr; |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 28 | struct stream_interface *si; |
| 29 | |
Willy Tarreau | 9994238 | 2015-09-25 17:56:16 +0200 | [diff] [blame] | 30 | if (LIST_ISEMPTY(&applet_active_queue)) |
| 31 | return; |
| 32 | |
| 33 | /* move active queue to run queue */ |
| 34 | applet_active_queue.n->p = &applet_run_queue; |
| 35 | applet_active_queue.p->n = &applet_run_queue; |
| 36 | |
| 37 | applet_run_queue = applet_active_queue; |
| 38 | LIST_INIT(&applet_active_queue); |
| 39 | |
| 40 | /* The list is only scanned from the head. This guarantees that if any |
| 41 | * applet removes another one, there is no side effect while walking |
| 42 | * through the list. |
| 43 | */ |
| 44 | while (!LIST_ISEMPTY(&applet_run_queue)) { |
| 45 | curr = LIST_ELEM(applet_run_queue.n, typeof(curr), runq); |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 46 | si = curr->owner; |
| 47 | |
| 48 | /* now we'll need a buffer */ |
| 49 | if (!stream_alloc_recv_buffer(si_ic(si))) { |
| 50 | si->flags |= SI_FL_WAIT_ROOM; |
| 51 | LIST_DEL(&curr->runq); |
| 52 | LIST_INIT(&curr->runq); |
| 53 | continue; |
| 54 | } |
| 55 | |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 56 | /* We always pretend the applet can't get and doesn't want to |
| 57 | * put, it's up to it to change this if needed. This ensures |
| 58 | * that one applet which ignores any event will not spin. |
| 59 | */ |
| 60 | si_applet_cant_get(si); |
| 61 | si_applet_stop_put(si); |
| 62 | |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 63 | curr->applet->fct(curr); |
Willy Tarreau | aa977ba | 2015-09-25 11:45:06 +0200 | [diff] [blame^] | 64 | si_applet_wake_cb(si); |
Willy Tarreau | 9994238 | 2015-09-25 17:56:16 +0200 | [diff] [blame] | 65 | |
| 66 | if (applet_run_queue.n == &curr->runq) { |
| 67 | /* curr was left in the list, move it back to the active list */ |
| 68 | LIST_DEL(&curr->runq); |
| 69 | LIST_ADDQ(&applet_active_queue, &curr->runq); |
| 70 | } |
Willy Tarreau | 3c595ac | 2015-04-19 09:59:31 +0200 | [diff] [blame] | 71 | } |
| 72 | } |