X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/baca54322c66983205edecd2ebb00d997878be50..270869139db617e29a35bb9ded41087bb702f9ac:/lunaix-os/includes/lunaix/switch.h diff --git a/lunaix-os/includes/lunaix/switch.h b/lunaix-os/includes/lunaix/switch.h new file mode 100644 index 0000000..4daca4d --- /dev/null +++ b/lunaix-os/includes/lunaix/switch.h @@ -0,0 +1,60 @@ +#ifndef __LUNAIX_SWITCH_H +#define __LUNAIX_SWITCH_H + +#define SWITCH_MODE_NORMAL 0 +#define SWITCH_MODE_FAST 1 +#define SWITCH_MODE_GIVEUP 2 + +#ifndef __ASM__ + +#include + +struct signpost_result +{ + int mode; + ptr_t stack; +}; + +/** + * @brief Decide how current thread should perform the context switch + * back to it's previously saved context. + * + * Return a user stack pointer perform a temporary fast redirected + * context switch. + * No redirection is required if such pointer is null. + * + * This function might never return if the decision is made to give up + * this switching. + * + * NOTE: This function might have side effects, it can only be + * called within the twilight zone of context restore. (after entering + * do_switch and before returning from exception) + * + * @return ptr_t + */ +ptr_t +switch_signposting(); + +static inline void +redirect_switch(struct signpost_result* res, ptr_t stack) +{ + res->mode = SWITCH_MODE_FAST; + res->stack = stack; +} + +static inline void +continue_switch(struct signpost_result* res) +{ + res->mode = SWITCH_MODE_NORMAL; + res->stack = 0; +} + +static inline void +giveup_switch(struct signpost_result* res) +{ + res->mode = SWITCH_MODE_GIVEUP; + res->stack = 0; +} + +#endif +#endif /* __LUNAIX_SWITCH_H */