diff --git a/Fuyu.Common/Collections/ThreadDictionary.cs b/Fuyu.Common/Collections/ThreadDictionary.cs index 423a409d..d3afb00a 100644 --- a/Fuyu.Common/Collections/ThreadDictionary.cs +++ b/Fuyu.Common/Collections/ThreadDictionary.cs @@ -1,4 +1,9 @@ using System.Collections.Generic; +#if NET9_0_OR_GREATER +using Lock = System.Threading.Lock; +#else +using Lock = object; +#endif namespace Fuyu.Common.Collections; @@ -10,18 +15,18 @@ namespace Fuyu.Common.Collections; public class ThreadDictionary { private readonly Dictionary _dictionary; - private readonly object _lock; + private readonly Lock _lock; public ThreadDictionary() { _dictionary = new Dictionary(); - _lock = new object(); + _lock = new Lock(); } public ThreadDictionary(IDictionary enumerable) { _dictionary = new Dictionary(enumerable); - _lock = new object(); + _lock = new Lock(); } public Dictionary ToDictionary() diff --git a/Fuyu.Common/Collections/ThreadList.cs b/Fuyu.Common/Collections/ThreadList.cs index cd3d2bc5..862c9cc8 100644 --- a/Fuyu.Common/Collections/ThreadList.cs +++ b/Fuyu.Common/Collections/ThreadList.cs @@ -1,4 +1,9 @@ using System.Collections.Generic; +#if NET9_0_OR_GREATER +using Lock = System.Threading.Lock; +#else +using Lock = object; +#endif namespace Fuyu.Common.Collections; @@ -11,12 +16,12 @@ namespace Fuyu.Common.Collections; public class ThreadList { private readonly List _list; - private readonly object _lock; + private readonly Lock _lock; public ThreadList() { _list = new List(); - _lock = new object(); + _lock = new Lock(); } public List ToList() diff --git a/Fuyu.Common/Collections/ThreadObject.cs b/Fuyu.Common/Collections/ThreadObject.cs index 7f2690e5..28b02f0a 100644 --- a/Fuyu.Common/Collections/ThreadObject.cs +++ b/Fuyu.Common/Collections/ThreadObject.cs @@ -1,14 +1,19 @@ namespace Fuyu.Common.Collections; +#if NET9_0_OR_GREATER +using Lock = System.Threading.Lock; +#else +using Lock = object; +#endif public class ThreadObject { private T _object; - private readonly object _lock; + private readonly Lock _lock; public ThreadObject(T value) { _object = value; - _lock = new object(); + _lock = new Lock(); } public T Get() diff --git a/Fuyu.Common/IO/Terminal.cs b/Fuyu.Common/IO/Terminal.cs index a6c999d2..2133a834 100644 --- a/Fuyu.Common/IO/Terminal.cs +++ b/Fuyu.Common/IO/Terminal.cs @@ -1,10 +1,15 @@ using System; +#if NET9_0_OR_GREATER +using Lock = System.Threading.Lock; +#else +using Lock = object; +#endif namespace Fuyu.Common.IO; public static class Terminal { - private static readonly object _lock = new object(); + private static readonly Lock _lock = new Lock(); private static string _filepath; static Terminal() diff --git a/Fuyu.Common/IO/VFS.cs b/Fuyu.Common/IO/VFS.cs index ee929714..9214aba7 100644 --- a/Fuyu.Common/IO/VFS.cs +++ b/Fuyu.Common/IO/VFS.cs @@ -1,16 +1,21 @@ using System; using System.Collections.Concurrent; using System.IO; +#if NET9_0_OR_GREATER +using Lock = System.Threading.Lock; +#else +using Lock = object; +#endif namespace Fuyu.Common.IO; public static class VFS { - private static readonly ConcurrentDictionary _writeLock; + private static readonly ConcurrentDictionary _writeLock; static VFS() { - _writeLock = new ConcurrentDictionary(); + _writeLock = new ConcurrentDictionary(); } public static string GetWorkingDirectory() @@ -116,7 +121,7 @@ public static void WriteTextFile(string filepath, string text, bool append = fal } // get thread lock - _writeLock.TryAdd(filepath, new object()); + _writeLock.TryAdd(filepath, new Lock()); // write text lock (_writeLock[filepath])