11 /* A QuickThreads thread is represented by it's current stack pointer.
12 To restart a thread, you merely need pass the current sp (qt_t*) to
13 a QuickThreads primitive. `qt_t*' is a location on the stack. To
14 improve type checking, represent it by a particular struct. */
21 /* Alignment is guaranteed to be a power of two. */
23 #error "Need to know the machine-dependent stack alignment."
26 #define QT_STKROUNDUP(bytes) \
27 (((bytes)+QT_STKALIGN) & ~(QT_STKALIGN-1))
30 /* Find ``top'' of the stack, space on the stack. */
33 #define QT_SP(sto, size) ((qt_t *)(&((char *)(sto))[(size)]))
36 #define QT_SP(sto, size) ((void *)(sto))
39 #error "QT_H: Stack must grow up or down!"
44 /* The type of the user function:
45 For non-varargs, takes one void* function.
46 For varargs, takes some number of arguments. */
47 typedef void *(qt_userf_t
)(void *pu
);
48 typedef void *(qt_vuserf_t
)(int arg0
, ...);
50 /* For non-varargs, just call a client-supplied function,
51 it does all startup and cleanup, and also calls the user's
53 typedef void (qt_only_t
)(void *pu
, void *pt
, qt_userf_t
*userf
);
55 /* For varargs, call `startup', then call the user's function,
56 then call `cleanup'. */
57 typedef void (qt_startup_t
)(void *pt
);
58 typedef void (qt_cleanup_t
)(void *pt
, void *vuserf_return
);
61 /* Internal helper for putting stuff on stack. */
63 #define QT_SPUT(top, at, val) \
64 (((qt_word_t *)(top))[(at)] = (qt_word_t)(val))
68 /* Push arguments for the non-varargs case. */
72 #define QT_ARGS_MD (0)
76 #error "Need to know the machine-dependent stack allocation."
79 /* All things are put on the stack relative to the final value of
82 #define QT_ADJ(sp) (((char *)sp) - QT_STKBASE)
84 #define QT_ADJ(sp) (((char *)sp) + QT_STKBASE)
87 #define QT_ARGS(sp, pu, pt, userf, only) \
88 (QT_ARGS_MD (QT_ADJ(sp)), \
89 QT_SPUT (QT_ADJ(sp), QT_ONLY_INDEX, only), \
90 QT_SPUT (QT_ADJ(sp), QT_USER_INDEX, userf), \
91 QT_SPUT (QT_ADJ(sp), QT_ARGT_INDEX, pt), \
92 QT_SPUT (QT_ADJ(sp), QT_ARGU_INDEX, pu), \
98 /* Push arguments for the varargs case.
99 Has to be a function call because initialization is an expression
100 and we need to loop to copy nbytes of stuff on to the stack.
101 But that's probably OK, it's not terribly cheap, anyway. */
103 #ifdef QT_VARGS_DEFAULT
105 #define QT_VARGS_MD0(sp, vasize) (sp)
108 #define QT_VARGS_MD1(sp) do { ; } while (0)
112 #error "Need base stack size for varargs functions."
115 /* Sometimes the stack pointer needs to munged a bit when storing
116 the list of arguments. */
117 #ifndef QT_VARGS_ADJUST
118 #define QT_VARGS_ADJUST(sp) (sp)
121 /* All things are put on the stack relative to the final value of
122 the stack pointer. */
124 #define QT_VADJ(sp) (((char *)sp) - QT_VSTKBASE)
126 #define QT_VADJ(sp) (((char *)sp) + QT_VSTKBASE)
129 extern qt_t
*qt_vargs (qt_t
*sp
, int nbytes
, void *vargs
,
130 void *pt
, qt_startup_t
*startup
,
131 qt_vuserf_t
*vuserf
, qt_cleanup_t
*cleanup
);
134 #define QT_VARGS(sp, nbytes, vargs, pt, startup, vuserf, cleanup) \
135 (qt_vargs (sp, nbytes, vargs, pt, startup, vuserf, cleanup))
141 /* Save the state of the thread and call the helper function
142 using the stack of the new thread. */
143 typedef void *(qt_helper_t
)(qt_t
*old
, void *a0
, void *a1
);
144 typedef void *(qt_block_t
)(qt_helper_t
*helper
, void *a0
, void *a1
,
147 /* Rearrange the parameters so that things passed to the helper
148 function are already in the right argument registers. */
150 extern void qt_abort (qt_helper_t
*h
, void *a0
, void *a1
, qt_t
*newthread
);
151 /* The following does, technically, `return' a value, but the
152 user had better not rely on it, since the function never
154 #define QT_ABORT(h, a0, a1, newthread) \
155 do { qt_abort (h, a0, a1, newthread); } while (0)
159 extern void *qt_block (qt_helper_t
*h
, void *a0
, void *a1
,
161 #define QT_BLOCK(h, a0, a1, newthread) \
162 (qt_block (h, a0, a1, newthread))
166 extern void *qt_blocki (qt_helper_t
*h
, void *a0
, void *a1
,
168 #define QT_BLOCKI(h, a0, a1, newthread) \
169 (qt_blocki (h, a0, a1, newthread))
173 } /* Match `extern "C" {' at top. */
176 #endif /* ndef QT_H */