#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
use std::cell::Cell;
#[cfg(feature = "apcu-intercept")]
pub(crate) mod apcu_clear_cache;
#[cfg(feature = "apcu-intercept")]
pub(crate) mod apcu_delete;
#[cfg(feature = "opcache-intercept")]
pub(crate) mod opcache_invalidate;
#[cfg(feature = "opcache-intercept")]
pub(crate) mod opcache_reset;
pub(crate) mod putenv;
pub(crate) mod sleep;
pub(crate) fn ensure_cache_invalidation_intercepts_for_current_thread() {
#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
{
if crate::bus::bus().is_none() {
return;
}
#[cfg(feature = "apcu-intercept")]
{
apcu_delete::ensure_apcu_delete_intercept_for_current_thread();
apcu_clear_cache::ensure_apcu_clear_cache_intercept_for_current_thread();
}
#[cfg(feature = "opcache-intercept")]
{
opcache_reset::ensure_opcache_reset_intercept_for_current_thread();
opcache_invalidate::ensure_opcache_invalidate_intercept_for_current_thread();
}
}
}
pub(crate) fn pre_execute_work_hooks() {
#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
{
if crate::bus::bus().is_none() {
return;
}
#[cfg(feature = "apcu-intercept")]
{
apcu_delete::drain_apply_queue();
apcu_clear_cache::drain_apply_queue();
}
#[cfg(feature = "opcache-intercept")]
{
opcache_reset::drain_apply_queue();
opcache_invalidate::drain_apply_queue();
}
}
}
#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
thread_local! {
static BROADCAST_REPLAY: Cell<bool> = const { Cell::new(false) };
}
#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
pub(crate) fn with_replay_guard<R, F: FnOnce() -> R>(f: F) -> R {
struct Guard(bool);
impl Drop for Guard {
fn drop(&mut self) {
BROADCAST_REPLAY.with(|c| c.set(self.0));
}
}
let previous = BROADCAST_REPLAY.with(|c| c.replace(true));
let _g = Guard(previous);
f()
}
#[cfg(any(feature = "apcu-intercept", feature = "opcache-intercept"))]
pub(crate) fn replay_in_progress() -> bool {
BROADCAST_REPLAY.with(Cell::get)
}