risent / c-coroutines Goto Github PK
View Code? Open in Web Editor NEWThis project forked from spc476/c-coroutines
Coroutines for C.
License: GNU Lesser General Public License v3.0
This project forked from spc476/c-coroutines
Coroutines for C.
License: GNU Lesser General Public License v3.0
An Implementaion of Coroutines for C This is not based on setjmp()/longjmp() or ucontext.h but is a ground-up implementation of coroutines for C. This involves the use of assembly to ensure the coroutine stack intialization and stack switching. The code may look simple, but it wasn't simple to write. but it is straightforward (mostly). There are two example programs, test and iter. test just runs some simple tests while iter will create a tree from lines of input (either stdin or a file), then use a coroutine to iterate through the tree. API: extern int coroutine_create( coroutine__s **pco, size_t stsize, uintptr_t (*fun)(coroutine__s *,uintptr_t) ); Creates a coroutine context, which will include a stack of stsize; if stsize is 0, a default size is automatically provided (which *should* be big enough for most uses). This will return 0 on success, non-zero on failure. The function passed in takes two parameters, a coroutine__s * (which will refer to its own context when called) and a uintptr_t (an integer quantity large enough to hold a pointer). It can return values back via coroutine_yield() or simply returning a value. Once the function returns, it will not be called on subsequent calls to coroutine_yield() (see coroutine_yield() for more information). extern void coroutine_init( coroutine__s *co, uintptr_t (*fun)(coroutine__s *,uintptr_t), void *stack ); Initializes the coroutine stack so that the first call to coroutine_yield() will call the given function. This is not meant to be called from user code but is rather an internal method to coroutine_create(). The stack paramter should point to the stack top (highest memory address on most systems). extern uintptr_t coroutine_yield( coroutine__s *co, uintptr_t data ); Passes control to the coroutine, passing data to it. This call is symetrical, being used on both sides to pass control back and forth. Once the coroutine's main function does an actual return, further calls to coroutine_yield() to said coroutine will immediately yield back, returning data directly. NOTE: setjmp()/longjmp() will *NOT* work across coroutine stacks. setjmp()/longjmp() will work within a coroutine stack. extern int coroutine_free( coroutine__s *co ); Free up the memory used for co and its stack. No other resources are reclaimed (like open files). calling coroutine_free() on a coroutine currently running is undefined (if you are lucky, the program will crash immediate). The coroutine need not be finished running when this is called.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.