libevent读书笔记

1.libevent使用回调可以让用户自定义log和内存分配,回调的威力

2.libevent的替换内存分配过程中使用了一个union,赶脚很霸气

/* This union's purpose is to be as big as the largest of all the
 * types it contains. */
union alignment {
    size_t sz;
    void *ptr;
    double dbl;
};
/* We need to make sure that everything we return is on the right
   alignment to hold anything, including a double. */
#define ALIGNMENT sizeof(union alignment)
注释写的很明显了。

3.调试锁 (Debugging lock usage)

实在没有想到会有这样的方法,值得借鉴。可检测出来的问题包括:

(1)unlocking a lock that we don’t actually hold

(2)re-locking a non-recursive lock

方法:

void evthread_enable_lock_debugging(void);
#define evthread_enable_lock_debuging() evthread_enable_lock_debugging()

note :This function MUST be called before any locks are created or used. To be safe, call it just after you set your threading functions

有意思的是这个evthread_enable_lock_debuging()在之前的版本是有个拼写错误的:P

看了看内容发现自己功力不够 :( 读不懂... ...5555555,果断跳过。

4.调试事件(Debugging event usage)

(1)Treating an uninitialized struct event as though it were initialized.

(2)Try to reinitialize a pending struct event.

由于是要花费额外的内存和cpu,所以就是为了排错才会用到专门的调试函数

void event_enable_debug_mode(void);

This function must only be called before any event_base is created.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章