2#ifndef CLICK_STORAGE_HH
3#define CLICK_STORAGE_HH
4#include <click/machine.hh>
11 typedef uint32_t index_type;
12 typedef int32_t signed_index_type;
13 static const index_type invalid_index = (index_type) -1;
15 Storage() : _head(0), _tail(0) { }
17 operator bool()
const {
return _head != _tail; }
18 bool empty()
const {
return _head == _tail; }
20 int size(index_type head, index_type tail)
const;
21 int capacity()
const {
return _capacity; }
23 index_type head()
const {
return _head; }
24 index_type tail()
const {
return _tail; }
26 index_type next_i(index_type i)
const {
27 return (i!=_capacity ? i+1 : 0);
29 index_type prev_i(index_type i)
const {
30 return (i!=0 ? i-1 : _capacity);
34 void set_capacity(index_type c) { _capacity = c; }
35 inline void set_head(index_type h);
36 inline void set_tail(index_type t);
37 inline void set_head_release(index_type h);
38 inline void set_tail_acquire(index_type t);
39 inline index_type reserve_tail_atomic();
41 static inline void packet_memory_barrier(
Packet*
volatile& packet,
42 volatile index_type& index)
43 __attribute__((deprecated));
44 inline void packet_memory_barrier(
Packet*
volatile& packet)
45 __attribute__((deprecated));
51 volatile index_type _head;
52 volatile index_type _tail;
57Storage::size(index_type head, index_type tail)
const
59 index_type x = tail - head;
60 return (signed_index_type(x) >= 0 ? x : _capacity + x + 1);
66 return size(_head, _tail);
70Storage::set_head(index_type h)
77Storage::set_tail(index_type t)
84Storage::set_head_release(index_type h)
91Storage::set_tail_acquire(index_type t)
97inline Storage::index_type
98Storage::reserve_tail_atomic()
105 return invalid_index;
106#if ! CLICK_ATOMIC_COMPARE_SWAP
109 }
while (atomic_uint32_t::compare_swap(_tail, t, nt) != t);
115Storage::packet_memory_barrier(
Packet*
volatile& packet,
volatile index_type& index)
117 __asm__
volatile(
"" : :
"m" (packet),
"m" (index));
121Storage::packet_memory_barrier(
Packet *
volatile &packet)
123 __asm__
volatile(
"" : :
"m" (packet),
"m" (_head),
"m" (_tail));
An atomic 32-bit integer.
A network packet.
Definition packet.hh:68
bool compare_and_swap(uint32_t expected, uint32_t desired) CLICK_BUILTINS_NONDEPRECATED
Perform a compare-and-swap operation.
Definition atomic.hh:734