Skip to content

Commit

Permalink
Do not require Lua to be alive when dropping AsyncThread
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Aug 22, 2024
1 parent d2e8794 commit 8092f00
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,17 @@ impl<R> AsyncThread<R> {
impl<R> Drop for AsyncThread<R> {
fn drop(&mut self) {
if self.recycle {
unsafe {
let lua = self.thread.0.lua.lock();
// For Lua 5.4 this also closes all pending to-be-closed variables
if !lua.recycle_thread(&mut self.thread) {
#[cfg(feature = "lua54")]
if self.thread.status_inner(&lua) == ThreadStatus::Error {
#[cfg(not(feature = "vendored"))]
ffi::lua_resetthread(self.thread.state());
#[cfg(feature = "vendored")]
ffi::lua_closethread(self.thread.state(), lua.state());
if let Some(lua) = self.thread.0.lua.try_lock() {
unsafe {
// For Lua 5.4 this also closes all pending to-be-closed variables
if !lua.recycle_thread(&mut self.thread) {
#[cfg(feature = "lua54")]
if self.thread.status_inner(&lua) == ThreadStatus::Error {
#[cfg(not(feature = "vendored"))]
ffi::lua_resetthread(self.thread.state());
#[cfg(feature = "vendored")]
ffi::lua_closethread(self.thread.state(), lua.state());
}
}
}
}
Expand Down

0 comments on commit 8092f00

Please sign in to comment.