int swapcontext(ucontext_t *oucp, ucontext_t *ucp);
int getcontext(ucontext_t *ucp);
int setcontext(const ucontext_t *ucp);
If my understanding is correct, swapcontext is equivalent to first calling getcontext on oucp and then calling setcontext on ucp. I am trying to see how I could implement swapcontext with getcontext and setcontext.
int swapcontext(ucontext_t *oucp, ucontext_t *ucp)
{
getcontext(oucp);
setcontext(ucp);
}
The problem is that the context of oucp is at the wrong line, I want to call getcontext in a way such that the next line is the line after setcontext(ucp). However, setcontext does not return so I cannot do that. Moreover, if I implement swapcontext in this manner, if I pass the same arguments to oucp and ucp I will be stuck.
How would one implement swapcontext using these two functions? Or is it not possible?