Skip to content

Commit

Permalink
LZMACompressor: Release locks with InterlockedExchange.
Browse files Browse the repository at this point in the history
Not sure if ordinary stores can be reordered under Windows on Arm's x86 emulator.
InterlockedExchange provides a full barrier.
  • Loading branch information
jordanrussell authored Nov 9, 2024
1 parent f41bfe1 commit 0e3bd96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Projects/Src/Compression.LZMACompressor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ function TLZMAWorkerThread.Read(var Data; Size: Cardinal;
Exit;
end;
Result := FillBuffer(False, @Data, Size, ProcessedSize);
FReadLock := 0;
InterlockedExchange(FReadLock, 0);
end;

function TLZMAWorkerThread.Write(const Data; Size: Cardinal;
Expand All @@ -618,7 +618,7 @@ function TLZMAWorkerThread.Write(const Data; Size: Cardinal;
Exit;
end;
Result := FillBuffer(True, @Data, Size, ProcessedSize);
FWriteLock := 0;
InterlockedExchange(FWriteLock, 0);
end;

function TLZMAWorkerThread.ProgressMade(const TotalBytesProcessed: Integer64): HRESULT;
Expand All @@ -645,7 +645,7 @@ function TLZMAWorkerThread.ProgressMade(const TotalBytesProcessed: Integer64): H
end;
Result := WakeMainAndWaitUntil(FEvents.WorkerHasProgressEvent,
FEvents.EndWaitOnProgressEvent);
FProgressLock := 0;
InterlockedExchange(FProgressLock, 0);
end
else
Result := S_OK;
Expand Down
6 changes: 3 additions & 3 deletions Projects/Src/Compression.LZMACompressor/islzma/islzma_exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static HRESULT Read(void *Data, size_t Size, size_t *ProcessedSize)
return E_FAIL;
}
Result = FillBuffer(FALSE, Data, Size, ProcessedSize);
FReadLock = 0;
InterlockedExchange(&FReadLock, 0);

return Result;
}
Expand All @@ -232,7 +232,7 @@ static HRESULT Write(const void *Data, size_t Size, size_t *ProcessedSize)
return E_FAIL;
}
Result = FillBuffer(TRUE, (void *)Data, Size, ProcessedSize);
FWriteLock = 0;
InterlockedExchange(&FWriteLock, 0);

return Result;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ static HRESULT ProgressMade(const UInt64 TotalBytesProcessed)
Result = WakeMainAndWaitUntil(
THandle32ToHandle(FEvents->WorkerHasProgressEvent),
THandle32ToHandle(FEvents->EndWaitOnProgressEvent));
FProgressLock = 0;
InterlockedExchange(&FProgressLock, 0);
} else {
Result = S_OK;
}
Expand Down

0 comments on commit 0e3bd96

Please sign in to comment.