qt.h.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef QT_H
  2. #define QT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <qt/@qtmd_h@>
  7. /* A QuickThreads thread is represented by it's current stack pointer.
  8. To restart a thread, you merely need pass the current sp (qt_t*) to
  9. a QuickThreads primitive. `qt_t*' is a location on the stack. To
  10. improve type checking, represent it by a particular struct. */
  11. typedef struct qt_t {
  12. char dummy;
  13. } qt_t;
  14. /* Alignment is guaranteed to be a power of two. */
  15. #ifndef QT_STKALIGN
  16. #error "Need to know the machine-dependent stack alignment."
  17. #endif
  18. #define QT_STKROUNDUP(bytes) \
  19. (((bytes)+QT_STKALIGN) & ~(QT_STKALIGN-1))
  20. /* Find ``top'' of the stack, space on the stack. */
  21. #ifndef QT_SP
  22. #ifdef QT_GROW_DOWN
  23. #define QT_SP(sto, size) ((qt_t *)(&((char *)(sto))[(size)]))
  24. #endif
  25. #ifdef QT_GROW_UP
  26. #define QT_SP(sto, size) ((void *)(sto))
  27. #endif
  28. #if !defined(QT_SP)
  29. #error "QT_H: Stack must grow up or down!"
  30. #endif
  31. #endif
  32. /* The type of the user function:
  33. For non-varargs, takes one void* function.
  34. For varargs, takes some number of arguments. */
  35. typedef void *(qt_userf_t)(void *pu);
  36. typedef void *(qt_vuserf_t)(int arg0, ...);
  37. /* For non-varargs, just call a client-supplied function,
  38. it does all startup and cleanup, and also calls the user's
  39. function. */
  40. typedef void (qt_only_t)(void *pu, void *pt, qt_userf_t *userf);
  41. /* For varargs, call `startup', then call the user's function,
  42. then call `cleanup'. */
  43. typedef void (qt_startup_t)(void *pt);
  44. typedef void (qt_cleanup_t)(void *pt, void *vuserf_return);
  45. /* Internal helper for putting stuff on stack. */
  46. #ifndef QT_SPUT
  47. #define QT_SPUT(top, at, val) \
  48. (((qt_word_t *)(top))[(at)] = (qt_word_t)(val))
  49. #endif
  50. /* Push arguments for the non-varargs case. */
  51. #ifndef QT_ARGS
  52. #ifndef QT_ARGS_MD
  53. #define QT_ARGS_MD (0)
  54. #endif
  55. #ifndef QT_STKBASE
  56. #error "Need to know the machine-dependent stack allocation."
  57. #endif
  58. /* All things are put on the stack relative to the final value of
  59. the stack pointer. */
  60. #ifdef QT_GROW_DOWN
  61. #define QT_ADJ(sp) (((char *)sp) - QT_STKBASE)
  62. #else
  63. #define QT_ADJ(sp) (((char *)sp) + QT_STKBASE)
  64. #endif
  65. #define QT_ARGS(sp, pu, pt, userf, only) \
  66. (QT_ARGS_MD (QT_ADJ(sp)), \
  67. QT_SPUT (QT_ADJ(sp), QT_ONLY_INDEX, only), \
  68. QT_SPUT (QT_ADJ(sp), QT_USER_INDEX, userf), \
  69. QT_SPUT (QT_ADJ(sp), QT_ARGT_INDEX, pt), \
  70. QT_SPUT (QT_ADJ(sp), QT_ARGU_INDEX, pu), \
  71. ((qt_t *)QT_ADJ(sp)))
  72. #endif
  73. /* Push arguments for the varargs case.
  74. Has to be a function call because initialization is an expression
  75. and we need to loop to copy nbytes of stuff on to the stack.
  76. But that's probably OK, it's not terribly cheap, anyway. */
  77. #ifdef QT_VARGS_DEFAULT
  78. #ifndef QT_VARGS_MD0
  79. #define QT_VARGS_MD0(sp, vasize) (sp)
  80. #endif
  81. #ifndef QT_VARGS_MD1
  82. #define QT_VARGS_MD1(sp) do { ; } while (0)
  83. #endif
  84. #ifndef QT_VSTKBASE
  85. #error "Need base stack size for varargs functions."
  86. #endif
  87. /* Sometimes the stack pointer needs to munged a bit when storing
  88. the list of arguments. */
  89. #ifndef QT_VARGS_ADJUST
  90. #define QT_VARGS_ADJUST(sp) (sp)
  91. #endif
  92. /* All things are put on the stack relative to the final value of
  93. the stack pointer. */
  94. #ifdef QT_GROW_DOWN
  95. #define QT_VADJ(sp) (((char *)sp) - QT_VSTKBASE)
  96. #else
  97. #define QT_VADJ(sp) (((char *)sp) + QT_VSTKBASE)
  98. #endif
  99. extern qt_t *qt_vargs (qt_t *sp, int nbytes, void *vargs,
  100. void *pt, qt_startup_t *startup,
  101. qt_vuserf_t *vuserf, qt_cleanup_t *cleanup);
  102. #ifndef QT_VARGS
  103. #define QT_VARGS(sp, nbytes, vargs, pt, startup, vuserf, cleanup) \
  104. (qt_vargs (sp, nbytes, vargs, pt, startup, vuserf, cleanup))
  105. #endif
  106. #endif
  107. extern void qt_null (void);
  108. extern void qt_error (void);
  109. /* Save the state of the thread and call the helper function
  110. using the stack of the new thread. */
  111. typedef void *(qt_helper_t)(qt_t *old, void *a0, void *a1);
  112. typedef void *(qt_block_t)(qt_helper_t *helper, void *a0, void *a1,
  113. qt_t *newthread);
  114. /* Rearrange the parameters so that things passed to the helper
  115. function are already in the right argument registers. */
  116. #ifndef QT_ABORT
  117. extern void qt_abort (qt_helper_t *h, void *a0, void *a1, qt_t *newthread);
  118. /* The following does, technically, `return' a value, but the
  119. user had better not rely on it, since the function never
  120. returns. */
  121. #define QT_ABORT(h, a0, a1, newthread) \
  122. do { qt_abort (h, a0, a1, newthread); } while (0)
  123. #endif
  124. #ifndef QT_BLOCK
  125. extern void *qt_block (qt_helper_t *h, void *a0, void *a1,
  126. qt_t *newthread);
  127. #define QT_BLOCK(h, a0, a1, newthread) \
  128. (qt_block (h, a0, a1, newthread))
  129. #endif
  130. #ifndef QT_BLOCKI
  131. extern void *qt_blocki (qt_helper_t *h, void *a0, void *a1,
  132. qt_t *newthread);
  133. #define QT_BLOCKI(h, a0, a1, newthread) \
  134. (qt_blocki (h, a0, a1, newthread))
  135. #endif
  136. #ifdef __cplusplus
  137. } /* Match `extern "C" {' at top. */
  138. #endif
  139. #endif /* ndef QT_H */