GetTheLights.cpp 769 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/core/utils/GetTheLights.h>
  6. #include <cassert>
  7. namespace Aws
  8. {
  9. namespace Utils
  10. {
  11. GetTheLights::GetTheLights() : m_value(0)
  12. {
  13. }
  14. void GetTheLights::EnterRoom(std::function<void()> &&callable)
  15. {
  16. int cpy = ++m_value;
  17. assert(cpy > 0);
  18. if(cpy == 1)
  19. {
  20. callable();
  21. }
  22. }
  23. void GetTheLights::LeaveRoom(std::function<void()> &&callable)
  24. {
  25. int cpy = --m_value;
  26. assert(cpy >= 0);
  27. if(cpy == 0)
  28. {
  29. callable();
  30. }
  31. }
  32. }
  33. }