mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IDEA-330224 fix concurrent access to shared buffer
should not really affect anything, because other implementation is used by default GitOrigin-RevId: 86e8993b26dcb63dc8964c1ce22b0a7f7bccf904
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d03791280e
commit
e46cf8a4c4
@@ -274,7 +274,6 @@ public final class MappedFileTypeIndex extends FileTypeIndexImplBase {
|
||||
private final @NotNull ResilientFileChannel myFileChannel;
|
||||
private volatile long myElementsCount;
|
||||
private volatile long myModificationsCounter = 0L;
|
||||
private final @NotNull ByteBuffer myDataBuffer = ByteBuffer.allocate(ELEMENT_BYTES);
|
||||
|
||||
private ForwardIndexFileControllerOverFile(@NotNull Path storage) throws StorageException {
|
||||
try {
|
||||
@@ -303,11 +302,11 @@ public final class MappedFileTypeIndex extends FileTypeIndexImplBase {
|
||||
|
||||
@Override
|
||||
public short get(int inputId) throws StorageException {
|
||||
ByteBuffer dataBuf = ByteBuffer.allocate(ELEMENT_BYTES);
|
||||
try {
|
||||
myDataBuffer.clear();
|
||||
int bytesLeft = ELEMENT_BYTES;
|
||||
while (bytesLeft > 0) {
|
||||
int result = myFileChannel.read(myDataBuffer, offsetInFile(inputId) + myDataBuffer.position());
|
||||
int result = myFileChannel.read(dataBuf, offsetInFile(inputId) + dataBuf.position());
|
||||
if (result == -1 && bytesLeft == ELEMENT_BYTES) {
|
||||
return 0; // read after EOF
|
||||
}
|
||||
@@ -316,8 +315,8 @@ public final class MappedFileTypeIndex extends FileTypeIndexImplBase {
|
||||
}
|
||||
bytesLeft -= result;
|
||||
}
|
||||
myDataBuffer.flip();
|
||||
return myDataBuffer.getShort();
|
||||
dataBuf.flip();
|
||||
return dataBuf.getShort();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw closeWithException(new StorageException(e));
|
||||
@@ -326,14 +325,14 @@ public final class MappedFileTypeIndex extends FileTypeIndexImplBase {
|
||||
|
||||
@Override
|
||||
public void set(int inputId, short value) throws StorageException {
|
||||
ByteBuffer dataBuf = ByteBuffer.allocate(ELEMENT_BYTES);
|
||||
try {
|
||||
ensureCapacity(inputId);
|
||||
myDataBuffer.clear();
|
||||
myDataBuffer.putShort(value);
|
||||
myDataBuffer.flip();
|
||||
dataBuf.putShort(value);
|
||||
dataBuf.flip();
|
||||
int bytesWritten = 0;
|
||||
while (bytesWritten < ELEMENT_BYTES) {
|
||||
bytesWritten += myFileChannel.write(myDataBuffer, offsetInFile(inputId) + bytesWritten);
|
||||
bytesWritten += myFileChannel.write(dataBuf, offsetInFile(inputId) + bytesWritten);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user