aboutsummaryrefslogtreecommitdiff
path: root/include/perfetto/base/task_runner.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/perfetto/base/task_runner.h')
-rw-r--r--include/perfetto/base/task_runner.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/perfetto/base/task_runner.h b/include/perfetto/base/task_runner.h
index cf6040123..3b80bbb2a 100644
--- a/include/perfetto/base/task_runner.h
+++ b/include/perfetto/base/task_runner.h
@@ -19,11 +19,18 @@
#include <functional>
+#include "perfetto/base/build_config.h"
#include "perfetto/base/export.h"
+#include "perfetto/base/utils.h"
+#include "perfetto/base/watchdog.h"
namespace perfetto {
namespace base {
+// Maximum time a single task can take in a TaskRunner before the
+// program suicides.
+constexpr int64_t kWatchdogMillis = 30000; // 30s
+
// A generic interface to allow the library clients to interleave the execution
// of the tracing internals in their runtime environment.
// The expectation is that all tasks, which are queued either via PostTask() or
@@ -66,6 +73,13 @@ class PERFETTO_EXPORT TaskRunner {
// thread/sequence. This can allow some callers to skip PostTask and instead
// directly execute the code. Can be called from any thread.
virtual bool RunsTasksOnCurrentThread() const = 0;
+
+ protected:
+ static void RunTask(const std::function<void()>& task) {
+ Watchdog::Timer handle =
+ base::Watchdog::GetInstance()->CreateFatalTimer(kWatchdogMillis);
+ task();
+ }
};
} // namespace base