Skip to content
libco is a coroutine library which is widely used in wechat back-end service. It has been running on tens of thousands of machines since 2013.
C++ C Makefile Assembly CMake
Branch: master
Clone or download
leiffyli Merge pull request #124 from anonymalias/co_free_leak
fix co_free memory leak and add co_reset interface
Latest commit 03ba1a4 Sep 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore update Oct 19, 2016
CMakeLists.txt fix undefined reference to dlsym Jun 16, 2017
LICENSE.txt libco Oct 12, 2016
Makefile add OS decetion Jul 1, 2017
README.md PaxosStore open-source coming soon.. Aug 10, 2017
co.mk port to FreeBSD Jul 1, 2017
co_closure.h get actual param size when input param is zero Jun 5, 2017
co_epoll.cpp port to FreeBSD Jul 1, 2017
co_epoll.h port to FreeBSD Jul 1, 2017
co_hook_sys_call.cpp fix: fix hook poll bug for curl post request on the same fd Feb 18, 2019
co_routine.cpp Merge pull request #124 from anonymalias/co_free_leak Sep 2, 2019
co_routine.h 1. fix co_free memory leak: issue:71 Jan 20, 2018
co_routine_inner.h fix typo: ocupy_co -> occupy_co Apr 6, 2017
co_routine_specific.h update Oct 19, 2016
coctx.cpp update Oct 19, 2016
coctx.h libco Oct 12, 2016
coctx_swap.S
example_closure.cpp update Oct 19, 2016
example_cond.cpp update Oct 19, 2016
example_copystack.cpp fix compile on mac; Jan 23, 2017
example_echocli.cpp libco Oct 12, 2016
example_echosvr.cpp Update example_echosvr.cpp Nov 21, 2018
example_poll.cpp fixed #107 Dec 19, 2018
example_setenv.cpp update Oct 19, 2016
example_specific.cpp update Oct 19, 2016
example_thread.cpp libco Oct 12, 2016

README.md

Libco

Libco is a c/c++ coroutine library that is widely used in WeChat services. It has been running on tens of thousands of machines since 2013.

Author: sunnyxu(sunnyxu@tencent.com), leiffyli(leiffyli@tencent.com), dengoswei@gmail.com(dengoswei@tencent.com), sarlmolchen(sarlmolchen@tencent.com)

By linking with libco, you can easily transform synchronous back-end service into coroutine service. The coroutine service will provide out-standing concurrency compare to multi-thread approach. With the system hook, You can easily coding in synchronous way but asynchronous executed.

You can also use co_create/co_resume/co_yield interfaces to create asynchronous back-end service. These interface will give you more control of coroutines.

By libco copy-stack mode, you can easily build a back-end service support tens of millions of tcp connection.


简介

libco是微信后台大规模使用的c/c++协程库,2013年至今稳定运行在微信后台的数万台机器上。

libco通过仅有的几个函数接口 co_create/co_resume/co_yield 再配合 co_poll,可以支持同步或者异步的写法,如线程库一样轻松。同时库里面提供了socket族函数的hook,使得后台逻辑服务几乎不用修改逻辑代码就可以完成异步化改造。

作者: sunnyxu(sunnyxu@tencent.com), leiffyli(leiffyli@tencent.com), dengoswei@gmail.com(dengoswei@tencent.com), sarlmolchen(sarlmolchen@tencent.com)

PS: 近期将开源PaxosStore,敬请期待。

libco的特性

  • 无需侵入业务逻辑,把多进程、多线程服务改造成协程服务,并发能力得到百倍提升;
  • 支持CGI框架,轻松构建web服务(New);
  • 支持gethostbyname、mysqlclient、ssl等常用第三库(New);
  • 可选的共享栈模式,单机轻松接入千万连接(New);
  • 完善简洁的协程编程接口
  • 类pthread接口设计,通过co_create、co_resume等简单清晰接口即可完成协程的创建与恢复;
  • __thread的协程私有变量、协程间通信的协程信号量co_signal (New);
  • 语言级别的lambda实现,结合协程原地编写并执行后台异步任务 (New);
  • 基于epoll/kqueue实现的小而轻的网络框架,基于时间轮盘实现的高性能定时器;

Build

$ cd /path/to/libco
$ make

or use cmake

$ cd /path/to/libco
$ mkdir build
$ cd build
$ cmake ..
$ make
You can’t perform that action at this time.