From 15bc68944779e23d94bfe14982217316d46385c2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 16 May 2022 07:54:27 +0200 Subject: [PATCH 1/3] Use Task.Run instead ThreadPool.QueueUserWorkItem --- src/TextMateSharp/Model/TMModel.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/TextMateSharp/Model/TMModel.cs b/src/TextMateSharp/Model/TMModel.cs index e742cd4..8a58381 100644 --- a/src/TextMateSharp/Model/TMModel.cs +++ b/src/TextMateSharp/Model/TMModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using System.Threading.Tasks; using TextMateSharp.Grammars; @@ -38,6 +39,7 @@ class TokenizerThread private string name; private TMModel model; private TMState lastState; + private Task task; public TokenizerThread(string name, TMModel model) { @@ -50,15 +52,18 @@ public void Run() { IsStopped = false; - ThreadPool.QueueUserWorkItem(ThreadWorker); + task = Task.Run(ThreadWorker); } public void Stop() { IsStopped = true; + this.model._resetEvent.Set(); + task.Wait(TimeSpan.FromSeconds(1)); + task.Dispose(); } - void ThreadWorker(object state) + void ThreadWorker() { if (IsStopped) { @@ -329,7 +334,6 @@ private void Stop() } this._thread.Stop(); - _resetEvent.Set(); this._thread = null; } From a3fab0a12a8e93f714f43ae3b3fc4b410c3a7b84 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 16 May 2022 08:01:10 +0200 Subject: [PATCH 2/3] Protect NRE if a call to Stop() is performed without calling Start() --- src/TextMateSharp/Model/TMModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TextMateSharp/Model/TMModel.cs b/src/TextMateSharp/Model/TMModel.cs index 8a58381..398d08c 100644 --- a/src/TextMateSharp/Model/TMModel.cs +++ b/src/TextMateSharp/Model/TMModel.cs @@ -59,8 +59,8 @@ public void Stop() { IsStopped = true; this.model._resetEvent.Set(); - task.Wait(TimeSpan.FromSeconds(1)); - task.Dispose(); + task?.Wait(TimeSpan.FromSeconds(1)); + task?.Dispose(); } void ThreadWorker() From 9f78d28418b51bb6ee90108c767561bcb94f0097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Pe=C3=B1alba?= Date: Sun, 23 Oct 2022 12:05:18 +0200 Subject: [PATCH 3/3] Add wasm dependencies --- .gitignore | 1 + .../Native/browser-wasm/libonigwrap.wasm | Bin 0 -> 801 bytes src/TextMateSharp/TextMateSharp.csproj | 12 ++++++++++++ 3 files changed, 13 insertions(+) create mode 100755 src/TextMateSharp/Internal/Oniguruma/Native/browser-wasm/libonigwrap.wasm diff --git a/.gitignore b/.gitignore index b1c9e89..3b8a782 100644 --- a/.gitignore +++ b/.gitignore @@ -381,3 +381,4 @@ onigwrap/src/onigwrap.lib onigwrap/src/onigwrap.exp onigwrap/src/onigwrap.dll onigwrap/src/onig_s.lib +onigwrap/src/libonigwrap.wasm diff --git a/src/TextMateSharp/Internal/Oniguruma/Native/browser-wasm/libonigwrap.wasm b/src/TextMateSharp/Internal/Oniguruma/Native/browser-wasm/libonigwrap.wasm new file mode 100755 index 0000000000000000000000000000000000000000..42d51b5bfc9953d578a6a239e08a1682bb7084df GIT binary patch literal 801 zcmZ{g&2G~`6ot>7aU3_35T^fT{&mSO8pD%c{CA7ZqK| zudZod@Bm5SrU*ikg!jn>bVfw2&yA#7)WZMfv{#Y7y8JB^SNwCd|Gek4>u>C4o4*qn z81t5COcJN5Ny=?r0HHB9&$F#bw@F;CwiyQga+#hNFA?6gn|VN0{jtwsCx>?AHMf_t~l+3Xa1d(Hmm@f!=-ZS*r+FrkIlX|6hDK(r1FGn}q+ zoA86@S>lLI8K0z<(E0Vj{X7q$uY5$9lJYQV4qO{h`y{FfXKQ`-dQ4M9q=smI-c;(V zK=)s9Fcqqe2_|Cg7D#spCE&gebRC2p{W0JcCl#lfT=Y|rti(J*4;mv9bB&p}3?8|w z6Ja>wzFjw>ya~eYOkfP|m)tZGZq-aY)p*il;PB3f85(Qo{G-Q>8{SMuf(N;+uUz_I z%oIw6y@>kizstmYXQ5_Tw_rN(aOlL4@v9LMwMmo=5-y literal 0 HcmV?d00001 diff --git a/src/TextMateSharp/TextMateSharp.csproj b/src/TextMateSharp/TextMateSharp.csproj index af613be..2d3c45b 100644 --- a/src/TextMateSharp/TextMateSharp.csproj +++ b/src/TextMateSharp/TextMateSharp.csproj @@ -33,6 +33,11 @@ TextMateSharp uses a wrapper around Oniguruma regex engine. Read below to learn PreserveNewest libonigwrap.dylib + + + PreserveNewest + libonigwrap.wasm + @@ -64,6 +69,13 @@ TextMateSharp uses a wrapper around Oniguruma regex engine. Read below to learn true PreserveNewest + + + libonigwrap.wasm + runtimes/browser-wasm/native/libonigwrap.wasm + true + PreserveNewest +