-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the performance of ParallelStream
- Loading branch information
1 parent
38fe6a5
commit 2d9e1f6
Showing
9 changed files
with
1,506 additions
and
161 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package rapid | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class LockFreeQueue[A](capacity: Int) { | ||
private val buffer = new Array[AnyRef](capacity) | ||
private val head = new AtomicInteger(0) | ||
private val tail = new AtomicInteger(0) | ||
|
||
def enqueue(value: A): Boolean = { | ||
val currentTail = tail.get() | ||
val nextTail = (currentTail + 1) % capacity | ||
if (nextTail != head.get()) { | ||
buffer(currentTail) = value.asInstanceOf[AnyRef] | ||
tail.set(nextTail) | ||
true | ||
} else false // Queue full | ||
} | ||
|
||
def dequeue(): Opt[A] = { | ||
val currentHead = head.get() | ||
if (currentHead == tail.get()) Opt.Empty // Queue empty | ||
else { | ||
val value = buffer(currentHead).asInstanceOf[A] | ||
buffer(currentHead) = null // Avoid memory leaks | ||
head.set((currentHead + 1) % capacity) | ||
Opt.Value(value) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
core/shared/src/main/scala/rapid/ParallelUnorderedStreamProcessor.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters