(&self, vm: &VirtualMachine)
| 221 | |
| 222 | #[pymethod] |
| 223 | fn release(&self, vm: &VirtualMachine) -> PyResult<()> { |
| 224 | if self.kind == RECURSIVE_MUTEX { |
| 225 | if !ismine!(self) { |
| 226 | return Err(vm.new_exception_msg( |
| 227 | vm.ctx.exceptions.assertion_error.to_owned(), |
| 228 | "attempt to release recursive lock not owned by thread".into(), |
| 229 | )); |
| 230 | } |
| 231 | if self.count.load(Ordering::Acquire) > 1 { |
| 232 | self.count.fetch_sub(1, Ordering::Release); |
| 233 | return Ok(()); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if unsafe { ReleaseSemaphore(self.handle.as_raw(), 1, core::ptr::null_mut()) } == 0 { |
| 238 | let err = unsafe { windows_sys::Win32::Foundation::GetLastError() }; |
| 239 | if err == ERROR_TOO_MANY_POSTS { |
| 240 | return Err(vm.new_value_error("semaphore or lock released too many times")); |
| 241 | } |
| 242 | return Err(vm.new_last_os_error()); |
| 243 | } |
| 244 | |
| 245 | self.count.fetch_sub(1, Ordering::Release); |
| 246 | Ok(()) |
| 247 | } |
| 248 | |
| 249 | #[pymethod(name = "__enter__")] |
| 250 | fn enter(&self, vm: &VirtualMachine) -> PyResult<bool> { |
no test coverage detected