[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -complete new PQ event implementation, a
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -complete new PQ event implementation, alas undertested |
Date: |
Sun, 25 Jul 2021 16:16:40 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new b1a0dcd61 -complete new PQ event implementation, alas undertested
b1a0dcd61 is described below
commit b1a0dcd618befbbef049d1c2ce262c97f1c70a6f
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sun Jul 25 16:05:56 2021 +0200
-complete new PQ event implementation, alas undertested
---
src/pq/pq.h | 15 ++++++++++
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
* Lock to access @e channel_map.
*/
pthread_mutex_t notify_lock;
+
+ /**
+ * Task responsible for processing events.
+ */
+ struct GNUNET_SCHEDULER_Task *event_task;
+
+ /**
+ * File descriptor wrapper for @e event_task.
+ */
+ struct GNUNET_NETWORK_Handle *rfd;
+
+ /**
+ * Is scheduling via the GNUnet scheduler desired?
+ */
+ bool scheduler_on;
};
#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)
}
+/**
+ * Function called when the Postgres FD changes and we need
+ * to update the scheduler event loop task.
+ *
+ * @param cls a `struct GNUNET_PQ_Context *`
+ * @param fd the file descriptor, possibly -1
+ */
+static void
+scheduler_fd_cb (void *cls,
+ int fd);
+
+
+/**
+ * The GNUnet scheduler notifies us that we need to
+ * trigger the DB event poller.
+ *
+ * @param cls a `struct GNUNET_PQ_Context *`
+ */
+static void
+do_scheduler_notify (void *cls)
+{
+ struct GNUNET_PQ_Context *db = cls;
+
+ GNUNET_assert (db->scheduler_on);
+ GNUNET_assert (NULL != db->rfd);
+ GNUNET_PQ_event_do_poll (db);
+ db->event_task
+ = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
+ db->rfd,
+ &do_scheduler_notify,
+ db);
+}
+
+
+/**
+ * Function called when the Postgres FD changes and we need
+ * to update the scheduler event loop task.
+ *
+ * @param cls a `struct GNUNET_PQ_Context *`
+ * @param fd the file descriptor, possibly -1
+ */
+static void
+scheduler_fd_cb (void *cls,
+ int fd)
+{
+ struct GNUNET_PQ_Context *db = cls;
+
+ if (NULL != db->event_task)
+ {
+ GNUNET_SCHEDULER_cancel (db->event_task);
+ db->event_task = NULL;
+ }
+ GNUNET_free (db->rfd);
+ if (-1 == fd)
+ return;
+ if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
+ return;
+ db->rfd = GNUNET_NETWORK_socket_box_native (fd);
+ db->event_task
+ = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
+ db->rfd,
+ &do_scheduler_notify,
+ db);
+}
+
+
void
GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db)
{
- GNUNET_break (0); // FIXME: not implemented
+ int fd;
+
+ GNUNET_assert (! db->scheduler_on);
+ GNUNET_assert (NULL == db->sc);
+ db->scheduler_on = true;
+ db->sc = &scheduler_fd_cb;
+ db->sc_cls = db;
+ fd = PQsocket (db->conn);
+ scheduler_fd_cb (db,
+ fd);
}
void
GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db)
{
- GNUNET_break (0); // FIXME: not implemented
+ GNUNET_assert (db->scheduler_on);
+ GNUNET_free (db->rfd);
+ db->sc = NULL;
+ db->scheduler_on = false;
+ if (NULL != db->event_task)
+ {
+ GNUNET_SCHEDULER_cancel (db->event_task);
+ db->event_task = NULL;
+ }
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -complete new PQ event implementation, alas undertested,
gnunet <=