9 Star 34 Fork 10

linuxmail / lib-zo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

lib-zo

一个 C 协程库

本协程库是从 https://gitee.com/linuxmail/lib-zc 抽出来的, 可单独使用

帮助文档 https://gitee.com/linuxmail/lib-zc/blob/master/doc/coroutine.md

感谢

本协程库的实现参考了 libco, libgo, nodejs 的实现

介绍

支持文件IO类协程化(如mkdir, getdents等)

支持协程条件, 协程锁

慢操作协程化

支持sleep

可以禁用 UDP 协程切换

部分支持dns协议

支持静态编译

睡眠

支持sleep

不支持usleep和nanosleep

毫秒睡眠请用 void zcoroutine_sleep_millisecond(int milliseconds);

支持的文件io

可开启支持文件io在其他线程池工作

open, openat, close, read, readv, write, writev, lseek,

fdatasync, fsync, rename, truncate, ftruncate,

rmdir, mkdir, getdents,

stat, fstat, lstat, link, symlink, readlink, unlink,

chmod, fchmod, chown, fchown, lchown, utime, utimes,

支持慢(阻塞式)操作

慢操作可以在其他线程池工作

dns协议

本框架下, 大部分 glibc 版本的 DNS 解析会有 BUG, 但至少版本 2.12 没问题

如果有问题, 建议:

  • 如果需要查询常用域名的 IP 地址, 可以写到 hosts 文件
  • 可以考虑 "慢操作协程化"
  • 可以禁用 53 端口(既 DNS)的 UDP 协程切换

可以禁用 UDP 协程切换

可以禁用 UDP 协程切换, 可以禁用 53 端口(既 DNS)的 UDP 协程切换

源码目录

coroutine.c coroutine.h 是源码

*_test.c 是例子

编译

make

得到

libzc_coroutine.a

使用

gcc your_code.c ./libzc_coroutine.a

MIT License Copyright (c) 张岩. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

简介

C协程库, 单文件易于迁移. 支持文件IO类协程化(如mkdir, getdents等) 支持协程条件, 协程锁 慢操作协程支持 展开 收起
C 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/linuxmail/lib-zo.git
git@gitee.com:linuxmail/lib-zo.git
linuxmail
lib-zo
lib-zo
master

搜索帮助