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.


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