gige_request_counter.cc
Go to the documentation of this file.
1 /*
2 * Roboception GmbH
3 * Munich, Germany
4 * www.roboception.com
5 *
6 * Copyright (c) 2017 Roboception GmbH
7 * All rights reserved
8 *
9 * Author: Raphael Schaller
10 */
11 #include "gige_request_counter.h"
12 
13 #include <atomic>
14 #include <limits>
15 
16 namespace rcdiscover
17 {
18 
19 std::tuple<std::uint8_t, std::uint8_t> GigERequestCounter::getNext()
20 {
21  static std::atomic_uint_fast16_t counter(0);
22 
23  std::uint_fast16_t new_value;
24  std::uint_fast16_t current;
25  do
26  {
27  current = counter;
28  if (current == std::numeric_limits<std::uint16_t>::max())
29  {
30  // skip 0
31  new_value = 1;
32  }
33  else
34  {
35  new_value = static_cast<std::uint_fast16_t>(current + 1);
36  }
37  }
38  while (!counter.compare_exchange_weak(current, new_value));
39 
40  return std::make_tuple(static_cast<std::uint8_t>(new_value >> 8),
41  static_cast<std::uint8_t>(new_value));
42 }
43 
44 }
static std::tuple< uint8_t, uint8_t > getNext()
Returns the next request number.


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32