Skip to content

Commit

Permalink
[FIX] Bad practice: locking on 'this'.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeago committed Feb 11, 2020
1 parent cb2c1ac commit cf1c91c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/EmbedIO/Files/Internal/FileCacheItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal sealed class FileCacheItem
// Size of a WeakReference<T> in bytes
private static readonly long SizeOfWeakReference = Environment.Is64BitProcess ? 16 : 32;

private readonly object _syncRoot = new object();

// Educated guess about the size of an Item in memory (see comments on constructor).
// 3 * SizeOfPointer + total size of fields, rounded up to a multiple of 16.
//
Expand Down Expand Up @@ -122,7 +124,7 @@ internal FileCacheItem(FileCache.Section section, DateTime lastModifiedUtc, long
// This is the bare minimum locking we need
// to ensure we don't mess sizes up.
byte[]? oldContent;
lock (this)
lock (_syncRoot)
{
switch (compressionMethod)
{
Expand Down

0 comments on commit cf1c91c

Please sign in to comment.