`
mryufeng
  • 浏览: 982356 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Adding my own BIF

阅读更多
原文地址:http://www.trapexit.org/Adding_my_own_BIF


Adding my own BIF
From Erlang Community
caveat

unless you really know what you're doing, you'll be better off using a linked-in driver or a port.
steps

    1. run configure
    2. add your bifs to erts/emulator/beam/bif.tab

bif re:grep/2 bif re:compile/1

    3. create a C file

erts/emulator/beam/erl_bif_re.c

    4. add your C file to erts/emulator/<arch>/Makefile

RUN_OBJS = $(OBJDIR)/erl_bif_re.o \

    5. implement your bifs by stealing bits from existing erl_bif_*.c files

BIF_RETTYPE re_grep_2(BIF_ALIST_2){
  Eterm result;
  result = magic_function();
  BIF_RET(result);
}

    6. run make; make install

notes

    * steps 0-3 need only be done once.

    * note that if you add

bif re:grep/2

to bif.tab there should be a erl_bif_re.c that implements

BIF_RETTYPE re_grep_2(BIF_ALIST_2);

为什么要用bif呢? bif比驱动或者port的好处是 bif支持trap, 所以能够让cpu计算平均在各个进程分配,这个网络程序很重要的一个要求. 没有这个特性一个费时的操作会把整个调度器拖死,其他的进程就谈不上什么响应了。下篇文章教你如何写带trap功能的bif。

分享到:
评论
1 楼 mryufeng 2009-07-28  
trap某种意义上讲就是erlang的coroutine, 因为erlang的调度是抢占式的, 同时又给程序员提供了协助式的, 真是贴心哦。。。

相关推荐

    Adding New Hardware for Avaya

    Adding New Hardware for Avaya

    LES Mean Value Theorem and Adding an Integrator

    局部指数稳定性定理及证明、中值定理、加权积分器详细介绍

    A tutorial on adding columns to Explorer’s details view via

    标题 "A tutorial on adding columns to Explorer’s details view via" 是一篇关于如何通过列处理程序外壳扩展在Windows资源管理器(Explorer)的详细视图中添加自定义列的教程。这通常涉及到增强Windows操作系统中...

    adding-white-noise-to-fixed-snr.zip_NOISE_adding noise_snr_white

    Adding white noise to a signal with fixed SNR

    Adding Reversed Numbers

    #include "stdafx.h" #include "iostream" #include "fstream" #include "algorithm" #include "string" #include "vector" #include "cmath" using namespace std; int main(int argc, char* argv[]) ...

    Taking the pain out of adding a horizontal scrollbar to a li

    标题“Taking the pain out of adding a horizontal scrollbar to a listbox”指向的就是这样一个问题:如何优雅地为列表框添加水平滚动条,以提升用户体验。这里我们将详细探讨这个主题,并提供一些实践技巧。 ...

    lua 5.3.5 windows预编译exe/dll文件 lua5.3.5.win.zip

    adding: lua5.3.5-x86/lua.exe (in=14336) (out=7311) (deflated 49%) adding: lua5.3.5-x86/lua.o (in=24873) (out=9654) (deflated 61%) adding: lua5.3.5-x86/lua5.3.5-static.lib (in=662596) (out=244441) ...

    Adding Password Management to Your Templates(cloudstack)

    Adding Password Management to Your Templates(cloudstack)

    kettle 5.0.1

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 04

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 08

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 02

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 07

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 06

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 09

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    kettle 5.0.1 03

    Simple plug-in architecture for adding your own custom extensions Enterprise Data Integration server providing security integration, scheduling, and robust content management including full revision ...

    下拉菜单 Adding Drop down navigation

    "Adding Drop down navigation"是关于如何在Android应用程序中实现这种功能的一个主题,通常与Action Bar紧密相关。Action Bar是Android系统中一个重要的界面组件,它位于应用顶部,用于显示应用的标识、标题以及...

    adding ajax.chm

    chm格式的,非常好的一本书,大家可以收藏!!有价值啊!!

    Adding Classifications to Web Services.doc

    "Adding Classifications to Web Services"这个过程涉及到将Web服务在SAP NetWeaver Developer Studio中进行分类,以符合SAP的分类系统。 分类(Classifications)的主要目的是让Web服务在服务注册表(Services ...

Global site tag (gtag.js) - Google Analytics