中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

中國建設(shè)銀行網(wǎng)站首頁u盾登入百度推廣基木魚

中國建設(shè)銀行網(wǎng)站首頁u盾登入,百度推廣基木魚,領(lǐng)卷網(wǎng)站如何做代理,裝修公司網(wǎng)站wordpress 模板基礎(chǔ)知識 rcu-read copy update的縮寫。和讀寫鎖起到相同的效果。據(jù)說牛逼一點。對于我們普通程序員,要先學(xué)會使用,再探究其內(nèi)部原理。 鏈表的數(shù)據(jù)結(jié)構(gòu): struct list_head {struct list_head *next, *prev; };還有一種:struct h…

基礎(chǔ)知識?

rcu-read copy update的縮寫。和讀寫鎖起到相同的效果。據(jù)說牛逼一點。對于我們普通程序員,要先學(xué)會使用,再探究其內(nèi)部原理。

鏈表的數(shù)據(jù)結(jié)構(gòu):

struct list_head {struct list_head *next, *prev;
};

?還有一種:struct hlist_head,本文不做該鏈表的測試。

struct hlist_head {struct hlist_node *first;
};struct hlist_node {struct hlist_node *next, **pprev;
};

?涉及的文件:include\linux\rculist.h

初始化鏈表:INIT_LIST_HEAD_RCU

/** INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers* @list: list to be initialized** You should instead use INIT_LIST_HEAD() for normal initialization and* cleanup tasks, when readers have no access to the list being initialized.* However, if the list being initialized is visible to readers, you* need to keep the compiler from being too mischievous.*/
static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
{WRITE_ONCE(list->next, list);WRITE_ONCE(list->prev, list);
}

?添加節(jié)點list_add_rcu(插入到頭節(jié)點后面)

/*** list_add_rcu - add a new entry to rcu-protected list* @new: new entry to be added* @head: list head to add it after** Insert a new entry after the specified head.* This is good for implementing stacks.** The caller must take whatever precautions are necessary* (such as holding appropriate locks) to avoid racing* with another list-mutation primitive, such as list_add_rcu()* or list_del_rcu(), running on this same list.* However, it is perfectly legal to run concurrently with* the _rcu list-traversal primitives, such as* list_for_each_entry_rcu().*/
static inline void list_add_rcu(struct list_head *new, struct list_head *head)
{__list_add_rcu(new, head, head->next);
}

?添加節(jié)點list_add_tail_rcu(插入到頭節(jié)點前面,就是鏈尾)?

/*** list_add_tail_rcu - add a new entry to rcu-protected list* @new: new entry to be added* @head: list head to add it before** Insert a new entry before the specified head.* This is useful for implementing queues.** The caller must take whatever precautions are necessary* (such as holding appropriate locks) to avoid racing* with another list-mutation primitive, such as list_add_tail_rcu()* or list_del_rcu(), running on this same list.* However, it is perfectly legal to run concurrently with* the _rcu list-traversal primitives, such as* list_for_each_entry_rcu().*/
static inline void list_add_tail_rcu(struct list_head *new,struct list_head *head)
{__list_add_rcu(new, head->prev, head);
}

刪除節(jié)點list_del_rcu

/*** list_del_rcu - deletes entry from list without re-initialization* @entry: the element to delete from the list.** Note: list_empty() on entry does not return true after this,* the entry is in an undefined state. It is useful for RCU based* lockfree traversal.** In particular, it means that we can not poison the forward* pointers that may still be used for walking the list.** The caller must take whatever precautions are necessary* (such as holding appropriate locks) to avoid racing* with another list-mutation primitive, such as list_del_rcu()* or list_add_rcu(), running on this same list.* However, it is perfectly legal to run concurrently with* the _rcu list-traversal primitives, such as* list_for_each_entry_rcu().** Note that the caller is not permitted to immediately free* the newly deleted entry.  Instead, either synchronize_rcu()* or call_rcu() must be used to defer freeing until an RCU* grace period has elapsed.*/
static inline void list_del_rcu(struct list_head *entry)
{__list_del_entry(entry);entry->prev = LIST_POISON2;
}

刪除尾節(jié)點hlist_del_init_rcu?

/*** hlist_del_init_rcu - deletes entry from hash list with re-initialization* @n: the element to delete from the hash list.** Note: list_unhashed() on the node return true after this. It is* useful for RCU based read lockfree traversal if the writer side* must know if the list entry is still hashed or already unhashed.** In particular, it means that we can not poison the forward pointers* that may still be used for walking the hash list and we can only* zero the pprev pointer so list_unhashed() will return true after* this.** The caller must take whatever precautions are necessary (such as* holding appropriate locks) to avoid racing with another* list-mutation primitive, such as hlist_add_head_rcu() or* hlist_del_rcu(), running on this same list.  However, it is* perfectly legal to run concurrently with the _rcu list-traversal* primitives, such as hlist_for_each_entry_rcu().*/
static inline void hlist_del_init_rcu(struct hlist_node *n)
{if (!hlist_unhashed(n)) {__hlist_del(n);n->pprev = NULL;}
}

?替換list_replace_rcu:

/*** list_replace_rcu - replace old entry by new one* @old : the element to be replaced* @new : the new element to insert** The @old entry will be replaced with the @new entry atomically.* Note: @old should not be empty.*/
static inline void list_replace_rcu(struct list_head *old,struct list_head *new)
{new->next = old->next;new->prev = old->prev;rcu_assign_pointer(list_next_rcu(new->prev), new);new->next->prev = new;old->prev = LIST_POISON2;
}

計算長度

判空:list_empty

鏈表尾空時,返回值為1:鏈表不空時返回0。

????????下面這段注釋的大體含義就是,當你想用list_empty_rcu的時候,list_empty就足夠滿足需要了。

/** Why is there no list_empty_rcu()?  Because list_empty() serves this* purpose.  The list_empty() function fetches the RCU-protected pointer* and compares it to the address of the list head, but neither dereferences* this pointer itself nor provides this pointer to the caller.  Therefore,* it is not necessary to use rcu_dereference(), so that list_empty() can* be used anywhere you would want to use a list_empty_rcu().*/

獲取節(jié)點對應(yīng)的數(shù)據(jù):list_entry_rcu

/*** list_entry_rcu - get the struct for this entry* @ptr:        the &struct list_head pointer.* @type:       the type of the struct this is embedded in.* @member:     the name of the list_head within the struct.** This primitive may safely run concurrently with the _rcu list-mutation* primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().*/
#define list_entry_rcu(ptr, type, member) \container_of(READ_ONCE(ptr), type, member)

遍歷?list_for_each_entry_rcu:

/*** list_for_each_entry_rcu	-	iterate over rcu list of given type* @pos:	the type * to use as a loop cursor.* @head:	the head for your list.* @member:	the name of the list_head within the struct.* @cond:	optional lockdep expression if called from non-RCU protection.** This list-traversal primitive may safely run concurrently with* the _rcu list-mutation primitives such as list_add_rcu()* as long as the traversal is guarded by rcu_read_lock().*/
#define list_for_each_entry_rcu(pos, head, member, cond...)		\for (__list_check_rcu(dummy, ## cond, 0),			\pos = list_entry_rcu((head)->next, typeof(*pos), member);	\&pos->member != (head);					\pos = list_entry_rcu(pos->member.next, typeof(*pos), member))

鏈表綜合實驗代碼

????????測試內(nèi)容包括添加、計算長度、遍歷數(shù)據(jù)、刪除節(jié)點、替換節(jié)點。最后在卸載函數(shù)中釋放鏈表資源。

#include <linux/module.h>
#include <linux/init.h>
#include <linux/rculist.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>#define _DEBUG_INFO
#ifdef _DEBUG_INFO#define DEBUG_INFO(format,...)	\printk(KERN_ERR"%s:%d -- "format"\n",\__func__,__LINE__,##__VA_ARGS__)
#else#define DEBUG_INFO(format,...)
#endifstruct rcu_private_data{struct list_head list;
};struct my_list_node{struct list_head node;int number;
};static int list_size(struct rcu_private_data *p){struct my_list_node *pos;struct list_head *head = &p->list;int count = 0;if(list_empty(&p->list)){DEBUG_INFO("list is empty");return 0;}else{DEBUG_INFO("list is not empty");}list_for_each_entry_rcu(pos,head,node){count++;}return count;
}//遍歷鏈表
void show_list_nodes(struct rcu_private_data *p){struct my_list_node *pos;struct list_head *head = &p->list;if(list_empty(&p->list)){DEBUG_INFO("list is empty");return;}else{DEBUG_INFO("list is not empty");}list_for_each_entry_rcu(pos,head,node){DEBUG_INFO("pos->number = %d",pos->number);}
}//清空鏈表
void del_list_nodes(struct rcu_private_data *p){struct my_list_node *pos;struct list_head *head = &p->list;if(list_empty(&p->list)){DEBUG_INFO("list is empty");return;}else{DEBUG_INFO("list is not empty");}list_for_each_entry_rcu(pos,head,node){DEBUG_INFO("pos->number = %d\n",pos->number);vfree(pos);}
}struct rcu_private_data *prpd;static int __init ch02_init(void){int i = 0;static struct my_list_node * new[6];struct rcu_private_data *p = (struct rcu_private_data*)vmalloc(sizeof(struct rcu_private_data));prpd = p;INIT_LIST_HEAD_RCU(&p->list);DEBUG_INFO("list_empty(&p->list) = %d",list_empty(&p->list));for(i = 0;i < 5;i++){new[i] = (struct my_list_node*)vmalloc(sizeof(struct my_list_node));INIT_LIST_HEAD_RCU(&new[i]->node);new[i]->number = i;list_add_rcu(&new[i]->node,&p->list);}DEBUG_INFO("list_size = %d",list_size(p));//添加后的結(jié)果,應(yīng)該是5 4 3 2 1//遍歷鏈表:show_list_nodes(p);//刪除鏈表節(jié)點 new[3];list_del_rcu(&new[3]->node);vfree(new[3]);DEBUG_INFO("list_size = %d",list_size(p));//遍歷鏈表:show_list_nodes(p);//替換一個鏈表節(jié)點new[5] = (struct my_list_node*)vmalloc(sizeof(struct my_list_node));INIT_LIST_HEAD_RCU(&new[5]->node);new[5]->number = i;list_replace_rcu(&new[1]->node,&new[5]->node);vfree(new[1]);//遍歷鏈表:show_list_nodes(p);DEBUG_INFO("init");return 0;
}static void __exit ch02_exit(void){del_list_nodes(prpd);vfree(prpd);DEBUG_INFO("exit");
}module_init(ch02_init);
module_exit(ch02_exit);
MODULE_LICENSE("GPL");

測試

加載模塊

卸載模塊?

小結(jié)

http://www.risenshineclean.com/news/12000.html

相關(guān)文章:

  • 蘇州高端網(wǎng)站設(shè)計企業(yè)滕州今日頭條新聞
  • 網(wǎng)站頁面怎么設(shè)計寧夏百度推廣代理商
  • 東麗區(qū) 網(wǎng)站建設(shè)今日足球賽事數(shù)據(jù)
  • 鄭州營銷網(wǎng)站托管seo最新技巧
  • 微網(wǎng)站促銷版seo輔助工具
  • 做劇情網(wǎng)站侵權(quán)嗎簡述網(wǎng)絡(luò)營銷的方法
  • 去年做那個網(wǎng)站致富google官網(wǎng)注冊賬號入口
  • 環(huán)保設(shè)備網(wǎng)站怎么做手機百度云電腦版入口
  • 設(shè)計網(wǎng)站要多久東莞seo技術(shù)培訓(xùn)
  • 團隊云智能網(wǎng)站建設(shè)crm
  • 以下屬于b2c網(wǎng)站的是搜索引擎廣告形式有
  • 西安買公司的網(wǎng)站建設(shè)百度一下百度下載
  • 互聯(lián)網(wǎng)網(wǎng)站建設(shè)哪里好新聞播報最新
  • 工業(yè)產(chǎn)品設(shè)計與創(chuàng)客實踐技能大賽蘋果aso優(yōu)化
  • 買什么樣的主機(用來建網(wǎng)站的)支持下載免費網(wǎng)站制作軟件平臺
  • 站群子網(wǎng)站開發(fā)小程序開發(fā)平臺
  • 網(wǎng)站建設(shè)合作范本橙子建站官網(wǎng)
  • 手游代理平臺哪個好seo專員是什么
  • 做外貿(mào)批發(fā)的網(wǎng)站有哪些seo搜索引擎優(yōu)化實訓(xùn)
  • dedecms農(nóng)業(yè)種植網(wǎng)站模板蘇州seo關(guān)鍵詞優(yōu)化方法
  • 廈門網(wǎng)站建設(shè)公司新網(wǎng)域名
  • 中國能建官網(wǎng)seo短視頻網(wǎng)頁入口引流免費
  • 馬來西亞做網(wǎng)站一鍵搭建網(wǎng)站
  • wordpress如何安裝網(wǎng)站主題seo平臺怎么樣
  • 東營網(wǎng)站建設(shè)公司臨沂頭條新聞今日頭條
  • 小型b2c網(wǎng)站營銷推廣活動策劃書模板
  • 青島建網(wǎng)站人如何查詢域名注冊人信息
  • 大企業(yè)網(wǎng)站建設(shè)方案seo關(guān)鍵詞排名優(yōu)化軟件
  • 香港做批發(fā)的網(wǎng)站有哪些手續(xù)灰色行業(yè)怎么推廣引流
  • 陽泉住房和城鄉(xiāng)建設(shè)部網(wǎng)站百度官方免費下載