wiredtiger - hazard pointers
http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890
memory deallocation lock-free
session.h
/*
* WT_HAZARD --
* A hazard pointer.
*/
struct __wt_hazard {
WT_PAGE *page; /* Page address */
#ifdef HAVE_DIAGNOSTIC
const char *file; /* File/line where hazard acquired */
int line;
#endif
}; struct WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) __wt_session_impl {
// 略...
/*
* Hazard pointers.
*
* Use the non-NULL state of the hazard field to know if the session has
* previously been initialized.
*/
#define WT_SESSION_FIRST_USE(s) \
((s)->hazard == NULL) /* The number of hazard pointers grows dynamically. */
#define WT_HAZARD_INCR 10
uint32_t hazard_size; /* Allocated slots in hazard array. */
uint32_t nhazard; /* Count of active hazard pointers */
WT_HAZARD *hazard; /* Hazard pointer array */
};
support/hazard.c
__wt_hazard_set()
/__wt_hazard_clear()
btree.i
在__wt_page_hazard_check前, cas保证WT_REF为 WT_REF_LOCKED(btmem.h, struct __wt_ref)
__wt_page_hazard_check(WT_SESSION_IMPL *session, WT_PAGE *page)
{
WT_CONNECTION_IMPL *conn;
WT_HAZARD *hp;
WT_SESSION_IMPL *s;
uint32_t i, hazard_size, session_cnt; conn = S2C(session); /*
* No lock is required because the session array is fixed size, but it
* may contain inactive entries. We must review any active session
* that might contain a hazard pointer, so insert a barrier before
* reading the active session count. That way, no matter what sessions
* come or go, we'll check the slots for all of the sessions that could
* have been active when we started our check.
*/
WT_ORDERED_READ(session_cnt, conn->session_cnt);
for (s = conn->sessions, i = ; i < session_cnt; ++s, ++i) {
if (!s->active)
continue;
WT_ORDERED_READ(hazard_size, s->hazard_size);
for (hp = s->hazard; hp < s->hazard + hazard_size; ++hp)
if (hp->page == page)
return (hp);
}
return (NULL);
}
wiredtiger - hazard pointers的更多相关文章
- 关于Hazard Pointers的话题
关于Hazard Pointers的话题, 起源于这个文章: 实现无锁的栈与队列(4) http://www.cnblogs.com/catch/p/3176636.html 其实他的系列文章(3)之 ...
- 风险指针(Hazard Pointer) 内存空间共享模型
WiredTiger是一种高性能的开源存储引擎,现已在MongoDB中作为内模式应用.WiredTiger支持行存储.列存储两种存储模式,采用LSM Tree方式进行索引记录 WiredTiger支持 ...
- lock free数据结构内存回收技术-hazard pointer
lock free数据结构一般来说拥有比基于lock实现的数据结构更高的性能,但是其实现比基于lock的实现更为复杂,需要处理的难题包括预防ABA问题,内存如何重用和回收等.通常,最简单最有效的处理A ...
- [转载]锁无关的数据结构与Hazard指针——操纵有限的资源
Lock-Free Data Structures with Hazard Pointers 锁无关的数据结构与Hazard指针----操纵有限的资源 By Andrei Alexandrescu a ...
- MongoDB新存储引擎WiredTiger实现(事务篇)
导语:计算机硬件在飞速发展,数据规模在急速膨胀,但是数据库仍然使用是十年以前的架构体系,WiredTiger 尝试打破这一切,充分利用多核与大内存时代,开发一种真正满足未来大数据管理所需的数据库.本文 ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- Leetcode 笔记 116 - Populating Next Right Pointers in Each Node
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...
- MongoDB 存储引擎:WiredTiger和In-Memory
存储引擎(Storage Engine)是MongoDB的核心组件,负责管理数据如何存储在硬盘(Disk)和内存(Memory)上.从MongoDB 3.2 版本开始,MongoDB 支持多数据存储引 ...
- [LeetCode] Populating Next Right Pointers in Each Node II 每个节点的右向指针之二
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
随机推荐
- 洛谷P3367 【模板】并查集
P3367 [模板]并查集 293通过 551提交 题目提供者HansBug 标签 难度普及- 提交 讨论 题解 最新讨论 不知道哪错了 为啥通不过最后三个节点 题解 不懂为什么MLE 最后一个数 ...
- Hadoop HDFS编程 API入门系列之HdfsUtil版本2(七)
不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs1; import java.io.FileInputStream;import ...
- objective c, protocol
OC中协议类似于java中的接口,在多个类具有类似的方法时可以将这些方法定义到protocol中,然后各个类分别实现protocol中的各个方法. 例:有两个类Square和Circle, 定义一个p ...
- 获取ServletContext
ServletConfig config.getServletContext(): GenericServlet this.getServletContext(); HttpSe ...
- Asp.net Page指令
Page指令为编译器编译页面时使用的指令 指令的格式为 <%@ [Directive] [Attribute=value]%> <%@ Page Language="C#& ...
- 未能加载文件或程序集Microsoft.ReportViewer.WebForms, Version=10.0.0.0
解决方案如下ASP.NET项目使用VS2010开发,部署到windows 2008环境中,出现未能加载文件或程序集“Microsoft.ReportViewer.WebForms, Version=1 ...
- asp.net截取指定长度的字符串内容
/// <summary> /// 用于截取指定长度的字符串内容 /// </summary> /// <param name="sString"&g ...
- css 中 list-style-image:
用于设置<a>标签的默认格式的背景图片
- ssh 互通脚本
实现了 主机到指定机器的ssh免密码登录. 若要实现互通, 则在机器列表的每台机器上执行该脚本. 192.168.1.22 root test 192.168.1.25 root test 192.1 ...
- C语课设心得分享(三)
调试. 以前咱们写课后习题,一般也不需要使用调试,如果程序编译error,根据错误信息就可以改好:如果是结果错误,那么在稿纸上过几遍基本也可以得出结果. 但咱们这个课设比较大,就需要很多调试的过程,尤 ...