diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-07-25 16:05:56 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-07-25 16:13:23 +0200 |
commit | b1a0dcd618befbbef049d1c2ce262c97f1c70a6f (patch) | |
tree | b6e45449f5b4e7b68fc84a20995fab5d8f46ecd7 | |
parent | aaeebebf670a2019a7ac8accb40e23cd923d396b (diff) | |
download | gnunet-b1a0dcd618befbbef049d1c2ce262c97f1c70a6f.tar.gz gnunet-b1a0dcd618befbbef049d1c2ce262c97f1c70a6f.zip |
-complete new PQ event implementation, alas undertested
-rw-r--r-- | src/pq/pq.h | 15 | ||||
-rw-r--r-- | src/pq/pq_event.c | 87 |
2 files changed, 100 insertions, 2 deletions
diff --git a/src/pq/pq.h b/src/pq/pq.h index 3c89626a9..bad99b307 100644 --- a/src/pq/pq.h +++ b/src/pq/pq.h | |||
@@ -77,6 +77,21 @@ struct GNUNET_PQ_Context | |||
77 | * Lock to access @e channel_map. | 77 | * Lock to access @e channel_map. |
78 | */ | 78 | */ |
79 | pthread_mutex_t notify_lock; | 79 | pthread_mutex_t notify_lock; |
80 | |||
81 | /** | ||
82 | * Task responsible for processing events. | ||
83 | */ | ||
84 | struct GNUNET_SCHEDULER_Task *event_task; | ||
85 | |||
86 | /** | ||
87 | * File descriptor wrapper for @e event_task. | ||
88 | */ | ||
89 | struct GNUNET_NETWORK_Handle *rfd; | ||
90 | |||
91 | /** | ||
92 | * Is scheduling via the GNUnet scheduler desired? | ||
93 | */ | ||
94 | bool scheduler_on; | ||
80 | }; | 95 | }; |
81 | 96 | ||
82 | #endif | 97 | #endif |
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index b87aa6c5a..879caf842 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c | |||
@@ -235,17 +235,100 @@ GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) | |||
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | /** | ||
239 | * Function called when the Postgres FD changes and we need | ||
240 | * to update the scheduler event loop task. | ||
241 | * | ||
242 | * @param cls a `struct GNUNET_PQ_Context *` | ||
243 | * @param fd the file descriptor, possibly -1 | ||
244 | */ | ||
245 | static void | ||
246 | scheduler_fd_cb (void *cls, | ||
247 | int fd); | ||
248 | |||
249 | |||
250 | /** | ||
251 | * The GNUnet scheduler notifies us that we need to | ||
252 | * trigger the DB event poller. | ||
253 | * | ||
254 | * @param cls a `struct GNUNET_PQ_Context *` | ||
255 | */ | ||
256 | static void | ||
257 | do_scheduler_notify (void *cls) | ||
258 | { | ||
259 | struct GNUNET_PQ_Context *db = cls; | ||
260 | |||
261 | GNUNET_assert (db->scheduler_on); | ||
262 | GNUNET_assert (NULL != db->rfd); | ||
263 | GNUNET_PQ_event_do_poll (db); | ||
264 | db->event_task | ||
265 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, | ||
266 | db->rfd, | ||
267 | &do_scheduler_notify, | ||
268 | db); | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Function called when the Postgres FD changes and we need | ||
274 | * to update the scheduler event loop task. | ||
275 | * | ||
276 | * @param cls a `struct GNUNET_PQ_Context *` | ||
277 | * @param fd the file descriptor, possibly -1 | ||
278 | */ | ||
279 | static void | ||
280 | scheduler_fd_cb (void *cls, | ||
281 | int fd) | ||
282 | { | ||
283 | struct GNUNET_PQ_Context *db = cls; | ||
284 | |||
285 | if (NULL != db->event_task) | ||
286 | { | ||
287 | GNUNET_SCHEDULER_cancel (db->event_task); | ||
288 | db->event_task = NULL; | ||
289 | } | ||
290 | GNUNET_free (db->rfd); | ||
291 | if (-1 == fd) | ||
292 | return; | ||
293 | if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)) | ||
294 | return; | ||
295 | db->rfd = GNUNET_NETWORK_socket_box_native (fd); | ||
296 | db->event_task | ||
297 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, | ||
298 | db->rfd, | ||
299 | &do_scheduler_notify, | ||
300 | db); | ||
301 | } | ||
302 | |||
303 | |||
238 | void | 304 | void |
239 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) | 305 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) |
240 | { | 306 | { |
241 | GNUNET_break (0); // FIXME: not implemented | 307 | int fd; |
308 | |||
309 | GNUNET_assert (! db->scheduler_on); | ||
310 | GNUNET_assert (NULL == db->sc); | ||
311 | db->scheduler_on = true; | ||
312 | db->sc = &scheduler_fd_cb; | ||
313 | db->sc_cls = db; | ||
314 | fd = PQsocket (db->conn); | ||
315 | scheduler_fd_cb (db, | ||
316 | fd); | ||
242 | } | 317 | } |
243 | 318 | ||
244 | 319 | ||
245 | void | 320 | void |
246 | GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) | 321 | GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) |
247 | { | 322 | { |
248 | GNUNET_break (0); // FIXME: not implemented | 323 | GNUNET_assert (db->scheduler_on); |
324 | GNUNET_free (db->rfd); | ||
325 | db->sc = NULL; | ||
326 | db->scheduler_on = false; | ||
327 | if (NULL != db->event_task) | ||
328 | { | ||
329 | GNUNET_SCHEDULER_cancel (db->event_task); | ||
330 | db->event_task = NULL; | ||
331 | } | ||
249 | } | 332 | } |
250 | 333 | ||
251 | 334 | ||