home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / ThreadLib 1.0d1 / Source / ThreadLib / ThreadLib.h < prev   
Encoding:
C/C++ Source or Header  |  1994-02-10  |  2.4 KB  |  74 lines  |  [TEXT/KAHL]

  1. /* See the file Distribution for distribution terms.
  2.     (c) Copyright 1994 Ari Halberstadt */
  3.  
  4. #pragma once
  5.  
  6. #if WINTER_SHELL
  7.     #include "LLHandleLib.h"
  8.     #include "TimeLib.h"
  9. #else /* WINTER_SHELL */
  10.     #include "ThreadUtil.h"
  11.     #include "ExceptionLib.h"
  12. #endif /* WINTER_SHELL */
  13.  
  14. /* Define as 1 to save certain low-memory global variables on context
  15.     switches. See warning in ThreadLib.c for more details. */
  16. #define THREAD_SAVE_GLOBALS    (0)
  17.  
  18. /* version of the thread library */
  19. #define THREAD_VERSION            (1)
  20.  
  21. /* default stack size */
  22. #define THREAD_STACK_SIZE        (0x2000)
  23.  
  24. /* function called as thread's entry point */
  25. typedef void (*ThreadProcType)(void *data);
  26.  
  27. /* information needed in SegmentLib.c */
  28. typedef struct {
  29.     Ptr stack_top;            /* highest address in thread's stack */
  30.     Ptr stack_bottom;        /* lowest address in thread's stack */
  31.     Ptr register_a6;        /* value of thread's register a6 */
  32. } ThreadStackFrameType;
  33.  
  34. /* data describing a thread */
  35. typedef struct {
  36.     LLType next;                    /* next thread */
  37.     jmp_buf env;                    /* for context switch */
  38.     Ptr stack;                        /* thread's stack */
  39.     TicksType wake;                /* when to wake thread */
  40.     ThreadProcType entry;        /* thread's entry point */
  41.     ThreadProcType suspend;        /* called when thread is suspended */
  42.     ThreadProcType resume;        /* called when thread is resumed */
  43.     ExceptionType exception;    /* saved state of gExeception global variable */
  44.     void *data;                        /* data to pass to thread's call-backs */
  45.     #if THREAD_SAVE_GLOBALS
  46.         Ptr heapEnd;                /* value of HeapEnd low-memory global */
  47.         Ptr applLimit;                /* value of ApplLimit low-memory global */
  48.         Ptr hiHeapMark;            /* value of HiHeapMark low-memory global */
  49.     #endif /* THREAD_SAVE_GLOBALS */
  50. } ThreadType, *ThreadPtr, **ThreadHandle;
  51.  
  52. Boolean ThreadValid(ThreadHandle thread);
  53.  
  54. size_t ThreadStackSpace(ThreadHandle thread);
  55. void ThreadStackFrame(ThreadHandle thread, ThreadStackFrameType *frame);
  56.  
  57. short ThreadCount(void);
  58. ThreadHandle ThreadMain(void);
  59. ThreadHandle ThreadActive(void);
  60. ThreadHandle ThreadFirst(void);
  61. ThreadHandle ThreadNext(ThreadHandle thread);
  62.  
  63. ThreadHandle ThreadSchedule(void);
  64. void ThreadActivate(ThreadHandle thread);
  65. void ThreadYield(TicksType sleep);
  66. TicksType ThreadYieldInterval(void);
  67.  
  68. ThreadHandle ThreadBeginMain(ThreadProcType suspend, ThreadProcType resume,
  69.     void *data);
  70. ThreadHandle ThreadBegin(ThreadProcType entry,
  71.     ThreadProcType suspend, ThreadProcType resume,
  72.     void *data, size_t stack_size);
  73. void ThreadEnd(ThreadHandle thread);
  74.