-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusyWaitStrategy.hpp
More file actions
37 lines (30 loc) · 1.09 KB
/
BusyWaitStrategy.hpp
File metadata and controls
37 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#if !defined(ELUCIDATE__DIS__BUSYWAITSTRATEGY_HPP)
#define ELUCIDATE__DIS__BUSYWAITSTRATEGY_HPP
#include "ARCount.hpp"
#include "Arithmetic.hpp"
namespace Elucidate::Dis {
/** @brief implements the waiting strategy that spins a core.
* collaborates with RingBuffer.
*/
struct BusyWaitStrategy final {
template< typename IndexType, unsigned PadSize >
static IndexType waitFor(ARCount< IndexType, PadSize > const& cursor, IndexType ask) noexcept;
template< typename IndexType, int Size, unsigned PadSize >
static void waitForWrap(ARCount< IndexType, PadSize > const& cursor, IndexType ask) noexcept;
};
template< typename IndexType, unsigned PadSize >
inline IndexType BusyWaitStrategy::waitFor(ARCount< IndexType, PadSize > const& cursor,
IndexType ask) noexcept {
IndexType ret;
while ((ret = cursor.get()) < ask)
{} // busy wait
return ret;
}
template< typename IndexType, int Size, unsigned PadSize >
void BusyWaitStrategy::waitForWrap(ARCount< IndexType, PadSize > const& cursor, IndexType ask) noexcept {
ask = bottomBound< Size >(ask);
while (cursor.get() < ask)
{} // busy wait
}
}
#endif