Skip to content

Commit ca7d9b6

Browse files
committed
Fix error with latest parking_lot version
1 parent 5f5478d commit ca7d9b6

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

Cargo.lock

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/src/stdlib/thread.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,17 @@ impl PyLock {
121121
}
122122
#[pymethod]
123123
#[pymethod(name = "release_lock")]
124-
fn release(&self) {
125-
self.mu.unlock()
124+
fn release(&self, vm: &VirtualMachine) -> PyResult<()> {
125+
if self.mu.is_locked() {
126+
return Err(vm.new_runtime_error("release unlocked lock".to_owned()));
127+
}
128+
unsafe { self.mu.unlock() };
129+
Ok(())
126130
}
127131

128132
#[pymethod(magic)]
129-
fn exit(&self, _args: PyFuncArgs) {
130-
self.release()
133+
fn exit(&self, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult<()> {
134+
self.release(vm)
131135
}
132136

133137
#[pymethod]
@@ -178,13 +182,17 @@ impl PyRLock {
178182
}
179183
#[pymethod]
180184
#[pymethod(name = "release_lock")]
181-
fn release(&self) {
182-
self.mu.unlock()
185+
fn release(&self, vm: &VirtualMachine) -> PyResult<()> {
186+
if self.mu.is_locked() {
187+
return Err(vm.new_runtime_error("release unlocked lock".to_owned()));
188+
}
189+
unsafe { self.mu.unlock() };
190+
Ok(())
183191
}
184192

185193
#[pymethod(magic)]
186-
fn exit(&self, _args: PyFuncArgs) {
187-
self.release()
194+
fn exit(&self, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult<()> {
195+
self.release(vm)
188196
}
189197

190198
#[pymethod(magic)]
@@ -237,7 +245,9 @@ fn thread_start_new_thread(
237245
}
238246
SENTINELS.with(|sents| {
239247
for lock in sents.replace(Default::default()) {
240-
lock.mu.unlock()
248+
if lock.mu.is_locked() {
249+
unsafe { lock.mu.unlock() };
250+
}
241251
}
242252
});
243253
vm.state.thread_count.fetch_sub(1);

0 commit comments

Comments
 (0)