/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #pragma once #include #include #include #include namespace Aws { namespace Utils { /** * A simple wrapper over std::atomic that captures atomic by reference and * increases-decreases it's count in constructor-destructor. * Optionally notifies all on conditional variable pointer if set and counter reaches 0. */ class AWS_CORE_API RAIICounter final { public: RAIICounter(std::atomic& iCount, std::condition_variable* cv = nullptr); ~RAIICounter(); RAIICounter(const RAIICounter&) = delete; RAIICounter(RAIICounter&&) = delete; RAIICounter& operator=(const RAIICounter&) = delete; RAIICounter& operator=(RAIICounter&&) = delete; protected: std::atomic& m_count; std::condition_variable* m_cv; }; } }