libPhenom高性能C语言并发编程框架

libPhenom 是 Facebook 发布的一个C语言事件框架,用于构建高性能和高可扩展的系统。支持多线程,提供内存管理和常用数据结构(hash tables, lists, queues),json处理。

俗话说的好:

熟读代码3百变,不会淫诗也会变。

小伙子,你会淫不?不会的话,你变一个来试试啊~

“闲着蛋疼”的我,于是下来研究研究,打算变一个(宿舍dota2的气氛太浓烈了,我也不容易啊)

听说

dota毁三代,摄影毁一生

当我拿起单反的时候,已经把一生毁了,我不能把三代都毁了啊!所以,你撸你的Dota,我撸我的代码。

好了,不扯淡了,开始......

###安装 从github里获取facebook的源码

git clone https://github.com/facebook/libphenom.git

###软件依赖

编译时,需要依赖下面的开发包(mac的终端安装命令)

  • pkg-config:brew install pkg-config

  • concurrencykit: brew install concurrencykit

  • libssl-dev:brew install libssl-dev 或者

  • openssl-devel :brew install openssl-devel

  • autoconf:brew install autoconf

  • automake:brew install automake

  • libtool:brew install libtool

类似安装截图: 11 看到没,我终端上能显示个啤酒的图标哦,提示我,得喝啤酒解困啊。 22

###编译并安装libphenom

$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install

###详细编译安装图文

  • $ ./autogen.sh

autogen.sh

  • $ ./configure

configure

  • $ make

make

  • $ make check

make check

  • $ sudo make install

install

###开始使用 编译完毕,即可快速使用此开发库,demo案例如下:

// Always include phenom/defs.h first to correctly set up the compilation env
#include "phenom/defs.h"
#include "phenom/configuration.h"
#include "phenom/job.h"
#include "phenom/log.h"
#include "phenom/sysutil.h"

int main(int argc, char **argv)
{
  // Must be called prior to calling any other phenom functions
  ph_library_init();
  // Optional config file for tuning internals
  ph_config_load_config_file("/path/to/my/config.json");
  // Enable the non-blocking IO manager
  ph_nbio_init(0);

  // Do stuff here to register client/server stuff.
  // This enables a very simple request/response console
  // that allows you to run diagnostic commands:
  // `echo memory | nc -UC /tmp/phenom-debug-console`
  // (on BSD systems, use `nc -Uc`!)
  // The code behind this is in
  // https://github.com/facebook/libphenom/blob/master/corelib/debug_console.c
  ph_debug_console_start("/tmp/phenom-debug-console");

  // Run
  ph_sched_run();

  return 0;
}

###编译运行此demo gcc -O2 main.c pkg-config libphenom --cflags --libs

编译完成,产生a.out文件。

更多的使用,有待我进一步去理解,源码面前了无秘密,加油。 有对此文档研究的朋友,可以加个一起学习!

具体的代码介绍文档: libPhenom

转载于:https://my.oschina.net/ittomato/blog/374197

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值