Skip to content

Commit

Permalink
Fixed issue with mutlithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQuan committed Oct 1, 2023
1 parent 689a09c commit 0d1f080
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO.Compression;
using System.Text;
using System.Text.Json;
using System.Threading;

namespace Nodsoft.WowsReplaysUnpack.Services;

Expand All @@ -21,6 +22,7 @@ public sealed class ReplayUnpackerService<TController> : ReplayUnpackerService,
private readonly JsonSerializerOptions _jsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
private readonly IReplayDataParser _replayDataParser;
private readonly IReplayController _replayController;
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1);

public ReplayUnpackerService(IReplayDataParser replayDataParser, TController replayController)
{
Expand Down Expand Up @@ -69,7 +71,7 @@ Seek to offset 4 in the replay file (skipping the magic number)
See http://wiki.vbaddict.net/pages/File_Replays for more details.
*/
options ??= new();

_semaphore.Wait();
BinaryReader binaryReader = new(stream);

byte[] signature = binaryReader.ReadBytes(4);
Expand Down Expand Up @@ -103,7 +105,7 @@ Seek to offset 4 in the replay file (skipping the magic number)
{
_replayController.HandleNetworkPacket(networkPacket, options);
}

_semaphore.Release();
return replay;
}

Expand Down

0 comments on commit 0d1f080

Please sign in to comment.