Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save [stack, sp]function _save_stack疑问 #9

Open
Qinch opened this issue Oct 21, 2018 · 2 comments
Open

save [stack, sp]function _save_stack疑问 #9

Qinch opened this issue Oct 21, 2018 · 2 comments

Comments

@Qinch
Copy link

Qinch commented Oct 21, 2018

_save_stack函数中dummy变量定义在coroutine_yield是不是更好?

static void
_save_stack(struct coroutine *C, char *top, char *bottom) {
       //top:stack bottom:sp
	assert(top - bottom <= STACK_SIZE);
	if (C->cap < top - bottom) {
		free(C->stack);
		C->cap = top-bottom;
		C->stack = malloc(C->cap);
	}
	C->size = top - bottom;
	memcpy(C->stack, bottom, C->size);
}

void
coroutine_yield(struct schedule * S) {
	int id = S->running;
	assert(id >= 0);
	struct coroutine * C = S->co[id];
	assert((char *)&C > S->stack);
	char dummy = 0;
	_save_stack(C,S->stack + STACK_SIZE, &dummy);
	C->status = COROUTINE_SUSPEND;
	S->running = -1;
	swapcontext(&C->ctx , &S->main);
}
@Qinch Qinch changed the title save [bp, sp]function _save_stack疑问 save [stack, sp]function _save_stack疑问 Oct 21, 2018
@qingdujun
Copy link

这样会多压一个,函数call栈

@Prince-Hervoet
Copy link

感觉这里可以适当采用宏函数去展开,抵消掉函数调用压入的返回地址等的空间

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants