/*#io
docCopyright("Steve Dekorte", 2002)
docLicense("BSD revised")
*/

#ifndef CSTACK_DEFINED
#define CSTACK_DEFINED 1

#include <setjmp.h>

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__SYMBIAN32__)
  #define CSTACK_STACKSIZE 8192
#else
  //#define CSTACK_STACKSIZE 32768
  //#define CSTACK_STACKSIZE 65536
  #define CSTACK_STACKSIZE (65536*10)
#endif

#ifdef _BSD_PPC_SETJMP_H_ 
  /* OSX */
  #define CSTACK_SETJMP  _setjmp
  #define CSTACK_LONGJMP _longjmp
#else
  #define CSTACK_SETJMP  setjmp
  #define CSTACK_LONGJMP longjmp
#endif

typedef void (CStackCallback)(void *c);

typedef struct
{
    void *context;
    jmp_buf env;
} CStack;

CStack *CStack_new(void);
void CStack_free(CStack *self);

void CStack_context_(CStack *self, void *context);
void *CStack_context(CStack *self);

char CStack_markAndCall_with_(CStack *self, CStackCallback *func, void *c);
void CStack_resume(CStack *self);

#ifdef __cplusplus
}
#endif
#endif
