4 #if defined (QT_IMPORT)
5 # define QT_API __declspec (dllimport) extern
6 #elif defined (QT_EXPORT) || defined (DLL_EXPORT)
7 # define QT_API __declspec (dllexport) extern
16 #include <qt/@qtmd_h@>
19 /* A QuickThreads thread is represented by it's current stack pointer.
20 To restart a thread, you merely need pass the current sp (qt_t*) to
21 a QuickThreads primitive. `qt_t*' is a location on the stack. To
22 improve type checking, represent it by a particular struct. */
29 /* Alignment is guaranteed to be a power of two. */
31 #error "Need to know the machine-dependent stack alignment."
34 #define QT_STKROUNDUP(bytes) \
35 (((bytes)+QT_STKALIGN) & ~(QT_STKALIGN-1))
38 /* Find ``top'' of the stack, space on the stack. */
41 #define QT_SP(sto, size) ((qt_t *)(&((char *)(sto))[(size)]))
44 #define QT_SP(sto, size) ((void *)(sto))
47 #error "QT_H: Stack must grow up or down!"
52 /* The type of the user function:
53 For non-varargs, takes one void* function.
54 For varargs, takes some number of arguments. */
55 typedef void *(qt_userf_t)(void *pu);
56 typedef void *(qt_vuserf_t)(int arg0, ...);
58 /* For non-varargs, just call a client-supplied function,
59 it does all startup and cleanup, and also calls the user's
61 typedef void (qt_only_t)(void *pu, void *pt, qt_userf_t *userf);
63 /* For varargs, call `startup', then call the user's function,
64 then call `cleanup'. */
65 typedef void (qt_startup_t)(void *pt);
66 typedef void (qt_cleanup_t)(void *pt, void *vuserf_return);
69 /* Internal helper for putting stuff on stack. */
71 #define QT_SPUT(top, at, val) \
72 (((qt_word_t *)(top))[(at)] = (qt_word_t)(val))
76 /* Push arguments for the non-varargs case. */
80 #define QT_ARGS_MD (0)
84 #error "Need to know the machine-dependent stack allocation."
87 /* All things are put on the stack relative to the final value of
90 #define QT_ADJ(sp) (((char *)sp) - QT_STKBASE)
92 #define QT_ADJ(sp) (((char *)sp) + QT_STKBASE)
95 #define QT_ARGS(sp, pu, pt, userf, only) \
96 (QT_ARGS_MD (QT_ADJ(sp)), \
97 QT_SPUT (QT_ADJ(sp), QT_ONLY_INDEX, only), \
98 QT_SPUT (QT_ADJ(sp), QT_USER_INDEX, userf), \
99 QT_SPUT (QT_ADJ(sp), QT_ARGT_INDEX, pt), \
100 QT_SPUT (QT_ADJ(sp), QT_ARGU_INDEX, pu), \
101 ((qt_t *)QT_ADJ(sp)))
106 /* Push arguments for the varargs case.
107 Has to be a function call because initialization is an expression
108 and we need to loop to copy nbytes of stuff on to the stack.
109 But that's probably OK, it's not terribly cheap, anyway. */
111 #ifdef QT_VARGS_DEFAULT
113 #define QT_VARGS_MD0(sp, vasize) (sp)
116 #define QT_VARGS_MD1(sp) do { ; } while (0)
120 #error "Need base stack size for varargs functions."
123 /* Sometimes the stack pointer needs to munged a bit when storing
124 the list of arguments. */
125 #ifndef QT_VARGS_ADJUST
126 #define QT_VARGS_ADJUST(sp) (sp)
129 /* All things are put on the stack relative to the final value of
130 the stack pointer. */
132 #define QT_VADJ(sp) (((char *)sp) - QT_VSTKBASE)
134 #define QT_VADJ(sp) (((char *)sp) + QT_VSTKBASE)
137 QT_API qt_t *qt_vargs (qt_t *sp, int nbytes, void *vargs,
138 void *pt, qt_startup_t *startup,
139 qt_vuserf_t *vuserf, qt_cleanup_t *cleanup);
142 #define QT_VARGS(sp, nbytes, vargs, pt, startup, vuserf, cleanup) \
143 (qt_vargs (sp, nbytes, vargs, pt, startup, vuserf, cleanup))
148 QT_API void qt_null (void);
149 QT_API void qt_error (void);
151 /* Save the state of the thread and call the helper function
152 using the stack of the new thread. */
153 typedef void *(qt_helper_t)(qt_t *old, void *a0, void *a1);
154 typedef void *(qt_block_t)(qt_helper_t *helper, void *a0, void *a1,
157 /* Rearrange the parameters so that things passed to the helper
158 function are already in the right argument registers. */
160 QT_API void qt_abort (qt_helper_t *h, void *a0, void *a1, qt_t *newthread);
161 /* The following does, technically, `return' a value, but the
162 user had better not rely on it, since the function never
164 #define QT_ABORT(h, a0, a1, newthread) \
165 do { qt_abort (h, a0, a1, newthread); } while (0)
169 QT_API void *qt_block (qt_helper_t *h, void *a0, void *a1,
171 #define QT_BLOCK(h, a0, a1, newthread) \
172 (qt_block (h, a0, a1, newthread))
176 QT_API void *qt_blocki (qt_helper_t *h, void *a0, void *a1,
178 #define QT_BLOCKI(h, a0, a1, newthread) \
179 (qt_blocki (h, a0, a1, newthread))
183 } /* Match `extern "C" {' at top. */
186 #endif /* ndef QT_H */