Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Makes a list of widgets and asynchronously frobnicates them.
- //
- // WTF::Vector promises that iterators remain valid unless the vector is mutated,
- // so this was previously legal code. It becomes illegal if compaction moves the
- // backing allocation.
- class Frobnicator : public GarbageCollected<Frobnicator> {
- public:
- Frobnicator() {
- // populate m_widgets with some widgets
- m_iterator = m_widgets.begin();
- }
- void frobnicate() {
- for (; m_iterator != m_widgets.end(); ++m_iterator) {
- if (shouldYield()) {
- postTask(WTF::bind(&Frobnicator::frobnicate, WTF::makePersistent(this)));
- return;
- }
- (*m_iterator)->frobnicate();
- }
- }
- private:
- bool shouldYield() const;
- HeapVector<Widget> m_widgets;
- HeapVector<Widget>::iterator m_iterator;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement