void updateAsyncTransactions() override { PROFILE_FUNCTION(); while (!m_in_progress.empty()) { AsynTrans* tr = m_in_progress.front(); if (!tr->isCompleted()) break; PROFILE_BLOCK("processAsyncTransaction"); m_in_progress.pop(); tr->data.m_cb.invoke(*tr->data.m_file, !!(tr->data.m_flags & E_SUCCESS)); if ((tr->data.m_flags & (E_SUCCESS | E_FAIL)) != 0) { closeAsync(*tr->data.m_file); } m_transaction_queue.dealoc(tr); } int32 can_add = C_MAX_TRANS - m_in_progress.size(); while (can_add && !m_pending.empty()) { AsynTrans* tr = m_transaction_queue.alloc(false); if (tr) { AsyncItem& item = m_pending[0]; tr->data.m_file = item.m_file; tr->data.m_cb = item.m_cb; tr->data.m_mode = item.m_mode; copyString(tr->data.m_path, sizeof(tr->data.m_path), item.m_path); tr->data.m_flags = item.m_flags; tr->reset(); m_transaction_queue.push(tr, true); m_in_progress.push(tr); m_pending.erase(0); } can_add--; } }
int task() { while (!m_trans_queue->isAborted()) { PROFILE_BLOCK("transaction"); AsynTrans* tr = m_trans_queue->pop(true); if (!tr) break; if ((tr->data.m_flags & E_IS_OPEN) == E_IS_OPEN) { tr->data.m_flags |= tr->data.m_file->open(Path(tr->data.m_path), tr->data.m_mode) ? E_SUCCESS : E_FAIL; } else if ((tr->data.m_flags & E_CLOSE) == E_CLOSE) { tr->data.m_file->close(); tr->data.m_file->release(); tr->data.m_file = nullptr; } tr->setCompleted(); } return 0; }
void updateAsyncTransactions() override { PROFILE_FUNCTION(); while (!m_in_progress.empty()) { AsynTrans* tr = m_in_progress.front(); if (!tr->isCompleted()) break; PROFILE_BLOCK("processAsyncTransaction"); m_in_progress.pop(); if ((tr->data.m_flags & E_CANCELED) == 0) { tr->data.m_cb.invoke(*tr->data.m_file, !!(tr->data.m_flags & E_SUCCESS)); } if ((tr->data.m_flags & (E_SUCCESS | E_FAIL)) != 0) { closeAsync(*tr->data.m_file); } m_transaction_queue.dealoc(tr); } i32 can_add = C_MAX_TRANS - m_in_progress.size(); while (can_add && !m_pending.empty()) { AsynTrans* tr = m_transaction_queue.alloc(false); if (tr) { AsyncItem& item = m_pending[0]; tr->data.m_file = item.m_file; tr->data.m_cb = item.m_cb; tr->data.m_id = item.m_id; tr->data.m_mode = item.m_mode; copyString(tr->data.m_path, sizeof(tr->data.m_path), item.m_path); tr->data.m_flags = item.m_flags; tr->reset(); m_transaction_queue.push(tr, true); m_in_progress.push(tr); m_pending.erase(0); } can_add--; } #if LUMIX_SINGLE_THREAD() while (AsynTrans* tr = m_transaction_queue.pop(false)) { PROFILE_BLOCK("transaction"); if ((tr->data.m_flags & E_IS_OPEN) == E_IS_OPEN) { tr->data.m_flags |= tr->data.m_file->open(Path(tr->data.m_path), tr->data.m_mode) ? E_SUCCESS : E_FAIL; } else if ((tr->data.m_flags & E_CLOSE) == E_CLOSE) { tr->data.m_file->close(); tr->data.m_file->release(); tr->data.m_file = nullptr; } tr->setCompleted(); } #endif }