libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
latency_timestamps_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2019 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE {
20 
21 inline bool
22 latency_timestamps_itf::timestamp::is_valid() const noexcept(true) {
23  return start>element_type{} && start<end;
24 }
25 
28 : lts_(lts) {
29  ts.start=timer_t::get_start();
30 }
31 
33 latency_timestamps_itf::period::~period() noexcept(true) {
34  ts.end=timer_t::get_end();
35  assert(ts.is_valid());
36  lts_.push_back(ts);
37 }
38 
39 inline REALLY_FORCE_INLINE latency_timestamps::size_type
40 latency_timestamps::size() const noexcept(true) {
41  const std::ptrdiff_t sz=current_timestamp-timestamps.get();
42  assert(sz>=0);
43  assert(static_cast<size_type>(sz)<=num_timestamps);
44  return static_cast<size_type>(sz);
45 }
46 
47 inline REALLY_FORCE_INLINE void
48 latency_timestamps::push_back(element_type const &ts) noexcept(true) {
49  if (num_timestamps>0 && size()<num_timestamps) {
50  element_type *curr_ts=current_timestamp.fetch_add(1U, std::memory_order_relaxed);
51  assert(curr_ts<std::next(timestamps.get(), num_timestamps));
52  assert(ts.is_valid());
53  PREFETCH_WRITE(curr_ts, _MM_HINT_NTA);
54  *curr_ts=ts;
55  assert(curr_ts->is_valid());
56  }
57 }
58 
59 } }