1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/main/valid_checker.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/constants.hpp"
12#include "duckdb/common/atomic.hpp"
13#include "duckdb/common/mutex.hpp"
14
15namespace duckdb {
16class DatabaseInstance;
17class MetaTransaction;
18
19class ValidChecker {
20public:
21 ValidChecker();
22
23 DUCKDB_API static ValidChecker &Get(DatabaseInstance &db);
24 DUCKDB_API static ValidChecker &Get(MetaTransaction &transaction);
25
26 DUCKDB_API void Invalidate(string error);
27 DUCKDB_API bool IsInvalidated();
28 DUCKDB_API string InvalidatedMessage();
29
30 template <class T>
31 static bool IsInvalidated(T &o) {
32 return Get(o).IsInvalidated();
33 }
34 template <class T>
35 static void Invalidate(T &o, string error) {
36 Get(o).Invalidate(std::move(error));
37 }
38
39 template <class T>
40 static string InvalidatedMessage(T &o) {
41 return Get(o).InvalidatedMessage();
42 }
43
44private:
45 //! Set to true if a fatal exception has occurred
46 mutex invalidate_lock;
47 atomic<bool> is_invalidated;
48 string invalidated_msg;
49};
50
51} // namespace duckdb
52