Advertisement
Guest User

Untitled

a guest
Dec 13th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. // Makes a list of widgets and asynchronously frobnicates them.
  2. //
  3. // WTF::Vector promises that iterators remain valid unless the vector is mutated,
  4. // so this was previously legal code. It becomes illegal if compaction moves the
  5. // backing allocation.
  6. class Frobnicator : public GarbageCollected<Frobnicator> {
  7. public:
  8. Frobnicator() {
  9. // populate m_widgets with some widgets
  10. m_iterator = m_widgets.begin();
  11. }
  12.  
  13. void frobnicate() {
  14. for (; m_iterator != m_widgets.end(); ++m_iterator) {
  15. if (shouldYield()) {
  16. postTask(WTF::bind(&Frobnicator::frobnicate, WTF::makePersistent(this)));
  17. return;
  18. }
  19. (*m_iterator)->frobnicate();
  20. }
  21. }
  22.  
  23. private:
  24. bool shouldYield() const;
  25.  
  26. HeapVector<Widget> m_widgets;
  27. HeapVector<Widget>::iterator m_iterator;
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement