regorus/utils/limits/
mod.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Helpers for cooperative execution time and memory limits.
5
6#![allow(dead_code)]
7
8mod error;
9#[cfg(feature = "allocator-memory-limits")]
10mod memory;
11mod time;
12
13#[allow(unused_imports)]
14pub use error::LimitError;
15
16#[allow(unused_imports)]
17#[cfg(feature = "allocator-memory-limits")]
18pub use memory::{
19    check_global_memory_limit, enforce_memory_limit, flush_thread_memory_counters,
20    global_memory_limit, set_global_memory_limit, set_thread_flush_threshold_override,
21    thread_memory_flush_threshold,
22};
23
24#[allow(unused_imports)]
25pub use time::{
26    fallback_execution_timer_config, monotonic_now, set_fallback_execution_timer_config,
27    ExecutionTimer, ExecutionTimerConfig, TimeSource,
28};
29
30#[cfg(test)]
31pub use time::acquire_limits_test_lock;
32
33#[cfg(any(test, not(feature = "std")))]
34#[allow(unused_imports)]
35pub use time::{set_time_source, TimeSourceRegistrationError};
36
37#[cfg(feature = "allocator-memory-limits")]
38#[inline]
39pub fn check_memory_limit_if_needed() -> core::result::Result<(), LimitError> {
40    memory::check_memory_limit_if_needed()
41}
42
43#[cfg(not(feature = "allocator-memory-limits"))]
44#[inline]
45pub const fn enforce_memory_limit() -> core::result::Result<(), LimitError> {
46    Ok(())
47}
48
49#[cfg(not(feature = "allocator-memory-limits"))]
50#[inline]
51pub const fn check_memory_limit_if_needed() -> core::result::Result<(), LimitError> {
52    Ok(())
53}