aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/GetTheLights.cpp
blob: 6e78b546ab58702be5564d32e6a4a82acbc36d5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#include <aws/core/utils/GetTheLights.h>
#include <cassert>

namespace Aws
{
    namespace Utils
    {
        GetTheLights::GetTheLights() : m_value(0)
        {
        }

        void GetTheLights::EnterRoom(std::function<void()> &&callable)
        {
            int cpy = ++m_value;
            assert(cpy > 0);
            if(cpy == 1)
            {
                callable();
            }
        }

        void GetTheLights::LeaveRoom(std::function<void()> &&callable)
        {
            int cpy = --m_value;
            assert(cpy >= 0);
            if(cpy == 0)
            {
                callable();
            }
        }
    }
}