libDwm-0.9.45
DwmPacer.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 1998-2007, 2016
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMPACER_HH_
42#define _DWMPACER_HH_
43
44#include "DwmTimeValue.hh"
45
46namespace Dwm {
47
48 //--------------------------------------------------------------------------
54 //--------------------------------------------------------------------------
55 class Pacer
56 {
57 public:
58 //------------------------------------------------------------------------
60 //------------------------------------------------------------------------
61 Pacer(uint32_t rate);
62
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
66 uint32_t Rate() const;
67
68 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
71 uint32_t Rate(uint32_t rate);
72
73 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 void Pace();
80
81 private:
82 uint32_t _rate;
83 TimeValue _nextTime;
84 TimeValue _interval;
85
86 static TimeValue _minSleep;
87 void SetMinSleep();
88 };
89
90} // namespace Dwm
91
92#endif // _DWMPACER_HH_
93
94//---------------------------- emacs settings -----------------------------
95// Local Variables:
96// mode: C++
97// tab-width: 2
98// indent-tabs-mode: nil
99// c-basic-offset: 2
100// End:
101//-------------------------------------------------------------------------
Dwm::TimeValue class definition.
This class permits throttling of functions to a max number of repetitions per second.
Definition DwmPacer.hh:56
uint32_t Rate() const
Returns the rate (reps per second).
void Pace()
This should be called between each call you wish to throttle.
Pacer(uint32_t rate)
Construct with the given rate (reps per second).
uint32_t Rate(uint32_t rate)
Sets the rate (reps per second).
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue.hh:68