Skip to content

Commit

Permalink
Make ThreadSafeObjectPool actually thread safe (AvaloniaUI#8106)
Browse files Browse the repository at this point in the history
* Make ThreadSafeObjectPool actually thread safe
  • Loading branch information
kekekeks authored and danwalmsley committed May 10, 2022
1 parent 467ceb5 commit 4f3fa13
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/Avalonia.Base/Threading/ThreadSafeObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Avalonia.Threading
public class ThreadSafeObjectPool<T> where T : class, new()
{
private Stack<T> _stack = new Stack<T>();
private object _lock = new object();
public static ThreadSafeObjectPool<T> Default { get; } = new ThreadSafeObjectPool<T>();

public T Get()
{
lock (_lock)
lock (_stack)
{
if(_stack.Count == 0)
return new T();
Expand Down

0 comments on commit 4f3fa13

Please sign in to comment.