diff -r 000000000000 -r deb0ee0c5b21 Coroutines/CoroX.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Coroutines/CoroX.h Tue Apr 29 17:05:32 2008 -0700 @@ -0,0 +1,58 @@ +/* + * CoroX.c + * Coroutines for Mac OS X + * + * 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. + * License is at the bottom of CoroX.c. + * + */ + +#pragma once +#include +#include + +/** C coroutine implementation for Mac OS X. + Based on, and API-compatible with, Steve Dekorte's libCoroutine. + His docs are at http://www.dekorte.com/projects/opensource/libCoroutine/docs/ +*/ + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct Coro Coro; + + Coro *Coro_new(void); + void Coro_free(Coro *self); + + // stack + + 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); + + // initialization + + 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); + +#ifdef __cplusplus +} +#endif