aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/time_provider/monotonic_provider.cpp
blob: 6b116a0e73ba176002d080521ebf4f16f84e270f (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
#include "monotonic_provider.h"

namespace NMonotonic {

    namespace {
        TIntrusivePtr<IMonotonicTimeProvider> GlobalMonotonicTimeProvider;
    }

    void TMonotonicOperator::RegisterProvider(TIntrusivePtr<IMonotonicTimeProvider> provider) {
        GlobalMonotonicTimeProvider = provider;
    }

    NMonotonic::TMonotonic TMonotonicOperator::Now() {
        if (GlobalMonotonicTimeProvider) {
            return GlobalMonotonicTimeProvider->Now();
        } else {
            return TMonotonic::Now();
        }
    }

    class TDefaultMonotonicTimeProvider: public IMonotonicTimeProvider {
    public:
        TMonotonic Now() override {
            return TMonotonic::Now();
        }
    };

    TIntrusivePtr<IMonotonicTimeProvider> CreateDefaultMonotonicTimeProvider() {
        return TIntrusivePtr<IMonotonicTimeProvider>(new TDefaultMonotonicTimeProvider);
    }

}