Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created February 24, 2011 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mraleph/842959 to your computer and use it in GitHub Desktop.
Save mraleph/842959 to your computer and use it in GitHub Desktop.
static coroutine* curr_coroutine; // getspecific, setspecific use this global var to know what is running
void resume (coroutine* target) {
coroutine* self = curr_coroutine;
{ Unlocker unlocker; // archive currently running coroutine
curr_coroutine = target;
switch_context(target);
current_coroutine = self;
} // here ~Unlocker will restore information from curr_coroutine.
}
// this is a coroutine entry point
void entry (coroutine* self) {
curr_coroutine = self;
{ Locker lock; // we are entering new coroutine
invoke_javascript_code();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment