57 lines · c
1//===--- rtsan_context.h - Realtime Sanitizer -------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9//===----------------------------------------------------------------------===//10 11#pragma once12 13namespace __rtsan {14 15class Context {16public:17 Context();18 19 void RealtimePush();20 void RealtimePop();21 22 void BypassPush();23 void BypassPop();24 25 bool InRealtimeContext() const;26 bool IsBypassed() const;27 28 Context(const Context &) = delete;29 Context(Context &&) = delete;30 Context &operator=(const Context &) = delete;31 Context &operator=(Context &&) = delete;32 33private:34 int realtime_depth_{0};35 int bypass_depth_{0};36};37 38class ScopedBypass {39public:40 [[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) {41 context_.BypassPush();42 }43 44 ~ScopedBypass() { context_.BypassPop(); }45 46 ScopedBypass(const ScopedBypass &) = delete;47 ScopedBypass &operator=(const ScopedBypass &) = delete;48 ScopedBypass(ScopedBypass &&) = delete;49 ScopedBypass &operator=(ScopedBypass &&) = delete;50 51private:52 Context &context_;53};54 55Context &GetContextForThisThread();56} // namespace __rtsan57