Commits on Feb 20, 2011
  1. Workaround v8 bugs with small stacks

    v8 seems to have some issues when you try and use stack sizes smaller
    than it's used to.
    First is that if you attempt to set a stack limit that's smaller than
    the snapshot size (if enabled) it will crash your shit in a very hard to
    understand way. Unfortunately there's no way to actually know what that
    magic size is in advance, so I'm just using a secret v8 internal
    variable. This means that for most systems each coroutine will consume
    ~320kb of memory.
    Second issue is there's a bug on 64 bit platforms when your Javascript
    overflows the stack. It's probably pretty hard to hit this bug in
    regular code but it's still quite bad. There's a workaround that I'm
    using to get past that.
    committed Feb 20, 2011
Commits on Feb 18, 2011
  1. Fix that pesky stack bug

    I was giving v8 the top of the stack instead of the bottom of the stack
    so it couldn't figure out where to stop. This change fixes that. I
    tested this using an infinite recussion function with really small
    stacks (8kb) and large ones (512k) and I'm getting reasonable results.
    Now the hard part is picking the right stack size. I'm going to go with
    64k as it's the default stack node picked for libeio threads.
    committed Feb 18, 2011
  2. Bump npm version

    committed Feb 18, 2011
  3. Simplify fiber-local storage

    Put FLS in the Coroutine object instead of with the thread in a vector.
    This technically means we are no longer calling destructors on
    outstanding keys when the keys are deleted, but that was already the
    case with multiple threads. The up side is that no one really deletes
    TLS keys unless the program is terminating anyway.
    committed Feb 18, 2011
  4. Make context swap ownership more explicit

    When swapping into a context we shouldn't remember the context we came
    from at all. That is the client's ( job. By setting the
    current_fiber this way we can be sure current_fiber is never something
    committed Feb 18, 2011
  5. Fix terrible bug in thread trampoline

    New threads created while the coroutine library is loaded have a pretty
    good chance of getting corrupted it seems. eio threading hasn't been
    put through too much scrutiny unfortunately, so I didn't catch this
    until now.
    committed Feb 18, 2011
  6. Spaces -> Tabs

    I'm going through my biennial spaces and tabs identity crisis. Tabs,
    you've hurt me in the past.. I just hope that I've learned enough so
    that it won't happen again. I'm putting a lot of faith in you, please
    don't leave me cold and alone.
    committed Feb 18, 2011
Commits on Feb 17, 2011
  1. Bump npm version

    committed Feb 17, 2011
  2. Volatile members

    This declares the member variables which getting mucked with from
    different fibers as volatile. Hopefully this will take care of some of
    the heisenbugs a few users have been reporting.
    committed Feb 17, 2011
  3. Hook pthreads earlier

    It seems that if you have v8 compiled as a shared library instead of a
    static library sometimes it can get initialized before, even
    with LD_PRELOAD. I'm not really sure why this is the case, but this
    means we need to run the hooks much earlier. So now everything that goes
    through pthread_getspecific is fiber-local, instead of the way it used
    to be where only keys created after is initialized were
    committed Feb 17, 2011
  4. Improved check for invalid calls to run()

    If you attempt to run() a fiber that's already running from inside
    another fiber you would get a segfault. This is because even though the
    fiber isn't running, it hasn't yielded either. Thus where to resume
    execution is unclear. This should throw an exception.
    Closes gh-8
    committed Feb 17, 2011
Commits on Feb 5, 2011
  1. Another bug with the loader script

    committed Feb 5, 2011
  2. Fix syntax error in fibers.js

    Whoops, how did this get in there? I swear I tested..
    committed Feb 5, 2011
Commits on Feb 3, 2011
  1. Fix node v0.2.x compatibility

    require.resolve is a new feature. v0.3.x is going stable soon, after
    which support for v0.2.x will dwindle. This also fixes 32-bit building
    on some platforms.
    Closes gh-7
    committed Feb 3, 2011
Commits on Jan 25, 2011
  1. Remove boost dependency

    Sometimes I forget that non-developers don't have boost installed... so
    to lower the friction of installation for the first time I'm removing
    boost since it's used in one place only anyway.
    committed Jan 25, 2011
Commits on Jan 24, 2011
  1. Package tweaks

    Detect on load when the fibers library is older than node, which
    probably means your build is out date. Also fix it so that `npm rebuild
    fibers` works.
    committed Jan 24, 2011
  2. Don't segfault while calling yield with no fiber

    Dereferencing uninitialized pointers is generally bad.
    committed Jan 24, 2011
Commits on Jan 23, 2011
  1. Fix behavior of child processes

    Child processes were getting the LD_PRELOAD carried over from node which
    is probably undesirable. Now when loads it nulls out those
    environment variables. Since it's loaded already they don't need to be
    Also fix a related linking error.
    committed Jan 23, 2011
  2. npm package

    This fixes the build and adds an npm package. I had to add
    LD_LIBRARY_PATH to fiber-shim because it fails to load if
    is not in your current working directory. This also uses a better
    heuristic for determining if fiber-shim was used.
    Also the library is now just called `fibers` when used in the context of
    committed Jan 23, 2011
  3. New directory structure

    Moving source files into `bin` and `src`. Also renaming ""
    to just "". This breaks the Makefile so don't try to make while
    you have this revision checked out.
    committed Jan 23, 2011
Commits on Jan 22, 2011
  1. Prevent abort trap on exit

    When running a debug version of v8 and your application terminates while
    there are still yielding fibers there's an abort trap that gets caught
    and a scary error message. v8 is trying to cleanup resources while is getting unloaded and it's all-around bad news. This
    quick and dirty hack prevents v8 from cleaning up, which actually
    doesn't make a huge difference since the application is terminating
    committed Jan 22, 2011
  2. Documentation and other inconsequential changes

    This just adds some more examples to the readme, makes Loader a totally
    self-contained class, and fixes the shebang in fiber-shim.
    committed Jan 22, 2011
  3. Fix reset() + unwinding double yield() segfault

    Not only was reset() just pointing to run(), there were problems in
    UnwindStack() which would make it seg fault in some cases. We were
    reusing `yielded` to store the exception thrown for zombified fibers,
    but that gets disposed aggressively (and rightfully so!) which leads to
    us returning a disposed pointer in the case where you re-call yield()
    from an unwinding fiber. And then in some cases v8 decided to
    garbage collect it already and that's when the fun stops.
    committed Jan 22, 2011
  4. README update

    Now with more markdown!
    committed Jan 22, 2011
Commits on Jan 20, 2011
  1. Catch illegal `this` invocations

    If you called any of the native methods with an unexpected `this`
    argument it would just fail an assertion at best, or continue with some
    other object at worst. This adds an instance check that you can't fake
    in plain Javascript to avoid those issues. Now Unwrap will throw to the
    calling code if there's a problem.
    committed Jan 20, 2011
  2. Better stack unwinding support

    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.
    committed Jan 20, 2011
Commits on Jan 19, 2011
  1. Coroutine recycling

    Instantiating new coroutines is quite expensive. Between allocating a
    new stack, getcontext(), and makecontext() we spend a good amount of
    time redoing work. The stack allocation cost is mitigated a little bit
    with the pool allocator, however it can't beat full object recylcing.
    This implements a pool of finished coroutines which are then reset and
    then returned again via `create_fiber`.
    committed Jan 19, 2011
Commits on Jan 18, 2011
  1. pthread_key destructor support

    The shim on top of pthreads did not correctly support destructors, so I
    went ahead and added that, so that when fibers are deleted the memory
    applications reserved for them is freed up correctly.
    committed Jan 18, 2011
  2. More memory correctness

    I was using auto_ptr<char> with new[] which is incorrect. So I switched
    to a vector to manage the stack, but it seems that performance took a
    hit here. That should be solved with pooling though.
    committed Jan 18, 2011
Commits on Jan 17, 2011
  1. Greatly improved memory management

    There were a lot of problems with garbage collection before,
    particularly with infinite loop generators. The problem is that the
    handle to the fiber was always held in a deadlock, since we pass it as
    the `this` context to the Fiber entry. So now `yield()` is a global,
    to avoid this problem.
    Additionally we are now giving v8 proper hints for externally-allocated
    memory, so it can handle garbage collection better. Also the coroutine
    library can free finished coroutines correctly now.
    Incidentally, node-fibers doesn't use any node-specific API's anymore;
    if you change the node.h include to be v8.h, it will still compile and
    run just fine.
    committed Jan 17, 2011
  2. Don't remake all the time

    Had a rule which could never be verified which was causing
    node-fibers.node to be rebuilt everytime.
    committed Jan 17, 2011
Commits on Jan 16, 2011
  1. Adding .gitignore

    Cleaning up `git status`.
    committed Jan 16, 2011
  2. Linux, 32-bit, and node v0.2.x support

    Added support for linux and 32-bit builds via makefile madness. I should
    probably be using waf, but I don't really care about learning that, so
    here we are. Also it was only a 2-line change to fix support for earlier
    versions of node, so why not?
    committed Jan 16, 2011
  3. Initial commit

    committed Jan 16, 2011