1.1 --- a/page_queue_partitioned.cc Sun Mar 28 22:41:12 2021 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,112 +0,0 @@
1.4 -#include "page_queue_partitioned.h"
1.5 -
1.6 -
1.7 -
1.8 -/* Discard all queued flexpages. */
1.9 -
1.10 -void PageQueuePartitioned::close(Memory *memory)
1.11 -{
1.12 - discard(_available, memory);
1.13 - discard(_issued, memory);
1.14 -}
1.15 -
1.16 -/* Keep waiting for a potential queue non-empty condition.
1.17 - Then, attempt to pop an entry from the queue. */
1.18 -
1.19 -void PageQueuePartitioned::pop(PageOwner **owner, Flexpage **flexpage)
1.20 -{
1.21 - std::unique_lock<std::mutex> guard(_lock);
1.22 - QueueEntry entry;
1.23 -
1.24 - while (1)
1.25 - {
1.26 - if (_pop(&entry))
1.27 - {
1.28 - *owner = entry.owner;
1.29 - *flexpage = entry.flexpage;
1.30 - return;
1.31 - }
1.32 - else
1.33 - _counter.wait(guard);
1.34 - }
1.35 -}
1.36 -
1.37 -/* Check the available pages queue for entries, returning false if no entries
1.38 - are available, returning true and providing the details if an entry can be
1.39 - removed from the front of the queue. */
1.40 -
1.41 -bool PageQueuePartitioned::_pop(QueueEntry *entry)
1.42 -{
1.43 - if (_available.empty())
1.44 - return false;
1.45 -
1.46 - *entry = _available.front();
1.47 - _available.pop_front();
1.48 -
1.49 - return true;
1.50 -}
1.51 -
1.52 -/* Push an entry for the given owner and flexpage to the appropriate queue. */
1.53 -
1.54 -void PageQueuePartitioned::push(PageOwner *owner, Flexpage *flexpage)
1.55 -{
1.56 - std::lock_guard<std::mutex> guard(_lock);
1.57 -
1.58 - /* Record the entry and a position reference for the flexpage. */
1.59 -
1.60 - Queue *queue;
1.61 - Positions *positions = NULL;
1.62 -
1.63 - if (owner == NULL)
1.64 - queue = &_available;
1.65 - else
1.66 - {
1.67 - queue = &_issued;
1.68 - positions = &_positions;
1.69 - }
1.70 -
1.71 - queue->push_back((QueueEntry) {flexpage, owner});
1.72 -
1.73 - if (positions != NULL)
1.74 - {
1.75 - Queue::iterator last = queue->end();
1.76 - last--;
1.77 - positions->insert(Position(flexpage, last));
1.78 - }
1.79 -
1.80 - _counter.notify_one();
1.81 -}
1.82 -
1.83 -/* Push an entry to the front of the appropriate queue. */
1.84 -
1.85 -void PageQueuePartitioned::push_front(PageOwner *owner, Flexpage *flexpage)
1.86 -{
1.87 - std::lock_guard<std::mutex> guard(_lock);
1.88 -
1.89 - Queue *queue;
1.90 - Positions *positions = NULL;
1.91 -
1.92 - if (owner == NULL)
1.93 - queue = &_available;
1.94 - else
1.95 - {
1.96 - queue = &_issued;
1.97 - positions = &_positions;
1.98 - }
1.99 -
1.100 - queue->push_back((QueueEntry) {flexpage, owner});
1.101 -
1.102 - if (positions != NULL)
1.103 - positions->insert(Position(flexpage, queue->begin()));
1.104 -
1.105 - _counter.notify_one();
1.106 -}
1.107 -
1.108 -/* Remove an entry for the given owner and flexpage from the queue. */
1.109 -
1.110 -bool PageQueuePartitioned::remove(PageOwner *owner, Flexpage *flexpage)
1.111 -{
1.112 - return PageQueue::remove(_issued, _positions, owner, flexpage);
1.113 -}
1.114 -
1.115 -// vim: tabstop=4 expandtab shiftwidth=4