netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / ovsdb / trigger.c
index 1ecfdca..74a1b0f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include "trigger.h"
 
-#include <assert.h>
 #include <limits.h>
 
 #include "json.h"
 #include "jsonrpc.h"
 #include "ovsdb.h"
 #include "poll-loop.h"
+#include "server.h"
 
-static bool ovsdb_trigger_try(struct ovsdb *db, struct ovsdb_trigger *,
-                              long long int now);
+static bool ovsdb_trigger_try(struct ovsdb_trigger *, long long int now);
 static void ovsdb_trigger_complete(struct ovsdb_trigger *);
 
 void
-ovsdb_trigger_init(struct ovsdb *db, struct ovsdb_trigger *trigger,
-                   struct json *request, struct list *completion,
-                   long long int now)
+ovsdb_trigger_init(struct ovsdb_session *session, struct ovsdb *db,
+                   struct ovsdb_trigger *trigger,
+                   struct json *request, long long int now)
 {
-    list_push_back(&db->triggers, &trigger->node);
-    trigger->completion = completion;
+    trigger->session = session;
+    trigger->db = db;
+    list_push_back(&trigger->db->triggers, &trigger->node);
     trigger->request = request;
     trigger->result = NULL;
     trigger->created = now;
     trigger->timeout_msec = LLONG_MAX;
-    ovsdb_trigger_try(db, trigger, now);
+    ovsdb_trigger_try(trigger, now);
 }
 
 void
@@ -73,9 +73,9 @@ ovsdb_trigger_run(struct ovsdb *db, long long int now)
 
     run_triggers = db->run_triggers;
     db->run_triggers = false;
-    LIST_FOR_EACH_SAFE (t, next, struct ovsdb_trigger, node, &db->triggers) {
+    LIST_FOR_EACH_SAFE (t, next, node, &db->triggers) {
         if (run_triggers || now - t->created >= t->timeout_msec) {
-            ovsdb_trigger_try(db, t, now);
+            ovsdb_trigger_try(t, now);
         }
     }
 }
@@ -89,7 +89,7 @@ ovsdb_trigger_wait(struct ovsdb *db, long long int now)
         long long int deadline = LLONG_MAX;
         struct ovsdb_trigger *t;
 
-        LIST_FOR_EACH (t, struct ovsdb_trigger, node, &db->triggers) {
+        LIST_FOR_EACH (t, node, &db->triggers) {
             if (t->created < LLONG_MAX - t->timeout_msec) {
                 long long int t_deadline = t->created + t->timeout_msec;
                 if (deadline > t_deadline) {
@@ -102,16 +102,16 @@ ovsdb_trigger_wait(struct ovsdb *db, long long int now)
         }
 
         if (deadline < LLONG_MAX) {
-            poll_timer_wait(MIN(deadline - now, INT_MAX));
+            poll_timer_wait_until(deadline);
         }
     }
 }
 
 static bool
-ovsdb_trigger_try(struct ovsdb *db, struct ovsdb_trigger *t, long long int now)
+ovsdb_trigger_try(struct ovsdb_trigger *t, long long int now)
 {
-    t->result = ovsdb_execute(db, t->request, now - t->created,
-                              &t->timeout_msec);
+    t->result = ovsdb_execute(t->db, t->session,
+                              t->request, now - t->created, &t->timeout_msec);
     if (t->result) {
         ovsdb_trigger_complete(t);
         return true;
@@ -123,7 +123,7 @@ ovsdb_trigger_try(struct ovsdb *db, struct ovsdb_trigger *t, long long int now)
 static void
 ovsdb_trigger_complete(struct ovsdb_trigger *t)
 {
-    assert(t->result != NULL);
+    ovs_assert(t->result != NULL);
     list_remove(&t->node);
-    list_push_back(t->completion, &t->node);
+    list_push_back(&t->session->completions, &t->node);
 }