]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
create heaps
authorAlan T. DeKok <aland@freeradius.org>
Tue, 22 Nov 2016 17:30:40 +0000 (12:30 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 22 Nov 2016 18:21:43 +0000 (13:21 -0500)
src/util/transport.h
src/util/worker.c

index 94e85a7002933e954154ab95eb587c6e6b1b9a1f..3c0ba7b53e5bd162f0b1d6c692f170d5bc3685b1 100644 (file)
@@ -96,6 +96,7 @@ typedef struct fr_transport_t {
  *     Minimal data structure to use the new code.
  */
 struct rad_request {
+       int                     heap_id;
        uint32_t                priority;
        fr_time_t               recv_time;
        fr_time_t               *original_recv_time;
index db7eced225394bd249b48477f104f802db95e02e..46bfc17428ae5a7577b58c7e783e2d2fd1b97b73 100644 (file)
@@ -406,6 +406,35 @@ static int fr_worker_idle(void *ctx, struct timeval *wake)
        return 1;
 }
 
+static int worker_message_cmp(void const *one, void const *two)
+{
+       fr_channel_data_t const *a = one;
+       fr_channel_data_t const *b = two;
+
+       if (a->request.priority < b->request.priority) return -1;
+       if (a->request.priority > b->request.priority) return +1;
+
+       if (a->m.when < b->m.when) return -1;
+       if (a->m.when > b->m.when) return +1;
+
+       return 0;
+}
+
+
+static int worker_request_cmp(void const *one, void const *two)
+{
+       REQUEST const *a = one;
+       REQUEST const *b = two;
+
+       if (a->priority < b->priority) return -1;
+       if (a->priority > b->priority) return +1;
+
+       if (a->recv_time < b->recv_time) return -1;
+       if (a->recv_time > b->recv_time) return +1;
+
+       return 0;
+}
+
 
 /** Create a worker
  *
@@ -431,7 +460,29 @@ static fr_worker_t *fr_worker_create(TALLOC_CTX *ctx)
                return NULL;
        }
 
-       // @todo create all of the heaps
+       worker->to_decode = fr_heap_create(worker_message_cmp, offsetof(fr_channel_data_t, channel.heap_id));
+       if (!worker->to_decode) {
+               talloc_free(worker);
+               return NULL;
+       }
+
+       worker->localized = fr_heap_create(worker_message_cmp, offsetof(fr_channel_data_t, channel.heap_id));
+       if (!worker->localized) {
+               talloc_free(worker);
+               return NULL;
+       }
+
+       worker->decoded = fr_heap_create(worker_request_cmp, offsetof(REQUEST, heap_id));
+       if (!worker->decoded) {
+               talloc_free(worker);
+               return NULL;
+       }
+
+       worker->runnable = fr_heap_create(worker_request_cmp, offsetof(REQUEST, heap_id));
+       if (!worker->decoded) {
+               talloc_free(worker);
+               return NULL;
+       }
 
        // @todo register our event loop / KQ with the global KQ system