当前位置: 首页>>代码示例>>C++>>正文


C++ duration_type::count方法代码示例

本文整理汇总了C++中duration_type::count方法的典型用法代码示例。如果您正苦于以下问题:C++ duration_type::count方法的具体用法?C++ duration_type::count怎么用?C++ duration_type::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在duration_type的用法示例。


在下文中一共展示了duration_type::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: frontBlock

 bool frontBlock(T& t, duration_type timeout) const
 {
     boost::mutex::scoped_lock lock(mutex_);
     bool gotValue = false;
     if (timeout.count() > 0)
     {
         if (deque_.empty())
         {
             available_.wait_for(lock, timeout);
         }
         if (!deque_.empty())
         {
             t = deque_.front();
             gotValue = true;
         }
     }
     else
     {
         while (deque_.empty())
         {
             available_.wait(lock);
         }
         t = deque_.front();
         gotValue = true;
     }
     return gotValue;
 }
开发者ID:ryanpartridge,项目名称:scratchpad,代码行数:27,代码来源:LockingQueue_new.hpp

示例2: bucket_count

  /// Estimate the necessary number of buckets
  std::size_t bucket_count(
      duration_type measurement_period, duration_type sampling_period) {
    if (sampling_period <= duration_type(0)) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - sampling period ("
         << sampling_period.count() << ") must be a positive number";
      throw std::invalid_argument(os.str());
    }
    if (sampling_period > measurement_period) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count() << ") is smaller than sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }

    if ((measurement_period % sampling_period).count() != 0) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count()
         << ") must be a multiple of the sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }

    // ... because measurement_period and sampling_period are positive
    // numbers N will be a positive number ...
    typedef typename duration_type::rep rep;
    typedef typename std::make_unsigned<rep>::type unsigned_rep;
    unsigned_rep N = measurement_period / sampling_period;
    // ... beware, the type may be larger than what can be stored in
    // an std::size_t (weird segmented memory platforms, yuck) ...
    if (N >= std::numeric_limits<std::size_t>::max()) {
      std::ostringstream os;
      os << "jb::event_rate_estimate - measurement period ("
         << measurement_period.count() << ") is too large for sampling period ("
         << sampling_period.count() << ")";
      throw std::invalid_argument(os.str());
    }
    return static_cast<std::size_t>(N);
  }
开发者ID:coryan,项目名称:jaybeams,代码行数:42,代码来源:event_rate_estimator.hpp


注:本文中的duration_type::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。