suspendable_thread_delegate.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_H_
  5. #define BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_H_
  6. #include <vector>
  7. #include "base/base_export.h"
  8. #include "base/profiler/register_context.h"
  9. #include "base/profiler/thread_delegate.h"
  10. namespace base {
  11. // Platform-specific thread and stack manipulation delegate, for use by the
  12. // platform-independent stack copying/walking implementation in
  13. // StackSamplerImpl for suspension-based stack copying.
  14. //
  15. // IMPORTANT NOTE: Most methods in this interface are invoked while the target
  16. // thread is suspended so must not do any allocation from the heap, including
  17. // indirectly via use of DCHECK/CHECK or other logging statements. Otherwise the
  18. // implementation can deadlock on heap locks acquired by the target thread
  19. // before it was suspended. These functions are commented with "NO HEAP
  20. // ALLOCATIONS".
  21. class BASE_EXPORT SuspendableThreadDelegate : public ThreadDelegate {
  22. public:
  23. // Implementations of this interface should suspend the thread for the
  24. // object's lifetime. NO HEAP ALLOCATIONS between the time the thread is
  25. // suspended and resumed.
  26. class BASE_EXPORT ScopedSuspendThread {
  27. public:
  28. ScopedSuspendThread() = default;
  29. virtual ~ScopedSuspendThread() = default;
  30. ScopedSuspendThread(const ScopedSuspendThread&) = delete;
  31. ScopedSuspendThread& operator=(const ScopedSuspendThread&) = delete;
  32. virtual bool WasSuccessful() const = 0;
  33. };
  34. SuspendableThreadDelegate() = default;
  35. // Creates an object that holds the thread suspended for its lifetime.
  36. virtual std::unique_ptr<ScopedSuspendThread> CreateScopedSuspendThread() = 0;
  37. // Gets the register context for the thread.
  38. // NO HEAP ALLOCATIONS.
  39. virtual bool GetThreadContext(RegisterContext* thread_context) = 0;
  40. // Returns true if the thread's stack can be copied, where the bottom address
  41. // of the thread is at |stack_pointer|.
  42. // NO HEAP ALLOCATIONS.
  43. virtual bool CanCopyStack(uintptr_t stack_pointer) = 0;
  44. };
  45. } // namespace base
  46. #endif // BASE_PROFILER_SUSPENDABLE_THREAD_DELEGATE_H_