Skip to content

Commit

Permalink
Better stack unwinding support
Browse files Browse the repository at this point in the history
This adds two new methods reset(), and throwInto(). Both will throw
exceptions into a yielding fiber, however reset() will take care of
catching the thrown exception and gracefully returning. throwInto() will
likely throw your exception right back out.

reset() can be used in cases where infinite loop generators are used
extensively. Leaving destruction of those fibers to v8 is generally
inefficient. throwInto() could be used to notify a fiber that you don't
care about its task anymore.

This also defers unwinding of orphaned fibers until after garbage
collection has finished. This greatly increases the speed at which
orphaned fibers are collected.
  • Loading branch information
laverdet committed Jan 20, 2011
1 parent fbef75c commit d0cfd2d
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 70 deletions.
6 changes: 2 additions & 4 deletions coroutine.cc
Expand Up @@ -237,14 +237,12 @@ void Coroutine::run() {
Coroutine& current = *thread.current_fiber;
assert(&current != this);
thread.current_fiber = this;
swapcontext(&current.context, &context);
thread.current_fiber = &current;
if (thread.delete_me) {
assert(thread.delete_me == this);
Thread& thread = this->thread;
delete thread.delete_me;
thread.delete_me = NULL;
}
swapcontext(&current.context, &context);
thread.current_fiber = &current;
}

void Coroutine::finish(Coroutine& next) {
Expand Down

0 comments on commit d0cfd2d

Please sign in to comment.