Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
162950e3
提交
162950e3
authored
7月 11, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A concurrent list, to replace the array list of old roots (work in progress)
上级
0dcbc5f7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
145 行删除
+44
-145
ConcurrentLinkedList.java
h2/src/main/org/h2/mvstore/ConcurrentLinkedList.java
+42
-43
ConcurrentRing.java
h2/src/main/org/h2/mvstore/ConcurrentRing.java
+0
-99
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+2
-3
没有找到文件。
h2/src/main/org/h2/mvstore/ConcurrentLinkedList.java
浏览文件 @
162950e3
...
...
@@ -7,70 +7,51 @@ package org.h2.mvstore;
import
java.util.Iterator
;
/**
* A very simple linked list that supports concurrent access.
* A very simple linked list that supports concurrent access.
* Internally, it uses immutable objects.
* It uses recursion and is not meant for long lists.
*
* @param <K> the key type
*/
public
class
ConcurrentLinkedList
<
K
>
{
static
final
Entry
<?>
NULL
=
new
Entry
<
Object
>(
null
,
null
);
volatile
Entry
<
K
>
head
;
private
volatile
Entry
<
K
>
tail
;
@SuppressWarnings
(
"unchecked"
)
volatile
Entry
<
K
>
head
=
(
Entry
<
K
>)
NULL
;
public
K
peekFirst
()
{
Entry
<
K
>
x
=
head
;
return
x
==
null
?
null
:
x
.
obj
;
return
x
.
obj
;
}
public
K
peekLast
()
{
Entry
<
K
>
x
=
tail
;
return
x
==
null
?
null
:
x
.
obj
;
Entry
<
K
>
x
=
head
;
while
(
x
!=
NULL
&&
x
.
next
!=
NULL
)
{
x
=
x
.
next
;
}
return
x
.
obj
;
}
public
void
add
(
K
obj
)
{
Entry
<
K
>
x
=
new
Entry
<
K
>(
obj
);
Entry
<
K
>
t
=
tail
;
if
(
t
!=
null
)
{
t
.
next
=
x
;
}
tail
=
x
;
if
(
head
==
null
)
{
head
=
x
;
}
public
synchronized
void
add
(
K
obj
)
{
head
=
Entry
.
append
(
head
,
obj
);
}
public
boolean
removeFirst
(
K
obj
)
{
Entry
<
K
>
x
=
head
;
if
(
x
==
null
||
x
.
obj
!=
obj
)
{
public
synchronized
boolean
removeFirst
(
K
obj
)
{
if
(
head
.
obj
!=
obj
)
{
return
false
;
}
if
(
head
==
tail
)
{
tail
=
x
.
next
;
}
head
=
x
.
next
;
head
=
head
.
next
;
return
true
;
}
public
boolean
removeLast
(
K
obj
)
{
Entry
<
K
>
x
=
head
;
if
(
x
==
null
)
{
public
synchronized
boolean
removeLast
(
K
obj
)
{
if
(
peekLast
()
!=
obj
)
{
return
false
;
}
Entry
<
K
>
prev
=
null
;
while
(
x
.
next
!=
null
)
{
prev
=
x
;
x
=
x
.
next
;
}
if
(
x
.
obj
!=
obj
)
{
return
false
;
}
if
(
prev
!=
null
)
{
prev
.
next
=
null
;
}
if
(
head
==
tail
)
{
head
=
prev
;
}
tail
=
prev
;
head
=
Entry
.
removeLast
(
head
);
return
true
;
}
...
...
@@ -81,7 +62,7 @@ public class ConcurrentLinkedList<K> {
@Override
public
boolean
hasNext
()
{
return
current
!=
null
;
return
current
!=
NULL
;
}
@Override
...
...
@@ -106,9 +87,27 @@ public class ConcurrentLinkedList<K> {
final
K
obj
;
Entry
<
K
>
next
;
Entry
(
K
obj
)
{
Entry
(
K
obj
,
Entry
<
K
>
next
)
{
this
.
obj
=
obj
;
this
.
next
=
next
;
}
@SuppressWarnings
(
"unchecked"
)
static
<
K
>
Entry
<
K
>
append
(
Entry
<
K
>
list
,
K
obj
)
{
if
(
list
==
NULL
)
{
return
new
Entry
<
K
>(
obj
,
(
Entry
<
K
>)
NULL
);
}
return
new
Entry
<
K
>(
list
.
obj
,
append
(
list
.
next
,
obj
));
}
@SuppressWarnings
(
"unchecked"
)
static
<
K
>
Entry
<
K
>
removeLast
(
Entry
<
K
>
list
)
{
if
(
list
==
NULL
||
list
.
next
==
NULL
)
{
return
(
Entry
<
K
>)
NULL
;
}
return
new
Entry
<
K
>(
list
.
obj
,
removeLast
(
list
.
next
));
}
}
}
h2/src/main/org/h2/mvstore/ConcurrentRing.java
deleted
100644 → 0
浏览文件 @
0dcbc5f7
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
;
import
java.util.Iterator
;
/**
* A ring buffer that supports concurrent access.
*
* @param <K> the key type
*/
public
class
ConcurrentRing
<
K
>
{
K
[]
buffer
;
volatile
int
readPos
;
volatile
int
writePos
;
@SuppressWarnings
(
"unchecked"
)
public
ConcurrentRing
()
{
buffer
=
(
K
[])
new
Object
[
4
];
}
public
K
peekFirst
()
{
return
buffer
[
getIndex
(
readPos
)];
}
public
K
peekLast
()
{
return
buffer
[
getIndex
(
writePos
-
1
)];
}
public
void
add
(
K
obj
)
{
buffer
[
getIndex
(
writePos
)]
=
obj
;
writePos
++;
if
(
writePos
-
readPos
>=
buffer
.
length
)
{
// double the capacity
@SuppressWarnings
(
"unchecked"
)
K
[]
b2
=
(
K
[])
new
Object
[
buffer
.
length
*
2
];
for
(
int
i
=
readPos
;
i
<
writePos
;
i
++)
{
K
x
=
buffer
[
getIndex
(
i
)];
int
i2
=
i
&
b2
.
length
-
1
;
b2
[
i2
]
=
x
;
}
buffer
=
b2
;
}
}
public
boolean
removeFirst
(
K
obj
)
{
int
p
=
readPos
;
int
idx
=
getIndex
(
p
);
if
(
buffer
[
idx
]
!=
obj
)
{
return
false
;
}
buffer
[
idx
]
=
null
;
readPos
=
p
+
1
;
return
true
;
}
public
boolean
removeLast
(
K
obj
)
{
int
p
=
writePos
;
int
idx
=
getIndex
(
p
-
1
);
if
(
buffer
[
idx
]
!=
obj
)
{
return
false
;
}
buffer
[
idx
]
=
null
;
writePos
=
p
-
1
;
return
true
;
}
int
getIndex
(
int
pos
)
{
return
pos
&
buffer
.
length
-
1
;
}
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
int
pos
=
readPos
;
@Override
public
boolean
hasNext
()
{
return
pos
!=
writePos
;
}
@Override
public
K
next
()
{
return
buffer
[
getIndex
(
pos
++)];
}
@Override
public
void
remove
()
{
throw
DataUtils
.
newUnsupportedOperationException
(
"remove"
);
}
};
}
}
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
162950e3
...
...
@@ -8,7 +8,6 @@ package org.h2.mvstore;
import
java.util.AbstractList
;
import
java.util.AbstractMap
;
import
java.util.AbstractSet
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
...
...
@@ -54,8 +53,8 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private
final
DataType
keyType
;
private
final
DataType
valueType
;
private
Concurrent
Ring
<
Page
>
oldRoots
=
new
Concurrent
Ring
<
Page
>();
private
Concurrent
LinkedList
<
Page
>
oldRoots
=
new
Concurrent
LinkedList
<
Page
>();
private
boolean
closed
;
private
boolean
readOnly
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论