11#if defined(__linux__) || defined(__gnu_linux__)
21static std::atomic<bool> g_override_availMem{
false};
22static std::atomic<AvailMemFunc> g_real_availMem(
nullptr);
24static std::once_flag g_init_flag;
26static void init_real_availMem() {
29 std::call_once(g_init_flag, []() {
31 char const *
const mangled =
"_ZNK6Mantid6Kernel11MemoryStats8availMemEv";
32 void *sym = dlsym(RTLD_NEXT, mangled);
35 sym = dlsym(RTLD_DEFAULT, mangled);
38 g_real_availMem.store(
reinterpret_cast<AvailMemFunc
>(sym));
48 g_override_availMem.store(
true);
58 if (g_override_availMem.load()) {
59 return g_value.load();
62 if (g_real_availMem.load()) {
63 return g_real_availMem.load()(
this);
66 throw std::runtime_error(
"Failed to reset the MemoryStats patch by name lookup");
72 if (g_override_availMem.load()) {
73 std::size_t avail = g_value.load();
74 if (requestedMemory > avail) {
75 return "Mock Memory Failure";
81 if (g_real_availMem.load()) {
83 std::size_t avail = g_real_availMem.load()(
this) * 1024;
84 if (requestedMemory > avail) {
91 throw std::runtime_error(
"Failed to reset the MemoryStats patch by name lookup");
double value
The value of the point.
This class is responsible for memory statistics.
std::string checkAvailableMemory(std::size_t const requestedMemoryBytes) const
Check if there is enough space in memory to hold the requested amount of memory.
std::size_t availMem() const
Returns the available memory of the system in kiB.
void disable_mem_override()
void enable_mem_override(std::size_t value=g_default_value)
constexpr std::size_t g_default_value
std::string to_string(const wide_integer< Bits, Signed > &n)