From b67e8f2edc49ea9dd3428970b04c77aede344c59 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 10 Jul 2025 14:49:29 +0300 Subject: [PATCH] Move some code, just for more natural logical ordering --- pgxn/neon/communicator/src/backend_comms.rs | 58 ++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/pgxn/neon/communicator/src/backend_comms.rs b/pgxn/neon/communicator/src/backend_comms.rs index 998e0daf71..0423b4486e 100644 --- a/pgxn/neon/communicator/src/backend_comms.rs +++ b/pgxn/neon/communicator/src/backend_comms.rs @@ -111,35 +111,6 @@ pub enum NeonIOHandleState { Completed, } -pub struct RequestProcessingGuard<'a>(&'a NeonIOHandle); - -unsafe impl<'a> Send for RequestProcessingGuard<'a> {} -unsafe impl<'a> Sync for RequestProcessingGuard<'a> {} - -impl<'a> RequestProcessingGuard<'a> { - pub fn get_request(&self) -> &NeonIORequest { - unsafe { &*self.0.request.get() } - } - - pub fn get_owner_procno(&self) -> i32 { - self.0.owner_procno.load(Ordering::Relaxed) - } - - pub fn completed(self, result: NeonIOResult) { - unsafe { - *self.0.result.get() = result; - }; - - // Ok, we have completed the IO. Mark the request as completed. After that, - // we no longer have ownership of the slot, and must not modify it. - let old_state = self - .0 - .state - .swap(NeonIOHandleState::Completed, Ordering::Release); - assert!(old_state == NeonIOHandleState::Processing); - } -} - impl NeonIOHandle { pub fn fill_request(&self, request: &NeonIORequest, proc_number: i32) { // Verify that the slot is in Idle state previously, and start filling it. @@ -205,3 +176,32 @@ impl NeonIOHandle { Some(RequestProcessingGuard(self)) } } + +pub struct RequestProcessingGuard<'a>(&'a NeonIOHandle); + +unsafe impl<'a> Send for RequestProcessingGuard<'a> {} +unsafe impl<'a> Sync for RequestProcessingGuard<'a> {} + +impl<'a> RequestProcessingGuard<'a> { + pub fn get_request(&self) -> &NeonIORequest { + unsafe { &*self.0.request.get() } + } + + pub fn get_owner_procno(&self) -> i32 { + self.0.owner_procno.load(Ordering::Relaxed) + } + + pub fn completed(self, result: NeonIOResult) { + unsafe { + *self.0.result.get() = result; + }; + + // Ok, we have completed the IO. Mark the request as completed. After that, + // we no longer have ownership of the slot, and must not modify it. + let old_state = self + .0 + .state + .swap(NeonIOHandleState::Completed, Ordering::Release); + assert!(old_state == NeonIOHandleState::Processing); + } +}