Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
8a34d2f4
Unverified
Commit
8a34d2f4
authored
Jul 26, 2019
by
Vinicius Jarina
Committed by
GitHub
Jul 26, 2019
Browse files
Use `ConcurrentQueue` due a race condition. (#311)
parent
be037f73
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/ObjectTranslator.cs
View file @
8a34d2f4
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.IO
;
using
System.IO
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Collections.Concurrent
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
KeraLua
;
using
KeraLua
;
...
@@ -50,7 +51,7 @@ namespace NLua
...
@@ -50,7 +51,7 @@ namespace NLua
// object # to object (FIXME - it should be possible to get object address as an object #)
// object # to object (FIXME - it should be possible to get object address as an object #)
readonly
Dictionary
<
int
,
object
>
_objects
=
new
Dictionary
<
int
,
object
>();
readonly
Dictionary
<
int
,
object
>
_objects
=
new
Dictionary
<
int
,
object
>();
readonly
Queue
<
int
>
finalizedReferences
=
new
Queue
<
int
>();
readonly
Concurrent
Queue
<
int
>
finalizedReferences
=
new
Concurrent
Queue
<
int
>();
internal
EventHandlerContainer
PendingEvents
=
new
EventHandlerContainer
();
internal
EventHandlerContainer
PendingEvents
=
new
EventHandlerContainer
();
MetaFunctions
metaFunctions
;
MetaFunctions
metaFunctions
;
...
@@ -1136,11 +1137,10 @@ namespace NLua
...
@@ -1136,11 +1137,10 @@ namespace NLua
if
(
finalizedReferences
.
Count
==
0
)
if
(
finalizedReferences
.
Count
==
0
)
return
;
return
;
while
(
finalizedReferences
.
Count
!=
0
)
int
reference
;
{
int
reference
=
finalizedReferences
.
Dequeue
()
;
while
(
finalizedReferences
.
Try
Dequeue
(
out
reference
)
)
state
.
Unref
(
LuaRegistry
.
Index
,
reference
);
state
.
Unref
(
LuaRegistry
.
Index
,
reference
);
}
}
}
}
}
}
}
tests/src/LuaTests.cs
View file @
8a34d2f4
...
@@ -2384,7 +2384,7 @@ namespace NLuaTest
...
@@ -2384,7 +2384,7 @@ namespace NLuaTest
void
PleaseRunFinalizers
()
void
PleaseRunFinalizers
()
{
{
for
(
int
i
=
0
;
i
<
2
0
;
i
++)
for
(
int
i
=
0
;
i
<
4
0
;
i
++)
{
{
GC
.
Collect
();
GC
.
Collect
();
GC
.
WaitForPendingFinalizers
();
GC
.
WaitForPendingFinalizers
();
...
@@ -2412,6 +2412,7 @@ namespace NLuaTest
...
@@ -2412,6 +2412,7 @@ namespace NLuaTest
ImplicitlyCreateATable
(
lua
);
ImplicitlyCreateATable
(
lua
);
lua
.
State
.
GarbageCollector
(
LuaGC
.
Collect
,
0
);
lua
.
State
.
GarbageCollector
(
LuaGC
.
Collect
,
0
);
lua
.
State
.
GarbageCollector
(
LuaGC
.
Collect
,
0
);
int
after2
=
lua
.
State
.
GarbageCollector
(
LuaGC
.
Count
,
0
);
int
after2
=
lua
.
State
.
GarbageCollector
(
LuaGC
.
Count
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment