From 9cf460de884ff1a7f2fd3fb9d8df3e1bd5691b3a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 7 May 2014 18:20:07 +0200 Subject: sort interceptors by priority MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-server.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/mds-server.c b/src/mds-server.c index 9145033..8f0e8fe 100644 --- a/src/mds-server.c +++ b/src/mds-server.c @@ -908,6 +908,22 @@ void add_intercept_condition(client_t* client, char* condition, int64_t priority } +/** + * Compare two queued interceptors by priority + * + * @param a:const queued_interception_t* One of the interceptors + * @param b:const queued_interception_t* The other of the two interceptors + * @return Negative if a before b, positive if a after b, otherwise zero + */ +static int cmp_queued_interception(const void* a, const void* b) +{ + const queued_interception_t* p = b; /* Highest first, so swap them. */ + const queued_interception_t* q = a; + int64_t diff = p->priority - q->priority; + return diff < 0 ? -1 : diff > 0 ? 1 : 0; +} + + /** * Multicast a message * @@ -1027,6 +1043,8 @@ void multicast_message(char* message, size_t length) goto fail; /* Sort interceptors. */ + qsort(interceptions, interceptions_count, sizeof(queued_interception_t), cmp_queued_interception); + /* TODO */ errno = 0; -- cgit v1.2.3-70-g09d2