summaryrefslogtreecommitdiff
path: root/src/pulp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulp.c')
-rw-r--r--src/pulp.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/pulp.c b/src/pulp.c
index f57f077..7972dac 100644
--- a/src/pulp.c
+++ b/src/pulp.c
@@ -352,6 +352,35 @@ pulp_t * pulp_new(void)
}
+/* reset a pulp scheduler instance for reuse */
+void pulp_reset(pulp_t *pulp)
+{
+ pulp_fiber_t *f;
+
+ assert(pulp);
+
+ pulp->exited = 0;
+ pulp->now = now();
+
+ /* XXX: Note the idle queue isn't currently utilized */
+ list_for_each_entry(f, &pulp->fibers.idle, fibers)
+ destroy_context(&f->context);
+ list_splice_init(&pulp->fibers.idle, &pulp->fibers.free);
+
+ /* The run queue is drained per-tick, but newly created fibers
+ * with 0 delay go directly on the run queue. So it's possible
+ * there will be some there outside a tick.
+ */
+ list_for_each_entry(f, &pulp->fibers.run, fibers)
+ destroy_context(&f->context);
+ list_splice_init(&pulp->fibers.run, &pulp->fibers.free);
+
+ list_for_each_entry(f, &pulp->fibers.sleep, fibers)
+ destroy_context(&f->context);
+ list_splice_init(&pulp->fibers.sleep, &pulp->fibers.free);
+}
+
+
/* free a pulp scheduler instance */
void pulp_free(pulp_t *pulp)
{
@@ -359,6 +388,8 @@ void pulp_free(pulp_t *pulp)
assert(pulp);
+ pulp_reset(pulp);
+
list_for_each_entry_safe(alloc, _alloc, &pulp->allocs, allocs)
free(alloc);
© All Rights Reserved