qt.h.in 4.9 KB

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