================
@@ -0,0 +1,102 @@
+//===-- ThreadPlanSingleThreadTimeout.h -------------------------*- C++ 
-*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include <thread>
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and gets reset by each internal
+// stop to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan may be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.
+//
+class ThreadPlanSingleThreadTimeout : public ThreadPlan {
+  enum class State {
+    WaitTimeout,    // Waiting for timeout.
+    AsyncInterrupt, // Async interrupt has been issued.
+    Done,           // Finished resume all threads.
+  };
+
+public:
+  struct TimeoutInfo {
----------------
jimingham wrote:

This isn't something you need to do in this patch, but it would be good to 
allow different thread plan invocations to use different timeouts, and not just 
depend on the thread timeout.  For instance, we should be able to reimplement 
RunThreadPlan with this infrastructure.  But the timeouts you want for 
expression evaluation and stepping are likely to be very different (and 
different executions also use different timeouts).  So being able to pass in 
the timeout, rather than relying on one thread specific one will be necessary.  
We could for instance add the timeout to the TimeoutInfo and plumb that so that 
the ThreadPlan that mixes in TimeoutResumeAll can pass in a timeout.

https://github.com/llvm/llvm-project/pull/90930
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to