aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_mq_lib.h30
-rw-r--r--src/nse/gnunet-service-nse.c4
-rw-r--r--src/util/mq.c87
3 files changed, 119 insertions, 2 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 999ee4134..ff8c9ba1b 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -637,6 +637,36 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq);
637 637
638 638
639/** 639/**
640 * Handle we return for callbacks registered to be
641 * notified when #GNUNET_MQ_destroy() is called on a queue.
642 */
643struct GNUNET_MQ_DestroyNotificationHandle;
644
645
646/**
647 * Register function to be called whenever @a mq is being
648 * destroyed.
649 *
650 * @param mq message queue to watch
651 * @param cb function to call on @a mq destruction
652 * @param cb_cls closure for @a cb
653 * @return handle for #GNUNET_MQ_destroy_notify_cancel().
654 */
655struct GNUNET_MQ_DestroyNotificationHandle *
656GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
657 GNUNET_SCHEDULER_TaskCallback cb,
658 void *cb_cls);
659
660/**
661 * Cancel registration from #GNUNET_MQ_destroy_notify().
662 *
663 * @param dnh handle for registration to cancel
664 */
665void
666GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh);
667
668
669/**
640 * Call the message message handler that was registered 670 * Call the message message handler that was registered
641 * for the type of the given message in the given message queue. 671 * for the type of the given message in the given message queue.
642 * 672 *
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 1f06c0a75..bf7c79fcb 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -276,12 +276,12 @@ static unsigned int estimate_count;
276/** 276/**
277 * Task scheduled to update our flood message for the next round. 277 * Task scheduled to update our flood message for the next round.
278 */ 278 */
279static struct GNUNET_SCHEDULER_Task * flood_task; 279static struct GNUNET_SCHEDULER_Task *flood_task;
280 280
281/** 281/**
282 * Task scheduled to compute our proof. 282 * Task scheduled to compute our proof.
283 */ 283 */
284static struct GNUNET_SCHEDULER_Task * proof_task; 284static struct GNUNET_SCHEDULER_Task *proof_task;
285 285
286/** 286/**
287 * Notification context, simplifies client broadcasts. 287 * Notification context, simplifies client broadcasts.
diff --git a/src/util/mq.c b/src/util/mq.c
index e9dba3d9d..01cdf764b 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -155,6 +155,16 @@ struct GNUNET_MQ_Handle
155 struct GNUNET_SCHEDULER_Task *continue_task; 155 struct GNUNET_SCHEDULER_Task *continue_task;
156 156
157 /** 157 /**
158 * Functions to call on queue destruction; kept in a DLL.
159 */
160 struct GNUNET_MQ_DestroyNotificationHandle *dnh_head;
161
162 /**
163 * Functions to call on queue destruction; kept in a DLL.
164 */
165 struct GNUNET_MQ_DestroyNotificationHandle *dnh_tail;
166
167 /**
158 * Additional options buffer set for this queue by 168 * Additional options buffer set for this queue by
159 * #GNUNET_MQ_set_options(). Default is 0. 169 * #GNUNET_MQ_set_options(). Default is 0.
160 */ 170 */
@@ -1173,4 +1183,81 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
1173} 1183}
1174 1184
1175 1185
1186/**
1187 * Handle we return for callbacks registered to be
1188 * notified when #GNUNET_MQ_destroy() is called on a queue.
1189 */
1190struct GNUNET_MQ_DestroyNotificationHandle
1191{
1192 /**
1193 * Kept in a DLL.
1194 */
1195 struct GNUNET_MQ_DestroyNotificationHandle *prev;
1196
1197 /**
1198 * Kept in a DLL.
1199 */
1200 struct GNUNET_MQ_DestroyNotificationHandle *next;
1201
1202 /**
1203 * Queue to notify about.
1204 */
1205 struct GNUNET_MQ_Handle *mq;
1206
1207 /**
1208 * Function to call.
1209 */
1210 GNUNET_SCHEDULER_TaskCallback cb;
1211
1212 /**
1213 * Closure for @e cb.
1214 */
1215 void *cb_cls;
1216};
1217
1218
1219/**
1220 * Register function to be called whenever @a mq is being
1221 * destroyed.
1222 *
1223 * @param mq message queue to watch
1224 * @param cb function to call on @a mq destruction
1225 * @param cb_cls closure for @a cb
1226 * @return handle for #GNUNET_MQ_destroy_notify_cancel().
1227 */
1228struct GNUNET_MQ_DestroyNotificationHandle *
1229GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
1230 GNUNET_SCHEDULER_TaskCallback cb,
1231 void *cb_cls)
1232{
1233 struct GNUNET_MQ_DestroyNotificationHandle *dnh;
1234
1235 dnh = GNUNET_new (struct GNUNET_MQ_DestroyNotificationHandle);
1236 dnh->mq = mq;
1237 dnh->cb = cb;
1238 dnh->cb_cls = cb_cls;
1239 GNUNET_CONTAINER_DLL_insert (mq->dnh_head,
1240 mq->dnh_tail,
1241 dnh);
1242 return dnh;
1243}
1244
1245
1246/**
1247 * Cancel registration from #GNUNET_MQ_destroy_notify().
1248 *
1249 * @param dnh handle for registration to cancel
1250 */
1251void
1252GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh)
1253{
1254 struct GNUNET_MQ_Handle *mq = dnh->mq;
1255
1256 GNUNET_CONTAINER_DLL_remove (mq->dnh_head,
1257 mq->dnh_tail,
1258 dnh);
1259 GNUNET_free (dnh);
1260}
1261
1262
1176/* end of mq.c */ 1263/* end of mq.c */