[Lldb-commits] [lldb] [lldb-dap] Implement a MemoryMonitor for macOS & Linux (PR #129332)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 28 14:41:44 PST 2025
================
@@ -0,0 +1,114 @@
+//===-- MemoryMonitor.cpp -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MemoryMonitor.h"
+#include "llvm/ADT/ScopeExit.h"
+#include <atomic>
+#include <cstdio>
+#include <cstring>
+#include <thread>
+
+#if defined(__APPLE__)
+#include <dispatch/dispatch.h>
+#endif
+
+#if defined(__linux__)
+#include <fcntl.h>
+#include <poll.h>
+#include <unistd.h>
+#endif
+
+using namespace lldb_dap;
+
+#if defined(__APPLE__)
+class MemoryMonitorDarwin : public MemoryMonitor {
+ using MemoryMonitor::MemoryMonitor;
+ void Start() override {
+ m_memory_pressure_source = dispatch_source_create(
+ DISPATCH_SOURCE_TYPE_MEMORYPRESSURE,
+ 0, // system-wide monitoring
+ DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL,
+ dispatch_get_main_queue());
----------------
ashgti wrote:
Do we call `dispatch_main` anywhere?
I don't know which thread would be considered the 'main' thread. I can't find if thats called in lldb.
I think we need that to be called for this queue to exist, right?
https://github.com/llvm/llvm-project/pull/129332
More information about the lldb-commits
mailing list