towards adding mq destruction notification
authorChristian Grothoff <christian@grothoff.org>
Mon, 19 Sep 2016 14:31:14 +0000 (14:31 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 19 Sep 2016 14:31:14 +0000 (14:31 +0000)
src/include/gnunet_mq_lib.h
src/nse/gnunet-service-nse.c
src/util/mq.c

index 999ee41341f9c57c8321e9d4e82b57d845bc32ac..ff8c9ba1b99a7f583c10a5b0e452f22e9775f64b 100644 (file)
@@ -636,6 +636,36 @@ void
 GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq);
 
 
+/**
+ * Handle we return for callbacks registered to be
+ * notified when #GNUNET_MQ_destroy() is called on a queue.
+ */
+struct GNUNET_MQ_DestroyNotificationHandle;
+
+
+/**
+ * Register function to be called whenever @a mq is being
+ * destroyed.
+ *
+ * @param mq message queue to watch
+ * @param cb function to call on @a mq destruction
+ * @param cb_cls closure for @a cb
+ * @return handle for #GNUNET_MQ_destroy_notify_cancel().
+ */
+struct GNUNET_MQ_DestroyNotificationHandle *
+GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
+                         GNUNET_SCHEDULER_TaskCallback cb,
+                         void *cb_cls);
+
+/**
+ * Cancel registration from #GNUNET_MQ_destroy_notify().
+ *
+ * @param dnh handle for registration to cancel
+ */
+void
+GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh);
+
+
 /**
  * Call the message message handler that was registered
  * for the type of the given message in the given message queue.
index 1f06c0a7571a4c173793cfc3dda5f5dd483faf10..bf7c79fcba92e65864ac6d3ffa45b3a88a2fcc14 100644 (file)
@@ -276,12 +276,12 @@ static unsigned int estimate_count;
 /**
  * Task scheduled to update our flood message for the next round.
  */
-static struct GNUNET_SCHEDULER_Task * flood_task;
+static struct GNUNET_SCHEDULER_Task *flood_task;
 
 /**
  * Task scheduled to compute our proof.
  */
-static struct GNUNET_SCHEDULER_Task * proof_task;
+static struct GNUNET_SCHEDULER_Task *proof_task;
 
 /**
  * Notification context, simplifies client broadcasts.
index e9dba3d9d89ac9c413cd33f10189deb7519049c8..01cdf764b90aa9c4e8b285d5015c92e256155c95 100644 (file)
@@ -154,6 +154,16 @@ struct GNUNET_MQ_Handle
    */
   struct GNUNET_SCHEDULER_Task *continue_task;
 
+  /**
+   * Functions to call on queue destruction; kept in a DLL.
+   */
+  struct GNUNET_MQ_DestroyNotificationHandle *dnh_head;
+
+  /**
+   * Functions to call on queue destruction; kept in a DLL.
+   */
+  struct GNUNET_MQ_DestroyNotificationHandle *dnh_tail;
+
   /**
    * Additional options buffer set for this queue by
    * #GNUNET_MQ_set_options().  Default is 0.
@@ -1173,4 +1183,81 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
 }
 
 
+/**
+ * Handle we return for callbacks registered to be
+ * notified when #GNUNET_MQ_destroy() is called on a queue.
+ */
+struct GNUNET_MQ_DestroyNotificationHandle
+{
+  /**
+   * Kept in a DLL.
+   */
+  struct GNUNET_MQ_DestroyNotificationHandle *prev;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct GNUNET_MQ_DestroyNotificationHandle *next;
+
+  /**
+   * Queue to notify about.
+   */
+  struct GNUNET_MQ_Handle *mq;
+
+  /**
+   * Function to call.
+   */
+  GNUNET_SCHEDULER_TaskCallback cb;
+
+  /**
+   * Closure for @e cb.
+   */
+  void *cb_cls;
+};
+
+
+/**
+ * Register function to be called whenever @a mq is being
+ * destroyed.
+ *
+ * @param mq message queue to watch
+ * @param cb function to call on @a mq destruction
+ * @param cb_cls closure for @a cb
+ * @return handle for #GNUNET_MQ_destroy_notify_cancel().
+ */
+struct GNUNET_MQ_DestroyNotificationHandle *
+GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
+                         GNUNET_SCHEDULER_TaskCallback cb,
+                         void *cb_cls)
+{
+  struct GNUNET_MQ_DestroyNotificationHandle *dnh;
+
+  dnh = GNUNET_new (struct GNUNET_MQ_DestroyNotificationHandle);
+  dnh->mq = mq;
+  dnh->cb = cb;
+  dnh->cb_cls = cb_cls;
+  GNUNET_CONTAINER_DLL_insert (mq->dnh_head,
+                              mq->dnh_tail,
+                              dnh);
+  return dnh;
+}
+
+
+/**
+ * Cancel registration from #GNUNET_MQ_destroy_notify().
+ *
+ * @param dnh handle for registration to cancel
+ */
+void
+GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh)
+{
+  struct GNUNET_MQ_Handle *mq = dnh->mq;
+  
+  GNUNET_CONTAINER_DLL_remove (mq->dnh_head,
+                              mq->dnh_tail,
+                              dnh);
+  GNUNET_free (dnh);
+}
+
+
 /* end of mq.c */