mirror of
https://github.com/apache/lucene.git
synced 2025-02-10 12:05:36 +00:00
sequence numbers: removed synchronized in DocumentsWriterDeleteQueue.add
This commit is contained in:
parent
4ee0b49429
commit
818ed49098
@ -150,10 +150,31 @@ final class DocumentsWriterDeleteQueue implements Accountable {
|
||||
return seqNo;
|
||||
}
|
||||
|
||||
synchronized long add(Node<?> newNode) {
|
||||
tail.next = newNode;
|
||||
tail = newNode;
|
||||
return seqNo.getAndIncrement();
|
||||
long add(Node<?> newNode) {
|
||||
/*
|
||||
* this non-blocking / 'wait-free' linked list add was inspired by Apache
|
||||
* Harmony's ConcurrentLinkedQueue Implementation.
|
||||
*/
|
||||
while (true) {
|
||||
final Node<?> currentTail = tail;
|
||||
final Node<?> tailNext = currentTail.next;
|
||||
if (tail == currentTail && tailNext == null) {
|
||||
/*
|
||||
* we are in quiescent state and can try to insert the newNode to the
|
||||
* current tail if we fail to insert we just retry the operation since
|
||||
* somebody else has already added its newNode
|
||||
*/
|
||||
if (currentTail.casNext(null, newNode)) {
|
||||
/*
|
||||
* now that we are done we need to advance the tail
|
||||
*/
|
||||
long mySeqNo = seqNo.getAndIncrement();
|
||||
boolean result = tailUpdater.compareAndSet(this, currentTail, newNode);
|
||||
assert result;
|
||||
return mySeqNo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean anyChanges() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user