Skip to main content

khora_lanes/render_lane/util/
mod.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Internal helpers for render-lane implementations.
16
17pub mod lock;
18
19pub use lock::{mutex_lock, read_lock, write_lock};
20
21/// Lock helper for callers that cannot propagate `Result<_, LaneError>`.
22///
23/// Returns the guard on success; on poisoning logs an error and
24/// `return`s from the surrounding function. The optional second form
25/// returns a caller-provided default value (for non-`()` returning
26/// functions).
27///
28/// ```ignore
29/// let mut res = lock_or_log!(self.gpu_resources.lock(), "MyLane::render");
30/// let assets = lock_or_log!(meshes.read(), "MyLane::cost", 0.0);
31/// ```
32#[macro_export]
33macro_rules! lock_or_log {
34    ($expr:expr, $ctx:literal) => {
35        match $expr {
36            Ok(g) => g,
37            Err(_) => {
38                log::error!("{}: lock poisoned", $ctx);
39                return;
40            }
41        }
42    };
43    ($expr:expr, $ctx:literal, $default:expr) => {
44        match $expr {
45            Ok(g) => g,
46            Err(_) => {
47                log::error!("{}: lock poisoned", $ctx);
48                return $default;
49            }
50        }
51    };
52}