summaryrefslogtreecommitdiff
path: root/sysdep/unix/coroutine.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-06-19 20:50:18 +0200
committerMaria Matejka <mq@ucw.cz>2021-11-22 19:05:43 +0100
commit94eb0858c2b938549d9d1703c872c6149901e7dd (patch)
tree2eb0cff73002b4278916c1ad6865b7a85b680bd1 /sysdep/unix/coroutine.c
parentc84ed603714db2c42a781f8dbb5b3fd540ff689f (diff)
Converting the former BFD loop to a universal IO loop and protocol loop.
There is a simple universal IO loop, taking care of events, timers and sockets. Primarily, one instance of a protocol should use exactly one IO loop to do all its work, as is now done in BFD. Contrary to previous versions, the loop is now launched and cleaned by the nest/proto.c code, allowing for a protocol to just request its own loop by setting the loop's lock order in config higher than the_bird. It is not supported nor checked if any protocol changed the requested lock order in reconfigure. No protocol should do it at all.
Diffstat (limited to 'sysdep/unix/coroutine.c')
-rw-r--r--sysdep/unix/coroutine.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/sysdep/unix/coroutine.c b/sysdep/unix/coroutine.c
index 2eba142c..4758c056 100644
--- a/sysdep/unix/coroutine.c
+++ b/sysdep/unix/coroutine.c
@@ -21,10 +21,9 @@
#include "lib/resource.h"
#include "lib/timer.h"
-/* Using a rather big stack for coroutines to allow for stack-local allocations.
- * In real world, the kernel doesn't alloc this memory until it is used.
- * */
-#define CORO_STACK_SIZE 1048576
+#include "conf/conf.h"
+
+#define CORO_STACK_SIZE 65536
/*
* Implementation of coroutines based on POSIX threads
@@ -79,6 +78,11 @@ domain_free(struct domain_generic *dg)
xfree(dg);
}
+uint dg_order(struct domain_generic *dg)
+{
+ return dg->order;
+}
+
void do_lock(struct domain_generic *dg, struct domain_generic **lsp)
{
if ((char *) lsp - (char *) &locking_stack != dg->order)
@@ -89,7 +93,11 @@ void do_lock(struct domain_generic *dg, struct domain_generic **lsp)
if (*lsp)
bug("Inconsistent locking stack state on lock");
+ btime lock_begin = current_time();
pthread_mutex_lock(&dg->mutex);
+ btime duration = current_time() - lock_begin;
+ if (config && (duration > config->watchdog_warning))
+ log(L_WARN "Locking of %s took %d ms", dg->name, (int) (duration TO_MS));
if (dg->prev || dg->locked_by)
bug("Previous unlock not finished correctly");
@@ -140,11 +148,16 @@ static struct resclass coro_class = {
.free = coro_free,
};
+_Thread_local struct coroutine *this_coro = NULL;
+
static void *coro_entry(void *p)
{
struct coroutine *c = p;
+
ASSERT_DIE(c->entry);
+ this_coro = c;
+
c->entry(c->data);
ASSERT_DIE(coro_cleaned_up);