使用emacs的etags阅读源代码

在阅读代码的时候,经常需要在文件间,函数间跳转,跳转到某个函数,某个变量,这时候可以使用ctags方式实现这个功能.

emacs自带一个叫etags的工具程序,用来生成一个给emacs用的TAGS索引文件,在emacs中实现函数文件间跳转,搜索的功能.

1. 使用etags 创建TAGS索引文件.
搜索当前目录及子目录下.c,.cpp,.h等文件,并生成TAGS文件,放在当前目录下.
find . -type f -iname "*.[ch]*" | etags -

2. 使用M-.键查找符号表
`M-.’ (‘find-tag’) – find a tag, that is, use the Tags file to look up a definition
`M-*’ (‘pop-tag-mark’) – jump back
‘tags-search’ – regexp-search through the source files indexed by a tags file (a bit like ‘grep’)
‘tags-query-replace’ – query-replace through the source files indexed by a tags file
`M-,’ (‘tags-loop-continue’) – resume ‘tags-search’ or ‘tags-query-replace’ starting at point in a source file
‘tags-apropos’ – list all tags in a tags file that match a regexp
‘list-tags’ – list all tags defined in a source file

其中比较重要的两个命令,M-. 查找, M-*返回

3. 同时使用多个TAGS符号表文件

libdispatch 来自apple的开源多线程编程库

这是apple在Snow Leopard中引入的一个新的特性,现在已经开源,主要实现对多线程编程的封装,简化多线程编程的复杂度,提高多纯种程序的稳定性。
libdispatch使用apache license 2开源协议发布。

这个库是针对apple系统编写,目前还不能用在其他linux/unix等posix系统中。但是由于它良好的包装风格及思想理念,目前许多的linux/unix开发人员已经开始了这个库的移植工作。在不久之后,我们就可以在常见的linux/unix系统中看到它了。

目前freebsd已经完成了libdispatch的大部分移植工作。

项目地址:http://libdispatch.macosforge.org/

要在nullfxp中嵌入一种脚本,使用什么呢

准备在nullfxp中嵌入一种脚本语言,能够为用户做一些插件化、自动化的任务,应该使用哪种呢?
目前准备了三种脚本,都有各自的优点,或者是个人爱好,暂且列举出来做个比较:
lisp语言:
lua语言:
qtscript语言:

这三种都有应用,其中lisp用于autocad,然后称其为autolisp.lisp还用于emacs,然后称其为elisp.其他的暂时还不知道。
lua据说大量用于一些游戏中,玩游戏不多,列举不出来。
qtscript被用于amarok,做为插件来使用。qtscript还是qt库自带的一个比较完整的库,在以qt库为基础的nullfxp上集成非常方便。另外qtscript是一种类比较接近javascript的脚本语言,好象是scma解析引擎的一个子集。

Android马上就要支持Qt了

in

真是个好消息,因为google Android在以前一直都拿一种不可能的态度对待Qt, 终于有变化了。

这次的主要变化入情发生在 Android 1.6上,对Native C/C++的支持进一步加强,不是照也Qt去的也差不多了。

http://www.kdedevelopers.org/node/4070

epoll的实现原理

发信人: luohandsome (重生|begin from zero|脚踏实地), 板面: LinuxDev
标 题: [yc]读核感悟-文件读写-epoll的实现原理
发信站: 飘渺水云间 (Mon Aug 25 14:18:34 2008), 转信


1 功能介绍
epoll与select/poll不同的一点是,它是由一组系统调用组成。
int epoll_create(int size);
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
int epoll_wait(int epfd, struct epoll_event *events,
int maxevents, int timeout);
epoll相关系统调用是在Linux 2.5.44开始引入的。该系统调用针对传统的selec
t/poll系统调用的不足,设计上作了很大的改动。select/poll的缺点在于:
1.每次调用时要重复地从用户态读入参数。
2.每次调用时要重复地扫描文件描述符。
3.每次在调用开始时,要把当前进程放入各个文件描述符的等待队列。在调用结
束后,又把进程从各个等待队列中删除。
在实际应用中,select/poll监视的文件描述符可能会非常多,如果每次只是返回
一小部分,那么,这种情况下select/poll显得不够高效。epoll的设计思路,是把s
elect/poll单个的操作拆分为1个epoll_create+多个epoll_ctrl+一个wait。此外,
内核针对epoll操作添加了一个文件系统”eventpollfs”,每一个或者多个要监视的
文件描述符都有一个对应的eventpollfs文件系统的inode节点,主要信息保存在eve
ntpoll结构体中。而被监视的文件的重要信息则保存在epitem结构体中。所以他们
是一对多的关系。
由于在执行epoll_create和epoll_ctrl时,已经把用户态的信息保存到内核态了
,所以之后即使反复地调用epoll_wait,也不会重复地拷贝参数,扫描文件描述符,
反复地把当前进程放入/放出等待队列。这样就避免了以上的三个缺点。
接下去看看它们的实现:
2 关键结构体:
/* Wrapper struct used by poll queueing */
struct ep_pqueue {
poll_table pt;
struct epitem *epi;
};
这个结构体类似于select/poll中的struct poll_wqueues。由于epoll需要在内核
态保存大量信息,所以光光一个回调函数指针已经不能满足要求,所以在这里引入了
一个新的结构体struct epitem。
/*
* Each file descriptor added to the eventpoll interface will
* have an entry of this type linked to the hash.
*/
struct epitem {
/* RB-Tree node used to link this structure to the eventpoll rb
-tree */
struct rb_node rbn;
红黑树,用来保存eventpoll
/* List header used to link this structure to the eventpoll rea
dy list */
struct list_head rdllink;
双向链表,用来保存已经完成的eventpoll
/* The file descriptor information this item refers to */
struct epoll_filefd ffd;
这个结构体对应的被监听的文件描述符信息
/* Number of active wait queue attached to poll operations */
int nwait;
poll操作中事件的个数
/* List containing poll wait queues */
struct list_head pwqlist;
双向链表,保存着被监视文件的等待队列,功能类似于select/poll中的poll_tab
le
/* The "container" of this item */
struct eventpoll *ep;
指向eventpoll,多个epitem对应一个eventpoll
/* The structure that describe the interested events and the so
urce fd */
struct epoll_event event;
记录发生的事件和对应的fd
/*
* Used to keep track of the usage count of the structure. This
avoids

* that the structure will desappear from underneath our proces
sing.
*/
atomic_t usecnt;
引用计数
/* List header used to link this item to the "struct file" item
s list */
struct list_head fllink;
双向链表,用来链接被监视的文件描述符对应的struct file。因为file里有f_ep
_link,用来保存所有监视这个文件的epoll节点
/* List header used to link the item to the transfer list */
struct list_head txlink;
双向链表,用来保存传输队列
/*
* This is used during the collection/transfer of events to use
rspace
* to pin items empty events set.
*/
unsigned int revents;
文件描述符的状态,在收集和传输时用来锁住空的事件集合
};
该结构体用来保存与epoll节点关联的多个文件描述符,保存的方式是使用红黑树
实现的hash表。至于为什么要保存,下文有详细解释。它与被监听的文件描述符一一
对应。
struct eventpoll {
/* Protect the this structure access */
rwlock_t lock;
读写锁
/*
* This semaphore is used to ensure that files are not removed
* while epoll is using them. This is read-held during the even
t
* collection loop and it is write-held during the file cleanup
* path, the epoll file exit code and the ctl operations.
*/
struct rw_semaphore sem;
读写信号量
/* Wait queue used by sys_epoll_wait() */
wait_queue_head_t wq;
/* Wait queue used by file->poll() */
wait_queue_head_t poll_wait;
/* List of ready file descriptors */
struct list_head rdllist;
已经完成的操作事件的队列。
/* RB-Tree root used to store monitored fd structs */
struct rb_root rbr;
保存epoll监视的文件描述符
};
这个结构体保存了epoll文件描述符的扩展信息,它被保存在file结构体的priva
te_data中。它与epoll文件节点一一对应。通常一个epoll文件节点对应多个被监视
的文件描述符。所以一个eventpoll结构体会对应多个epitem结构体。
那么,epoll中的等待事件放在哪里呢?见下面
/* Wait structure used by the poll hooks */
struct eppoll_entry {
/* List header used to link this structure to the "struct epite
m" */
struct list_head llink;
/* The "base" pointer is set to the container "struct epitem" *
/
void *base;
/*
* Wait queue item that will be linked to the target file wait
* queue head.
*/
wait_queue_t wait;
/* The wait queue head that linked the "wait" wait queue item *
/
wait_queue_head_t *whead;
};
与select/poll的struct poll_table_entry相比,epoll的表示等待队列节点的结
构体只是稍有不同,与struct poll_table_entry比较一下。
struct poll_table_entry {
struct file * filp;
wait_queue_t wait;
wait_queue_head_t * wait_address;
};
由于epitem对应一个被监视的文件,所以通过base可以方便地得到被监视的文件
信息。又因为一个文件可能有多个事件发生,所以用llink链接这些事件。
3 epoll_create的实现
epoll_create()的功能是创建一个eventpollfs文件系统的inode节点。具体由ep
_getfd()完成。ep_getfd()先调用ep_eventpoll_inode()创建一个inode节点,然后
调用d_alloc()为inode分配一个dentry。最后把file,dentry,inode三者关联起来。
在执行了ep_getfd()之后,它又调用了ep_file_init(),分配了eventpoll结构体
,并把eventpoll的指针赋给file结构体,这样eventpoll就与file结构体关联起来了

需要注意的是epoll_create()的参数size实际上只是起参考作用,只要它不小于
等于0,就并不限制这个epoll inode关联的文件描述符数量。
4 epoll_ctl的实现
epoll_ctl的功能是实现一系列操作,如把文件与eventpollfs文件系统的inode节
点关联起来。这里要介绍一下eventpoll结构体,它保存在file->f_private中,记录
了eventpollfs文件系统的inode节点的重要信息,其中成员rbr保存了该epoll文件节
点监视的所有文件描述符。组织的方式是一棵红黑树,这种结构体在查找节点时非常
高效。
首先它调用ep_find()从eventpoll中的红黑树获得epitem结构体。然后根据op参
数的不同而选择不同的操作。如果op为EPOLL_CTL_ADD,那么正常情况下epitem是不
可能在eventpoll的红黑树中找到的,所以调用ep_insert创建一个epitem结构体并插
入到对应的红黑树中。
ep_insert()首先分配一个epitem对象,对它初始化后,把它放入对应的红黑树。
此外,这个函数还要作一个操作,就是把当前进程放入对应文件操作的等待队列。这
一步是由下面的代码完成的。
init_poll_funcptr(&epq.pt, ep_ptable_queue_proc);

。。。
revents = tfile->f_op->poll(tfile, &epq.pt);
函数先调用init_poll_funcptr注册了一个回调函数 ep_ptable_queue_proc,这
个函数会在调用f_op->poll时被执行。该函数分配一个epoll等待队列结点eppoll_e
ntry:一方面把它挂到文件操作的等待队列中,另一方面把它挂到epitem的队列中
。此外,它还注册了一个等待队列的回调函数ep_poll_callback。当文件操作完成,
唤醒当前进程之前,会调用ep_poll_callback(),把eventpoll放到epitem的完成队
列中,并唤醒等待进程。
如果在执行f_op->poll以后,发现被监视的文件操作已经完成了,那么把它放在
完成队列中了,并立即把等待操作的那些进程唤醒。

5 epoll_wait的实现
epoll_wait的工作是等待文件操作完成并返回。
它的主体是ep_poll(),该函数在for循环中检查epitem中有没有已经完成的事件
,有的话就把结果返回。没有的话调用schedule_timeout()进入休眠,直到进程被再
度唤醒或者超时。
6 性能分析
epoll机制是针对select/poll的缺陷设计的。通过新引入的eventpollfs文件系统
,epoll把参数拷贝到内核态,在每次轮询时不会重复拷贝。通过把操作拆分为epol
l_create,epoll_ctl,epoll_wait,避免了重复地遍历要监视的文件描述符。此外,
由于调用epoll的进程被唤醒后,只要直接从epitem的完成队列中找出完成的事件,
找出完成事件的复杂度由O(N)降到了O(1)。
但是epoll的性能提高是有前提的,那就是监视的文件描述符非常多,而且每次完
成操作的文件非常少。所以,epoll能否显著提高效率,取决于实际的应用场景。这
方面需要进一步测试。

--

http://www.freecity.cn/agent/thread.do?id=LinuxDev-48b24eba-c4e53e6f2d89...

nullfxp 2.0.0 released

in

* 添加FTP协议文件传输(包括FXP协议)支持。

* 添加FTP<-->SFTP之间互传输功能。

* 提高SFTP协议传输速度。

* 修正会话窗口的Connect按钮无效的问题。

* 添加Mac OS X平台支持。

Gentoo Linux 10 LiveDVD正式发布

in

在gentoo官方已经给出了发布公告,DVD光盘下载等信息。

Gentoo Linux - Ten Years Compiling: 1999 - 2009

Posted on October 4, 2009
by Matthew Summers

gentoo

Happy Tenth Birthday, Gentoo!

Gentoo Linux is proud to announce the immediate availability of a new,
special edition LiveDVD
to celebrate this monumental occasion. The LiveDVD
features a superb list of packages, some of which are listed below.

  • System packages include: Linux Kernel 2.6.30 (with gentoo patches),
    Accessibility Support with Speakup 3.1.3, BASH 4.0, GLIBC 2.9, GCC 4.3.2.
    Binutils 2.18, Python 2.6.2, Perl 5.8.8, and more.
  • Desktop Environments and window managers include: KDE 4.3.1, GNOME
    2.26.3, Xfce 4.6.1, Enlightenment 0.16.8.15, Openbox 3.4.7.2, Fluxbox 1.1.1,
    TWM 1.0.4, and more.
  • Office, graphics, and productivity applications include: OpenOffice
    3.1.1, G/Vim 7.2.182, Abiword 2.6.4, GNUCash 2.2.9, Scribus 1.3.3.11, GIMP
    2.6.4, Inkscape 0.46, Blender 2.49a, XSane 0.996, and much more.
  • Web browsers include: Mozilla Firefox (Minefield) 3.5.3, Arora
    0.7.11, Opera 10.0, Epiphany 2.26.3, Galeon 2.0.4, Seamonkey 1.1.17, and
    other favorites.
  • Communication tools include: Pidgin 2.5.9, Quassel 0.5, Mozilla
    Thunderbird 2.0.23, Claws Mail 3.7.2, Ekiga 2.0.12, Qtwitter 0.7.1, irssi
    0.8.13, and many more.
  • Multimedia applications include: Amarok 2.1.1, MPlayer 1.0_rc4,
    DvdAuthor 0.6.14, LAME 3.98.2, FFMPEG 0.5_p19928, GNOME-MPlayer 0.9.7,
    SMPlayer 0.6.6, and several others.

The Gentoo-Ten LiveDVD is available in two flavors, a hybrid x86/x86_64
version, and an x86_64-only version. The livedvd-x86-amd64-32ul-10.0 will work on x86 or
x86_64. If your arch is x86, then boot with the default gentoo kernel. If
your arch is amd64 boot
with the gentoo64 kernel. This means you can boot a 64bit kernel and install a customized 64bit userland while using the provided 32bit userland. The livedvd-amd64-multilib-10.0 version is for x86_64 only.

Please select your architecture to be redirected to a mirror for download: x86
amd64

A FAQ is available to assist
you. We have also started a thread in our Forum. Please post
any bugs you encounter.

In addition, we have some exceptional new artwork from Ben
Stedman, and Gentoo Developer Alex Legler.

Thank you for your continued support,

Gentoo Linux Developers, The Gentoo Linux Foundation, and The Gentoo-Ten
Project

gentoo linux 10 周岁了

in

自gentoo发行版出世已经有10个年头了,最近官方也在为gentoo过生日。一个特大的生日礼物就是10周年liveDVD,正常邀请用户的测试,并给出了抓图及语言说明。

Gentoo 10 LiveDVD的包主要包括:
linux kernel 2.6.30, xorg 1.6, KDE 4.3.2, Gnome 2.26, XFCE 4.6.1, Mozilla Firefox 3.5.1, Openoffice 3.1.1等。

介绍地址:

http://linuxcrazy.com/?q=node/76

发行版Gentoo Linux 10.0 Test

in

Gentoo Linux是一套通用的、快捷的、完全免费的Linux发行,它面向开发人员和网络职业人员。与其他发行不同的是,Gentoo Linux拥有一套先进的包管理系统叫作Portage。在BSD ports的传统中,Portage是一套真正的自动导入系统,然而Gentoo里的Portage是用Python编写的,并具它有很多先进的特性,包括文件依赖、精细的包管理、OpenBSD风格的虚拟安装,安全卸载,系统框架文件、虚拟软件包、配置文件管理等等。

Matthew Summers has announced a testing release of Gentoo Linux 10.0, a special 10-year anniversary Gentoo live DVD: "In honor of Gentoo's 10th birthday, we are producing a new live DVD. We need you to test it on as many x86 and x86_64 machines as you can and post bugs. The x86-x86_64 live DVD will work on x86 or x86_64 processors. If your architecture is x86 boot with the default 'gentoo'. If your architecture is amd64 boot with gentoo64. The AMD64 live DVD is for amd64 only. So give us a hand by testing like crazy and posting bugs and we'll have the greatest live DVD ever." The very brief release announcement contains no technical information, but the live DVD comes with Linux kernel 2.6.30, glibc 2.9 and GCC 4.3.2, and boots into KDE 4.3.1 by default (GNOME 2.24 and Xfce 4.6.1 are also available). It can be installed to a hard disk. Interested testers can download the DVD images from here: livedvd-x86-x86_64-10.0.iso (1,849MB, MD5), livedvd-x86-amd64-10.0.iso (1,899MB, MD5).

在x86上成功使用gentoo系统上安装的grub2启动 Mac OS X Leopard 10.5.7

机器: thinkpad w500
环境:
/dev/sda1 gentoo-x86_64
/dev/sda2 iAKTKOS v7 10.5.7

grub2 安装在MBR, 在gentoo上安装grub-9999.ebuild, 修改grub-9999.ebuil, 添加configure参数--disable-werror,避免编译因警告停止编译安装。
由于grub2默认不支持efiemu,修改grub-9999.ebuild, 将--disable-efiemu改为--enable-efiemu。

emerge -v grub

安装完grub后,使用grub-install /dev/sda将grub2安装在MBR中。

mac os x菜单如下:

menuentry "Mac OS X" {
set root=(hd0,2)
insmod efiemu
insmod video
insmod vbe
gfxmode="1024x768x32"
xnu_kernel /mach_kernel rd=disk0s2
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
xnu_mkext /System/Library/Extensions.mkext
else
xnu_kextdir /System/Library/Extensions
fi
}

重启即可进入Leopard了。
现在启动Mac OS X Leopard的时候是字符模式,也像linux一样大量的信息输出,没有了原来的Leopard启动画面了,不过效果一样的,不影响启动后的系统使用。

Syndicate content