1.1 --- a/Coroutines/CoroX.h Tue Apr 29 17:05:32 2008 -0700
1.2 +++ b/Coroutines/CoroX.h Wed Apr 30 14:18:49 2008 -0700
1.3 @@ -5,9 +5,6 @@
1.4 * Created by Jens Alfke on 4/29/08.
1.5 * Adapted from Steve Dekorte's libCoroutine:
1.6 * <http://www.dekorte.com/projects/opensource/libCoroutine/>
1.7 - * by putting it on a piece of wood and banging a few nails through it.
1.8 - * No, actually I removed all the stuff for cross-platform support, leaving only the simple
1.9 - * code that works on Mac OS X 10.5, and then cleaned things up a bit.
1.10 *
1.11 * Copyright 2008 Jens Alfke. All rights reserved.
1.12 * Copyright (c) 2002, 2003 Steve Dekorte. All rights reserved.
1.13 @@ -18,6 +15,8 @@
1.14 #pragma once
1.15 #include <stdlib.h>
1.16 #include <stdint.h>
1.17 +#include <stdbool.h>
1.18 +
1.19
1.20 /** C coroutine implementation for Mac OS X.
1.21 Based on, and API-compatible with, Steve Dekorte's libCoroutine.
1.22 @@ -28,30 +27,30 @@
1.23 extern "C" {
1.24 #endif
1.25
1.26 - typedef struct Coro Coro;
1.27 + typedef struct CoroX CoroX;
1.28
1.29 - Coro *Coro_new(void);
1.30 - void Coro_free(Coro *self);
1.31 + typedef void (*CoroEntryPoint)(CoroX*);
1.32 +
1.33 + CoroX* CoroX_new(CoroEntryPoint, void *userData); // use entryPoint==NULL to init main Coro
1.34 + void CoroX_free(CoroX*);
1.35
1.36 - // stack
1.37 + void CoroX_switchTo_(CoroX *current, CoroX *next);
1.38
1.39 - void *Coro_stack(Coro *self);
1.40 - size_t Coro_stackSize(Coro *self);
1.41 - void Coro_setStackSize_(Coro *self, size_t sizeInBytes);
1.42 - size_t Coro_bytesLeftOnStack(Coro *self);
1.43 - int Coro_stackSpaceAlmostGone(Coro *self);
1.44 + void* CoroX_userData(CoroX*);
1.45 + bool CoroX_isMain(CoroX*);
1.46
1.47 - // initialization
1.48 + // Stack:
1.49 +
1.50 + extern const size_t kCoroX_minStackSize; // Minimum useable stack size
1.51
1.52 - void Coro_initializeMainCoro(Coro *self);
1.53 -
1.54 - typedef void (CoroStartCallback)(void *);
1.55 -
1.56 - void Coro_startCoro_(Coro *self, Coro *other, void *context, CoroStartCallback *callback);
1.57 -
1.58 - // context-switch
1.59 -
1.60 - void Coro_switchTo_(Coro *self, Coro *next);
1.61 + size_t CoroX_getDefaultStackSize(void);
1.62 + void CoroX_setDefaultStackSize(size_t);
1.63 +
1.64 + void* CoroX_stack(CoroX*);
1.65 + size_t CoroX_stackSize(CoroX*);
1.66 + void CoroX_setStackSize_(CoroX*, size_t);
1.67 + size_t CoroX_bytesLeftOnStack(CoroX*);
1.68 + int CoroX_stackSpaceAlmostGone(CoroX*);
1.69
1.70 #ifdef __cplusplus
1.71 }