| // Copyright 2020 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef SRC_DEVELOPER_DEBUG_DEBUG_AGENT_MOCK_SUSPEND_HANDLE_H_ | |
| #define SRC_DEVELOPER_DEBUG_DEBUG_AGENT_MOCK_SUSPEND_HANDLE_H_ | |
| #include <lib/fit/function.h> | |
| #include <lib/syslog/cpp/macros.h> | |
| #include <memory> | |
| #include "src/developer/debug/debug_agent/suspend_handle.h" | |
| namespace debug_agent { | |
| // This mock handle adjusts a shared counter in MockThreadHandle or MockProcessHandle::Suspend() to | |
| // indicate suspension. | |
| class MockSuspendHandle : public SuspendHandle { | |
| public: | |
| explicit MockSuspendHandle(std::shared_ptr<int> count, fit::closure on_destroy = {}) | |
| : count_(std::move(count)), on_destroy_(std::move(on_destroy)) { | |
| FX_DCHECK(*count_ >= 0); | |
| ++(*count_); | |
| } | |
| ~MockSuspendHandle() override { | |
| FX_CHECK(*count_ > 0); | |
| --(*count_); | |
| if (on_destroy_) { | |
| on_destroy_(); | |
| } | |
| } | |
| private: | |
| std::shared_ptr<int> count_; | |
| fit::closure on_destroy_; | |
| }; | |
| } // namespace debug_agent | |
| #endif // SRC_DEVELOPER_DEBUG_DEBUG_AGENT_MOCK_SUSPEND_HANDLE_H_ |