mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-07 00:39:13 +07:00
Resolved a concurrency issue regarding shared state within static decompress method
This commit is contained in:
@ -3,6 +3,8 @@ package com.riiablo.mpq.util;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Pool;
|
||||||
|
|
||||||
public class ADPCM {
|
public class ADPCM {
|
||||||
private ADPCM() {}
|
private ADPCM() {}
|
||||||
|
|
||||||
@ -37,14 +39,25 @@ public class ADPCM {
|
|||||||
byte stepIndex;
|
byte stepIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Channel[] state = new Channel[2];
|
private static final Pool<Channel[]> POOL = new Pool<Channel[]>(8, 64, true) {
|
||||||
static {
|
@Override
|
||||||
for (int i = 0; i < CHANNELS; i++) {
|
protected Channel[] newObject() {
|
||||||
state[i] = new Channel();
|
final Channel[] channels = new Channel[CHANNELS];
|
||||||
|
for (int i = 0; i < CHANNELS; i++) channels[i] = new Channel();
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void decompress(ByteBuffer in, ByteBuffer out, int numChannels) {
|
||||||
|
Channel[] channels = POOL.obtain();
|
||||||
|
try {
|
||||||
|
decompress(in, out, numChannels, channels);
|
||||||
|
} finally {
|
||||||
|
POOL.free(channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void decompress(ByteBuffer in, ByteBuffer out, int numChannels) {
|
public static void decompress(ByteBuffer in, ByteBuffer out, int numChannels, Channel[] state) {
|
||||||
assert in.order() == ByteOrder.LITTLE_ENDIAN && out.order() == ByteOrder.LITTLE_ENDIAN : "in.order() = " + in.order() + "; out.order() = " + out.order();
|
assert in.order() == ByteOrder.LITTLE_ENDIAN && out.order() == ByteOrder.LITTLE_ENDIAN : "in.order() = " + in.order() + "; out.order() = " + out.order();
|
||||||
|
|
||||||
byte stepshift = (byte) (in.getShort() >>> Byte.SIZE);
|
byte stepshift = (byte) (in.getShort() >>> Byte.SIZE);
|
||||||
|
Reference in New Issue
Block a user