8#ifndef INCLUDED_BDLMT_THROTTLE
9#define INCLUDED_BDLMT_THROTTLE
272#include <bdlscm_version.h>
286#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
287#include <bsl_chrono.h>
290#include <bsl_climits.h>
314 enum { k_BILLION = 1000 * 1000 * 1000 };
316 static const Int64 k_ALLOW_ALL = LLONG_MIN;
317 static const Int64 k_ALLOW_NONE = LLONG_MAX;
318 static const Int64 k_MAX_SECONDS = LLONG_MAX / k_BILLION;
319 static const Int64 k_MIN_SECONDS = LLONG_MIN / k_BILLION;
346 template <
int t_MAX_SIMULTANEOUS_ACTIONS,
376#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
396 const bsl::chrono::system_clock&);
417 const bsl::chrono::steady_clock&);
513template <
int t_MAX_SIMULTANEOUS_ACTIONS,
519 BSLMF_ASSERT(t_MAX_SIMULTANEOUS_ACTIONS || t_NANOSECONDS_PER_ACTION);
521 ? t_MAX_SIMULTANEOUS_ACTIONS
523 t_NANOSECONDS_PER_ACTION);
528 0 == t_MAX_SIMULTANEOUS_ACTIONS ? Throttle::k_ALLOW_NONE
529 : t_NANOSECONDS_PER_ACTION ? t_NANOSECONDS_PER_ACTION
530 : Throttle::k_ALLOW_ALL;
534 : t_MAX_SIMULTANEOUS_ACTIONS;
546#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
549 int maxSimultaneousActions,
550 Int64 nanosecondsPerAction,
551 const bsl::chrono::system_clock&)
560 int maxSimultaneousActions,
561 Int64 nanosecondsPerAction,
562 const bsl::chrono::steady_clock&)
620#define BDLMT_THROTTLE_INIT(maxSimultaneousActions, \
621 nanosecondsPerAction) { \
622 { -BloombergLP::bdlmt::Throttle::k_TEN_YEARS_NANOSECONDS }, \
623 BloombergLP::bdlmt::Throttle_InitHelper< \
624 (maxSimultaneousActions), \
625 (nanosecondsPerAction)>::k_npaValue, \
626 bsl::integral_constant<BloombergLP::bsls::Types::Int64, \
627 1LL * (maxSimultaneousActions) * (nanosecondsPerAction)>::value, \
628 BloombergLP::bdlmt::Throttle_InitHelper< \
629 (maxSimultaneousActions), \
630 (nanosecondsPerAction)>::k_msaValue, \
631 BloombergLP::bsls::SystemClockType::e_MONOTONIC \
634#define BDLMT_THROTTLE_INIT_REALTIME(maxSimultaneousActions, \
635 nanosecondsPerAction) { \
636 { -BloombergLP::bdlmt::Throttle::k_TEN_YEARS_NANOSECONDS }, \
637 BloombergLP::bdlmt::Throttle_InitHelper< \
638 (maxSimultaneousActions), \
639 (nanosecondsPerAction)>::k_npaValue, \
640 bsl::integral_constant<BloombergLP::bsls::Types::Int64, \
641 1LL * (maxSimultaneousActions) * (nanosecondsPerAction)>::value, \
642 BloombergLP::bdlmt::Throttle_InitHelper< \
643 (maxSimultaneousActions), \
644 (nanosecondsPerAction)>::k_msaValue, \
645 BloombergLP::bsls::SystemClockType::e_REALTIME \
648#define BDLMT_THROTTLE_INIT_ALLOW_ALL BDLMT_THROTTLE_INIT(1, 0)
649#define BDLMT_THROTTLE_INIT_ALLOW_NONE BDLMT_THROTTLE_INIT(0, 1)
655#define BDLMT_THROTTLE_IF(maxSimultaneousActions, \
656 nanosecondsPerAction) \
657 if (bool bdlmt_throttle_iFsToP = false) {} \
659 for (static BloombergLP::bdlmt::Throttle bdlmt_throttle_iFtHrOtTlE = \
660 BDLMT_THROTTLE_INIT((maxSimultaneousActions), \
661 (nanosecondsPerAction)); \
662 !bdlmt_throttle_iFsToP; \
663 bdlmt_throttle_iFsToP = true) \
664 if (bdlmt_throttle_iFtHrOtTlE.requestPermission())
666#define BDLMT_THROTTLE_IF_REALTIME(maxSimultaneousActions, \
667 nanosecondsPerAction) \
668 if (bool bdlmt_throttle_iFsToP = false) {} \
670 for (static BloombergLP::bdlmt::Throttle bdlmt_throttle_iFtHrOtTlE = \
671 BDLMT_THROTTLE_INIT_REALTIME((maxSimultaneousActions), \
672 (nanosecondsPerAction)); \
673 !bdlmt_throttle_iFsToP; \
674 bdlmt_throttle_iFsToP = true) \
675 if (bdlmt_throttle_iFtHrOtTlE.requestPermission())
677#define BDLMT_THROTTLE_IF_ALLOW_ALL BDLMT_THROTTLE_IF(1, 0)
678#define BDLMT_THROTTLE_IF_ALLOW_NONE BDLMT_THROTTLE_IF(0, 1)
Definition bdlmt_throttle.h:515
static const bsls::Types::Int64 k_npaValue
Definition bdlmt_throttle.h:527
static const int k_msaValue
Definition bdlmt_throttle.h:532
Definition bdlmt_throttle.h:306
bsls::SystemClockType::Enum d_clockType
Definition bdlmt_throttle.h:340
int maxSimultaneousActions() const
Definition bdlmt_throttle.h:605
void initialize(int maxSimultaneousActions, Int64 nanosecondsPerAction, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_MONOTONIC)
bool requestPermission(int numActions, const bsls::TimeInterval &now)
AtomicTypes::Int64 d_prevLeakTime
Definition bdlmt_throttle.h:327
Int64 d_nanosecondsPerTotalReset
Definition bdlmt_throttle.h:333
int d_maxSimultaneousActions
Definition bdlmt_throttle.h:336
int nextPermit(bsls::TimeInterval *result, int numActions) const
int requestPermissionIfValid(bool *result, int numActions, const bsls::TimeInterval &now)
Int64 d_nanosecondsPerAction
Definition bdlmt_throttle.h:330
bool requestPermission()
Definition bdlmt_throttle.h:571
Int64 nanosecondsPerAction() const
Definition bdlmt_throttle.h:611
bsls::SystemClockType::Enum clockType() const
Definition bdlmt_throttle.h:599
int requestPermissionIfValid(bool *result, int numActions)
Definition bdlmt_throttle.h:584
static const Int64 k_TEN_YEARS_NANOSECONDS
Definition bdlmt_throttle.h:323
bool requestPermission(const bsls::TimeInterval &now)
Definition bsls_timeinterval.h:301
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlmt_eventscheduler.h:522
static const bsls::Types::Int64 k_NANOSECONDS_PER_DAY
Definition bdlt_timeunitratio.h:226
Definition bsls_atomicoperations.h:834
Definition bsls_atomicoperations_default.h:333
Enum
Definition bsls_systemclocktype.h:117
@ e_MONOTONIC
Definition bsls_systemclocktype.h:126
@ e_REALTIME
Definition bsls_systemclocktype.h:120
static TimeInterval now(SystemClockType::Enum clockType)
Definition bsls_systemtime.h:175
long long Int64
Definition bsls_types.h:132