Skip to content
/ FUNK Public

a c continuation library inspired by Adam Dunkel's ProtoThread.

License

Notifications You must be signed in to change notification settings

matianfu/FUNK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FUNK

A C continuation implementation inspired by Adam Dunkels' ProtoThread.

Only 7 C macros and 1 struct definition; less than 100 lines of code.

Simple yet POWERFUL.

Now you can write a coroutine (generator, to be exact) in the following way, quick, simple, and in a natural way.

Enjoy the power of YIELD();

Continuation* add(Continuation* co,
    int a, int b, int * ret)
{
  struct timespec now;
  VAR_BEGIN
    struct timespec start;
  VAR_END

  if (!this || a < 0 || b < 0) { *ret = -1; EXIT(); }
  if (KILL_SIGNALLE()) EXIT();

  clock_gettime(CLOCK_REALTIME, &this->start);
  while(1)
  {
    clock_gettime(CLOCK_REALTIME, &now);
    if ((now.tv_sec - this->start.tv_sec) > 1)
      break;
    YIELD();
  }
  *ret = a + b;
  EXIT();
}

About

a c continuation library inspired by Adam Dunkel's ProtoThread.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages