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