I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3a767d84 authored by zzz's avatar zzz
Browse files

concurrentify with LBQ

parent d04ce7a2
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,7 @@ package net.i2p.crypto;
import gnu.crypto.hash.Sha256Standalone;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import net.i2p.I2PAppContext;
import net.i2p.data.Base64;
......@@ -15,11 +14,9 @@ import net.i2p.data.Hash;
*
*/
public final class SHA256Generator {
private List _digests;
private final List _digestsGnu;
private final LinkedBlockingQueue<Sha256Standalone> _digestsGnu;
public SHA256Generator(I2PAppContext context) {
_digests = new ArrayList(32);
_digestsGnu = new ArrayList(32);
_digestsGnu = new LinkedBlockingQueue(32);
}
public static final SHA256Generator getInstance() {
......@@ -50,11 +47,7 @@ public final class SHA256Generator {
}
private Sha256Standalone acquireGnu() {
Sha256Standalone rv = null;
synchronized (_digestsGnu) {
if (!_digestsGnu.isEmpty())
rv = (Sha256Standalone)_digestsGnu.remove(0);
}
Sha256Standalone rv = _digestsGnu.poll();
if (rv != null)
rv.reset();
else
......@@ -63,11 +56,7 @@ public final class SHA256Generator {
}
private void releaseGnu(Sha256Standalone digest) {
synchronized (_digestsGnu) {
if (_digestsGnu.size() < 32) {
_digestsGnu.add(digest);
}
}
_digestsGnu.offer(digest);
}
public static void main(String args[]) {
......@@ -75,4 +64,4 @@ public final class SHA256Generator {
for (int i = 0; i < args.length; i++)
System.out.println("SHA256 [" + args[i] + "] = [" + Base64.encode(ctx.sha().calculateHash(args[i].getBytes()).getData()) + "]");
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment