公开学习文档

公开学习文档


RCU机制

<h2>定义</h2> <p>核心接口:</p> <pre><code class="language-c">rcu_read_lock() // 标记读者临界区的开始 rcu_read_unlock() // 标记读者临界区的结束 synchronize_rcu() || call_rcu() // 等待 Grace period 结束后进行资源回收 rcu_assign_pointer() // Updater 使用这个宏对受 RCU 保护的指针进行赋值 rcu_dereference() // Reader 使用这个宏来获取受 RCU 保护的指针</code></pre> <p>其中下面 2 个接口说明:</p> <pre><code class="language-c">// rcu_assign_pointer() 通常用于写者的发布。 // 其中加入了内存屏障,目的是:保证在更新指针之前的代码,一定在更新指针之前执行 #define rcu_assign_pointer(p,v) ({ \ smp_wmb();\ (p)= (v); \ }) // rcu_dereference()通常用于读者的订阅。 // 其中也加入了内存屏障,这是加在赋值的下面,目的是:保证先获取指针,再进行下面的对指针的操作 #define rcu_dereference(p) ({ \ typeof(p)_________p1 =ACCESS_ONCE(p); \ smp_read_barrier_depends();\ (_________p1);\ })</code></pre> <h2>list 操作</h2> <pre><code class="language-c">// 定义 LIST_HEAD(linked_list); // 初始化 INIT_LIST_HEAD(&amp;amp;node.list); // 添加 inline void list_add(struct list_head *new, struct list_head *head); inline void list_add_tail(struct list_head *new, struct list_head *head); // 删除 inline void list_del(struct list_head *entry); inline void list_del_init(struct list_head *entry); // 替换 inline void list_replace(struct list_head *old, struct list_head *new); inline void list_replace_init(struct list_head *old, struct list_head *new); // 移动 inline void list_move(struct list_head *list, struct list_head *head); inline void list_move_tail(struct list_head *list, struct list_head *head); // 检查 inline int list_is_last(const struct list_head *list, const struct list_head *head); inline int list_empty(const struct list_head *head); inline int list_is_singular(const struct list_head *head); </code></pre> <p>&gt; 参考文档:<a href="https://mp.weixin.qq.com/s/DkR2ZyLeP5h76bGXOlcwWQ?version=4.1.28.6010&amp;platform=win&amp;nwr_flag=1#wechat_redirect">https://mp.weixin.qq.com/s/DkR2ZyLeP5h76bGXOlcwWQ?version=4.1.28.6010&amp;platform=win&amp;nwr_flag=1#wechat_redirect</a></p> <h2>参考文档</h2> <p>&gt; <a href="https://www.cnblogs.com/LoyenWang/p/12681494.html">https://www.cnblogs.com/LoyenWang/p/12681494.html</a></p>

页面列表

ITEM_HTML