Skip to content

aetherisa/aeco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aeco

A studying-purpose coroutine implementation based on C11/x86-64 assembly

Features

  • Create/destroy coroutines.
  • Resume/yield to switch between caller/callee.
  • Passing argument to coroutine and also get return value from it.

Example

#include "aeco.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

void *counter(void *cnt)
{
	for (size_t i = 0; i < (size_t)cnt; ++i)
		printf("%ld\n", i);
	co_yield();
	for (size_t i = (size_t)cnt; i >= 1; --i)
		printf("%ld\n", i);

	return (void *)0;
}

int main(void)
{
	uintptr_t co = co_new(counter, (void *)2);

	while (!co_is_dead(co))
		co_resume(co);
	co_delete(co);
}

TODO

  • Add nested resume support.
  • Add multi-thread support.
  • Write actual unit tests.

About

A coroutine implementation based on C11/x86-64 assembly

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Contributors