1 #include "page_queue_partitioned.h" 2 3 /* Keep waiting for a potential queue non-empty condition. 4 Then, attempt to pop an entry from the queue. */ 5 6 void PageQueuePartitioned::pop(PageOwner **owner, Flexpage **flexpage) 7 { 8 std::unique_lock<std::mutex> guard(_lock); 9 QueueEntry entry; 10 11 while (1) 12 { 13 if (_pop(&entry)) 14 { 15 *owner = entry.owner; 16 *flexpage = entry.flexpage; 17 return; 18 } 19 else 20 _counter.wait(guard); 21 } 22 } 23 24 /* Check the available pages queue for entries, returning false if no entries 25 are available, returning true and providing the details if an entry can be 26 removed from the front of the queue. */ 27 28 bool PageQueuePartitioned::_pop(QueueEntry *entry) 29 { 30 if (_available.empty()) 31 return false; 32 33 *entry = _available.front(); 34 _available.pop_front(); 35 36 return true; 37 } 38 39 /* Push an entry for the given owner and flexpage to the appropriate queue. */ 40 41 void PageQueuePartitioned::push(PageOwner *owner, Flexpage *flexpage) 42 { 43 std::lock_guard<std::mutex> guard(_lock); 44 45 /* Record the entry and a position reference for the flexpage. */ 46 47 Queue *queue; 48 Positions *positions = NULL; 49 50 if (owner == NULL) 51 queue = &_available; 52 else 53 { 54 queue = &_issued; 55 positions = &_positions; 56 } 57 58 queue->push_back((QueueEntry) {flexpage, owner}); 59 60 if (positions != NULL) 61 { 62 Queue::iterator last = queue->end(); 63 last--; 64 positions->insert(Position(flexpage, last)); 65 } 66 67 _counter.notify_one(); 68 } 69 70 /* Push an entry to the front of the appropriate queue. */ 71 72 void PageQueuePartitioned::push_front(PageOwner *owner, Flexpage *flexpage) 73 { 74 std::lock_guard<std::mutex> guard(_lock); 75 76 Queue *queue; 77 Positions *positions = NULL; 78 79 if (owner == NULL) 80 queue = &_available; 81 else 82 { 83 queue = &_issued; 84 positions = &_positions; 85 } 86 87 queue->push_back((QueueEntry) {flexpage, owner}); 88 89 if (positions != NULL) 90 positions->insert(Position(flexpage, queue->begin())); 91 92 _counter.notify_one(); 93 } 94 95 /* Remove an entry for the given owner and flexpage from the queue. */ 96 97 bool PageQueuePartitioned::remove(PageOwner *owner, Flexpage *flexpage) 98 { 99 (void) owner; (void) flexpage; 100 return true; 101 } 102 103 // vim: tabstop=4 expandtab shiftwidth=4