Coroutines/CoroX.h
changeset 0 deb0ee0c5b21
child 1 2475f871c218
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Coroutines/CoroX.h	Tue Apr 29 17:05:32 2008 -0700
     1.3 @@ -0,0 +1,58 @@
     1.4 +/*
     1.5 + *  CoroX.c
     1.6 + *  Coroutines for Mac OS X
     1.7 + *
     1.8 + *  Created by Jens Alfke on 4/29/08.
     1.9 + *  Adapted from Steve Dekorte's libCoroutine:
    1.10 + *  <http://www.dekorte.com/projects/opensource/libCoroutine/>
    1.11 + *  by putting it on a piece of wood and banging a few nails through it.
    1.12 + *  No, actually I removed all the stuff for cross-platform support, leaving only the simple
    1.13 + *  code that works on Mac OS X 10.5, and then cleaned things up a bit.
    1.14 + *
    1.15 + *  Copyright 2008 Jens Alfke. All rights reserved.
    1.16 + *  Copyright (c) 2002, 2003 Steve Dekorte. All rights reserved.
    1.17 + *  License is at the bottom of CoroX.c.
    1.18 + *
    1.19 + */
    1.20 +
    1.21 +#pragma once
    1.22 +#include <stdlib.h>
    1.23 +#include <stdint.h>
    1.24 +
    1.25 +/** C coroutine implementation for Mac OS X.
    1.26 +    Based on, and API-compatible with, Steve Dekorte's libCoroutine.
    1.27 +    His docs are at http://www.dekorte.com/projects/opensource/libCoroutine/docs/
    1.28 +*/
    1.29 +
    1.30 +#ifdef __cplusplus
    1.31 +extern "C" {
    1.32 +#endif
    1.33 +    
    1.34 +    typedef struct Coro Coro;
    1.35 +    
    1.36 +    Coro *Coro_new(void);
    1.37 +    void Coro_free(Coro *self);
    1.38 +    
    1.39 +    // stack
    1.40 +    
    1.41 +    void *Coro_stack(Coro *self);
    1.42 +    size_t Coro_stackSize(Coro *self);
    1.43 +    void Coro_setStackSize_(Coro *self, size_t sizeInBytes);
    1.44 +    size_t Coro_bytesLeftOnStack(Coro *self);
    1.45 +    int Coro_stackSpaceAlmostGone(Coro *self);
    1.46 +    
    1.47 +    // initialization
    1.48 +    
    1.49 +    void Coro_initializeMainCoro(Coro *self);
    1.50 +    
    1.51 +    typedef void (CoroStartCallback)(void *);
    1.52 +    
    1.53 +    void Coro_startCoro_(Coro *self, Coro *other, void *context, CoroStartCallback *callback);
    1.54 +    
    1.55 +    // context-switch
    1.56 +    
    1.57 +    void Coro_switchTo_(Coro *self, Coro *next);
    1.58 +    
    1.59 +#ifdef __cplusplus
    1.60 +}
    1.61 +#endif