Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rinhizakura/cocoro
cocoro aims to provide friendly interface of coroutine functionality
https://github.com/rinhizakura/cocoro
async async-await await c coroutines
Last synced: about 10 hours ago
JSON representation
cocoro aims to provide friendly interface of coroutine functionality
- Host: GitHub
- URL: https://github.com/rinhizakura/cocoro
- Owner: RinHizakura
- Created: 2021-10-01T10:25:49.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-06T05:40:46.000Z (about 3 years ago)
- Last Synced: 2024-11-07T06:26:22.908Z (about 2 months ago)
- Topics: async, async-await, await, c, coroutines
- Language: C
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cocoro
This project is mainly designed for my personal use. It aims to provide friendly interface
of coroutine functionality, which is originated from
[cserv](https://github.com/sysprog21/cserv) and work in process now.Note: Only `x86_64` architecture is supported now.
## API
The APIs to build the basic environment for couroutine are listed in following:
Function | Description
-----------------------------|------------------
*cocoro_init()* | Initialize the basic environment for cocoro
*cocoro_add_task(func, args)*| Register a function 'func' with its arguments 'args' in cocoro
*cocoro_set_nonblock(fd)* | Set the file descriptor to nonblocking I/O mode
*cocoro_run()* | Start cocoro to schedule and run the registered coroutines
*cocoro_exit()* | Reclaim the memory resource of cocoroThe APIs to perform coroutine operation in coroutine context are listed in following:
Function | Description
-----------------------------|------------------
*cocoro_yield()* | Yield the CPU resource to other coroutines
*cocoro_await(cond)* | Yield the CPU resource to other coroutines until `cond == true`We also provide `cocoro_read`, `cocoro_write`, `cocoro_recv`, and `cocoro_send` now for
non-blocking system call in the coroutines. The input file descriptor for these system
call should be set by `cocoro_set_nonblock` in advance, otherwise the behavior is not
guaranteed. Note that coroutines who use these APIs would have higher priority to be
waked up than the coroutines which use `cocoro_yield` or `cocoro_await` directly.## TODO List
- [x] await and yield implementation
- [x] Event driven scheduler
- [ ] Nested coroutine
- [ ] ...more feature / general purpose interface## Reference
* [cserv](https://github.com/sysprog21/cserv)
* [async.h](https://github.com/naasking/async.h)
* [concurrent-programs/tinync](https://github.com/sysprog21/concurrent-programs/tree/master/tinync)