void IDBDatabaseBackend::processPendingOpenCalls(bool success) { // Open calls can be requeued if an open call started a version change transaction or deletes the database. Deque<OwnPtr<IDBPendingOpenCall>> pendingOpenCalls; m_pendingOpenCalls.swap(pendingOpenCalls); while (!pendingOpenCalls.isEmpty()) { OwnPtr<IDBPendingOpenCall> pendingOpenCall = pendingOpenCalls.takeFirst(); if (success) { if (m_metadata.id == InvalidId) { // This database was deleted then quickly re-opened. // openInternalAsync() will recreate it in the backing store and then resume processing pending callbacks. pendingOpenCalls.prepend(pendingOpenCall.release()); pendingOpenCalls.swap(m_pendingOpenCalls); openInternalAsync(); return; } openConnectionInternal(pendingOpenCall->callbacks(), pendingOpenCall->databaseCallbacks(), pendingOpenCall->transactionId(), pendingOpenCall->version()); } else { String message; if (pendingOpenCall->version() == IDBDatabaseMetadata::NoIntVersion) message = "Internal error opening database with no version specified."; else message = String::format("Internal error opening database with version %llu", static_cast<unsigned long long>(pendingOpenCall->version())); pendingOpenCall->callbacks()->onError(IDBDatabaseError::create(IDBDatabaseException::UnknownError, message)); } } }
void ExecutionContext::notifyContextDestroyed() { Deque<OwnPtr<SuspendableTask>> suspendedTasks; suspendedTasks.swap(m_suspendedTasks); for (Deque<OwnPtr<SuspendableTask>>::iterator it = suspendedTasks.begin(); it != suspendedTasks.end(); ++it) (*it)->contextDestroyed(); ContextLifecycleNotifier::notifyContextDestroyed(); }
void WebSocket::EventQueue::dispatchQueuedEvents() { if (m_state != Active) return; RefPtr<EventQueue> protect(this); Deque<RefPtr<Event> > events; events.swap(m_events); while (!events.isEmpty()) { if (m_state == Stopped || m_state == Suspended) break; ASSERT(m_state == Active); ASSERT(m_target->executionContext()); m_target->dispatchEvent(events.takeFirst()); // |this| can be stopped here. } if (m_state == Suspended) { while (!m_events.isEmpty()) events.append(m_events.takeFirst()); events.swap(m_events); } }
void test_swap (const T *lhs_seq, std::size_t lhs_seq_len, const T *rhs_seq, std::size_t rhs_seq_len, std::deque<T, Allocator>*, const char *tname) { typedef std::deque<T, Allocator> Deque; typedef typename Deque::iterator Iterator; typedef typename Deque::size_type SizeType; // create two containers from the provided sequences Deque lhs (lhs_seq, lhs_seq + lhs_seq_len); Deque rhs (rhs_seq, rhs_seq + rhs_seq_len); // save the begin and and iterators and the size // of each container before swapping the objects const Iterator lhs_begin_0 = lhs.begin (); const Iterator lhs_end_0 = lhs.end (); const SizeType lhs_size_0 = lhs.size (); const Iterator rhs_begin_0 = rhs.begin (); const Iterator rhs_end_0 = rhs.end (); const SizeType rhs_size_0 = rhs.size (); // swap the two containers lhs.swap (rhs); // compute the begin and and iterators and the size // of each container after swapping the objects const Iterator lhs_begin_1 = lhs.begin (); const Iterator lhs_end_1 = lhs.end (); const SizeType lhs_size_1 = lhs.size (); const Iterator rhs_begin_1 = rhs.begin (); const Iterator rhs_end_1 = rhs.end (); const SizeType rhs_size_1 = rhs.size (); static const int cwidth = sizeof (T); // verify that the iterators and sizes // of the two objects were swapped rw_assert (lhs_begin_0 == rhs_begin_1 && lhs_begin_1 == rhs_begin_0, 0, __LINE__, "begin() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (lhs_end_0 == rhs_end_1 && lhs_end_1 == rhs_end_0, 0, __LINE__, "end() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (lhs_size_0 == rhs_size_1 && lhs_size_1 == rhs_size_0, 0, __LINE__, "size() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); // swap one of the containers with an empty unnamed temporary // container and verify that the object is empty { Deque ().swap (lhs); } const Iterator lhs_begin_2 = lhs.begin (); const Iterator lhs_end_2 = lhs.end (); const SizeType lhs_size_2 = lhs.size (); rw_assert (lhs_begin_2 == lhs_end_2, 0, __LINE__, "deque<%s>().begin() not swapped for \"%{X=*.*}\"", tname, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (0 == lhs_size_2, 0, __LINE__, "deque<%s>().size() not swapped for \"%{X=*.*}\"", tname, cwidth, int (rhs_seq_len), -1, rhs_seq); }