1 // @file elapsed_tracker.h 2 3 4 /** 5 * Copyright (C) 2018-present MongoDB, Inc. 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the Server Side Public License, version 1, 9 * as published by MongoDB, Inc. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * Server Side Public License for more details. 15 * 16 * You should have received a copy of the Server Side Public License 17 * along with this program. If not, see 18 * <http://www.mongodb.com/licensing/server-side-public-license>. 19 * 20 * As a special exception, the copyright holders give permission to link the 21 * code of portions of this program with the OpenSSL library under certain 22 * conditions as described in each individual source file and distribute 23 * linked combinations including the program with the OpenSSL library. You 24 * must comply with the Server Side Public License in all respects for 25 * all of the code used other than as permitted herein. If you modify file(s) 26 * with this exception, you may extend this exception to your version of the 27 * file(s), but you are not obligated to do so. If you do not wish to do so, 28 * delete this exception statement from your version. If you delete this 29 * exception statement from all source files in the program, then also delete 30 * it in the license file. 31 */ 32 33 #pragma once 34 35 #include <cstdint> 36 37 #include "mongo/util/time_support.h" 38 39 namespace mongo { 40 41 class ClockSource; 42 43 /** Keep track of elapsed time. After a set amount of time, tells you to do something. */ 44 class ElapsedTracker { 45 public: 46 ElapsedTracker(ClockSource* cs, int32_t hitsBetweenMarks, Milliseconds msBetweenMarks); 47 48 /** 49 * Call this for every iteration. 50 * @return true if one of the triggers has gone off. 51 */ 52 bool intervalHasElapsed(); 53 54 void resetLastTime(); 55 56 private: 57 ClockSource* const _clock; 58 const int32_t _hitsBetweenMarks; 59 const Milliseconds _msBetweenMarks; 60 61 int32_t _pings; 62 63 Date_t _last; 64 }; 65 66 } // namespace mongo 67