diff -r deb0ee0c5b21 -r 2475f871c218 Coroutines/CoroX.h --- a/Coroutines/CoroX.h Tue Apr 29 17:05:32 2008 -0700 +++ b/Coroutines/CoroX.h Wed Apr 30 14:18:49 2008 -0700 @@ -5,9 +5,6 @@ * Created by Jens Alfke on 4/29/08. * Adapted from Steve Dekorte's libCoroutine: * - * by putting it on a piece of wood and banging a few nails through it. - * No, actually I removed all the stuff for cross-platform support, leaving only the simple - * code that works on Mac OS X 10.5, and then cleaned things up a bit. * * Copyright 2008 Jens Alfke. All rights reserved. * Copyright (c) 2002, 2003 Steve Dekorte. All rights reserved. @@ -18,6 +15,8 @@ #pragma once #include #include +#include + /** C coroutine implementation for Mac OS X. Based on, and API-compatible with, Steve Dekorte's libCoroutine. @@ -28,30 +27,30 @@ extern "C" { #endif - typedef struct Coro Coro; + typedef struct CoroX CoroX; - Coro *Coro_new(void); - void Coro_free(Coro *self); + typedef void (*CoroEntryPoint)(CoroX*); + + CoroX* CoroX_new(CoroEntryPoint, void *userData); // use entryPoint==NULL to init main Coro + void CoroX_free(CoroX*); - // stack + void CoroX_switchTo_(CoroX *current, CoroX *next); - void *Coro_stack(Coro *self); - size_t Coro_stackSize(Coro *self); - void Coro_setStackSize_(Coro *self, size_t sizeInBytes); - size_t Coro_bytesLeftOnStack(Coro *self); - int Coro_stackSpaceAlmostGone(Coro *self); + void* CoroX_userData(CoroX*); + bool CoroX_isMain(CoroX*); - // initialization + // Stack: + + extern const size_t kCoroX_minStackSize; // Minimum useable stack size - void Coro_initializeMainCoro(Coro *self); - - typedef void (CoroStartCallback)(void *); - - void Coro_startCoro_(Coro *self, Coro *other, void *context, CoroStartCallback *callback); - - // context-switch - - void Coro_switchTo_(Coro *self, Coro *next); + size_t CoroX_getDefaultStackSize(void); + void CoroX_setDefaultStackSize(size_t); + + void* CoroX_stack(CoroX*); + size_t CoroX_stackSize(CoroX*); + void CoroX_setStackSize_(CoroX*, size_t); + size_t CoroX_bytesLeftOnStack(CoroX*); + int CoroX_stackSpaceAlmostGone(CoroX*); #ifdef __cplusplus }