aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-19 14:31:14 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-19 14:31:14 +0000
commit63eb0920ef2261e98dc0ff6310c303a5d8c163ce (patch)
tree3c88a4fce9f507e2978a2ea463d51e692c31202c /src/util
parent64fda257bdaf166ed3d96dce3a01ea14017a2a3e (diff)
downloadgnunet-63eb0920ef2261e98dc0ff6310c303a5d8c163ce.tar.gz
gnunet-63eb0920ef2261e98dc0ff6310c303a5d8c163ce.zip
towards adding mq destruction notification
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mq.c87
1 files changed, 87 insertions, 0 deletions
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 */