monotonic_provider.cpp 887 B

1234567891011121314151617181920212223242526272829303132
  1. #include "monotonic_provider.h"
  2. namespace NMonotonic {
  3. namespace {
  4. TIntrusivePtr<IMonotonicTimeProvider> GlobalMonotonicTimeProvider;
  5. }
  6. void TMonotonicOperator::RegisterProvider(TIntrusivePtr<IMonotonicTimeProvider> provider) {
  7. GlobalMonotonicTimeProvider = provider;
  8. }
  9. NMonotonic::TMonotonic TMonotonicOperator::Now() {
  10. if (GlobalMonotonicTimeProvider) {
  11. return GlobalMonotonicTimeProvider->Now();
  12. } else {
  13. return TMonotonic::Now();
  14. }
  15. }
  16. class TDefaultMonotonicTimeProvider: public IMonotonicTimeProvider {
  17. public:
  18. TMonotonic Now() override {
  19. return TMonotonic::Now();
  20. }
  21. };
  22. TIntrusivePtr<IMonotonicTimeProvider> CreateDefaultMonotonicTimeProvider() {
  23. return TIntrusivePtr<IMonotonicTimeProvider>(new TDefaultMonotonicTimeProvider);
  24. }
  25. }