2#ifndef included_AMP_ThreadPoolQueue
3#define included_AMP_ThreadPoolQueue
6#include "AMP/utils/threadpool/AtomicList.h"
7#include "AMP/utils/threadpool/ThreadPoolId.h"
50 for ( int64_t i = N - 1; i >= 0; i-- )
57 auto compare = [](
const ThreadPoolID &a,
const uint64_t &b ) {
60 for (
auto item : list ) {
65 tmp.
setPriority( std::max( item.second, tmp.getPriority() ) );
124 for (
size_t i = 0; i < N; i++ ) {
125 if ( ids[i].ready() ) {
126 d_ids[Nh2++] = ids[i];
128 const_cast<size_t &
>(
d_Nb )++;
134 if ( Nh2 -
d_Nh > 3 ) {
137 for (
size_t i =
d_Nh + 1; i <= Nh2; i++ )
151 bool changed =
false;
152 for (
size_t i = 0; i <
d_Nh; i++ ) {
155 for (
size_t j = 0; j < list.size(); j++ ) {
156 if ( list[j].first == id2 ) {
157 id.setPriority( std::max( list[j].second,
id.getPriority() ) );
165 for ( int64_t i =
d_Nc - 1; i >=
static_cast<int64_t
>(
d_Nc -
d_Nb ); i-- ) {
168 for (
size_t j = 0; j < list.size(); j++ ) {
169 if ( list[j].first == id2 ) {
170 id.setPriority( std::max( list[j].second,
id.getPriority() ) );
183 while ( !
d_lock.compare_exchange_weak( expected, 1 ) ) {
190 d_lock.compare_exchange_weak( expected, 0 );
204 const_cast<size_t &
>(
d_Nb )--;
Maintain a sorted list of entries.
size_t size() const
Return the size of the list.
TYPE remove(Compare compare, const Args &...args)
Remove an item from the list.
void insert(const TYPE &x)
Insert an item.
constexpr size_t capacity() const
Return the capacity of the list.
bool empty() const
Check if the list is empty.
Class to store the queue for the ThreadPool using a binary heap.
ThreadPoolHeapQueue()=delete
Empty constructor.
ThreadPoolHeapQueue(const ThreadPoolHeapQueue &)=delete
Copy constructor.
void insert(size_t N, const ThreadPoolID *ids)
Add the given items to the queue.
bool empty() const
Check if the queue is empty.
size_t capacity() const
The number of items that can be in the queue.
volatile std::atomic_int32_t d_lock
ThreadPoolHeapQueue(size_t N)
Default constructor.
void changePriorities(const std::vector< std::pair< uint64_t, int8_t > > &list)
Change the prioirties of items in the queue.
ThreadPoolID pop()
Get the next item to process.
size_t size() const
The number of items that are in the queue.
ThreadPoolHeapQueue & operator=(const ThreadPoolHeapQueue &)=delete
Asignment operator.
volatile ThreadPoolID * d_ids
This a class to hold the work item id.
uint64_t getLocalID() const
void setPriority(int8_t priority)
Class to store the queue for the ThreadPool using an thread-safe list.
ThreadPoolListQueue & operator=(const ThreadPoolListQueue &)=delete
Asignment operator.
void insert(size_t N, const ThreadPoolID *ids)
Add the given items to the queue.
ThreadPoolListQueue(size_t N)
Default constructor.
void changePriorities(const std::vector< std::pair< uint64_t, int8_t > > &list)
Change the prioirties of items in the queue.
size_t size() const
The number of items that are in the queue.
size_t capacity() const
The number of items that can be in the queue.
ThreadPoolID pop()
Get the next item to process.
AtomicList< ThreadPoolID, std::greater< ThreadPoolID > > queue_type
ThreadPoolListQueue(const ThreadPoolListQueue &)=delete
Copy constructor.
ThreadPoolListQueue()=delete
Empty constructor.
bool empty() const
Check if the queue is empty.
decltype(void(T{ std::declval< Args >()... }), std::true_type()) test(int)