Coroutines/CoroX.h
author Jens Alfke <jens@mooseyard.com>
Tue Apr 29 17:05:32 2008 -0700 (2008-04-29)
changeset 0 deb0ee0c5b21
child 1 2475f871c218
permissions -rw-r--r--
First checkin
     1 /*
     2  *  CoroX.c
     3  *  Coroutines for Mac OS X
     4  *
     5  *  Created by Jens Alfke on 4/29/08.
     6  *  Adapted from Steve Dekorte's libCoroutine:
     7  *  <http://www.dekorte.com/projects/opensource/libCoroutine/>
     8  *  by putting it on a piece of wood and banging a few nails through it.
     9  *  No, actually I removed all the stuff for cross-platform support, leaving only the simple
    10  *  code that works on Mac OS X 10.5, and then cleaned things up a bit.
    11  *
    12  *  Copyright 2008 Jens Alfke. All rights reserved.
    13  *  Copyright (c) 2002, 2003 Steve Dekorte. All rights reserved.
    14  *  License is at the bottom of CoroX.c.
    15  *
    16  */
    17 
    18 #pragma once
    19 #include <stdlib.h>
    20 #include <stdint.h>
    21 
    22 /** C coroutine implementation for Mac OS X.
    23     Based on, and API-compatible with, Steve Dekorte's libCoroutine.
    24     His docs are at http://www.dekorte.com/projects/opensource/libCoroutine/docs/
    25 */
    26 
    27 #ifdef __cplusplus
    28 extern "C" {
    29 #endif
    30     
    31     typedef struct Coro Coro;
    32     
    33     Coro *Coro_new(void);
    34     void Coro_free(Coro *self);
    35     
    36     // stack
    37     
    38     void *Coro_stack(Coro *self);
    39     size_t Coro_stackSize(Coro *self);
    40     void Coro_setStackSize_(Coro *self, size_t sizeInBytes);
    41     size_t Coro_bytesLeftOnStack(Coro *self);
    42     int Coro_stackSpaceAlmostGone(Coro *self);
    43     
    44     // initialization
    45     
    46     void Coro_initializeMainCoro(Coro *self);
    47     
    48     typedef void (CoroStartCallback)(void *);
    49     
    50     void Coro_startCoro_(Coro *self, Coro *other, void *context, CoroStartCallback *callback);
    51     
    52     // context-switch
    53     
    54     void Coro_switchTo_(Coro *self, Coro *next);
    55     
    56 #ifdef __cplusplus
    57 }
    58 #endif