ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
Backoff.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*----------------------------- File Backoff.h -----------------------------*/
3
/*--------------------------------------------------------------------------*/
37
/*--------------------------------------------------------------------------*/
38
/*----------------------------- DEFINITIONS --------------------------------*/
39
/*--------------------------------------------------------------------------*/
40
41
#ifndef __ADS_Backoff
42
#define __ADS_Backoff
43
/* self-identification: #endif constant */
44
45
/*--------------------------------------------------------------------------*/
46
/*------------------------------ INCLUDES ----------------------------------*/
47
/*--------------------------------------------------------------------------*/
48
49
#include "
ADS/Contract.h
"
50
#include "
ADS/memory/Prefetch.h
"
51
// the spin waits, which issue prefetches
52
#include "ADS/concurrent/impl/Spin.tpp"
53
54
#include <thread>
55
56
/*--------------------------------------------------------------------------*/
57
/*--------------------------- NAMESPACE ------------------------------------*/
58
/*--------------------------------------------------------------------------*/
59
60
namespace
ADS
61
{
62
63
/*--------------------------------------------------------------------------*/
64
/*---------------------------- CLASS Backoff -------------------------------*/
65
/*--------------------------------------------------------------------------*/
66
69
class
Backoff
70
{
71
72
/*--------------------------------------------------------------------------*/
73
public
:
76
explicit
Backoff
(
int
S = 6 ) : f_limit( S ) {
77
ADS_PRE
( ( S >= 0 ) && ( S <= 16 ) );
78
}
79
95
void
pause
(
void
)
noexcept
{
96
if
( f_k <= f_limit ) {
97
for
(
unsigned
i = 0 , n = 1u << f_k ; i < n ; ++i )
98
detail::spinPause();
99
++f_k;
100
}
101
else
102
std::this_thread::yield();
103
}
104
106
void
reset
(
void
)
noexcept
{ f_k = 0; }
107
109
[[nodiscard]]
bool
spinning
(
void
)
const
noexcept
{
110
return
( f_k <= f_limit );
111
}
112
114
[[nodiscard]]
int
step
(
void
)
const
noexcept
{
return
( f_k ); }
115
116
/*--------------------------------------------------------------------------*/
117
private
:
118
int
f_limit;
119
int
f_k = 0;
120
121
};
// end( class Backoff )
122
123
/*--------------------------------------------------------------------------*/
124
125
}
// end( namespace ADS )
126
127
/*--------------------------------------------------------------------------*/
128
129
#endif
/* Backoff.h included */
130
131
/*--------------------------------------------------------------------------*/
132
/*--------------------------- End File Backoff.h ---------------------------*/
133
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Prefetch.h
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
ADS::Backoff::Backoff
Backoff(int S=6)
the backoff that spins on the first calls
Definition
Backoff.h:76
ADS::Backoff::pause
void pause(void) noexcept
waits a little: pauses of the processor at the call from the last reset() if , a yield of the threa...
Definition
Backoff.h:95
ADS::Backoff::spinning
bool spinning(void) const noexcept
whether the next pause() spins, i.e.,
Definition
Backoff.h:109
ADS::Backoff::reset
void reset(void) noexcept
starts again from one pause
Definition
Backoff.h:106
ADS::Backoff::step
int step(void) const noexcept
the calls of pause() since the last reset() that spun,
Definition
Backoff.h:114
ADS_PRE
#define ADS_PRE(cond)
[check]
Definition
Contract.h:121
ADS
Definition
ADT.h:96
ADS
concurrent
Backoff.h
Generated by
1.17.0