ClientCached* getClientCached(const std::string &name, Client *client) const { ClientCached *cc = NULL; m_clientcached.get(name, &cc); if (cc) return cc; if (std::this_thread::get_id() == m_main_thread) { return createClientCachedDirect(name, client); } // We're gonna ask the result to be put into here static ResultQueue<std::string, ClientCached*, u8, u8> result_queue; // Throw a request in m_get_clientcached_queue.add(name, 0, 0, &result_queue); try { while(true) { // Wait result for a second GetResult<std::string, ClientCached*, u8, u8> result = result_queue.pop_front(1000); if (result.key == name) { return result.item; } } } catch(ItemNotFoundException &e) { errorstream << "Waiting for clientcached " << name << " timed out." << std::endl; return &m_dummy_clientcached; } }
void ClearResults() { while (results.size()) { SQLite3Result* res = results[0]; delete res; results.pop_front(); } }
void SendResults() { while (results.size()) { SQLite3Result* res = results[0]; if (res->GetDest()) { res->Send(); } else { /* If the client module is unloaded partway through a query then the provider will set * the pointer to NULL. We cannot just cancel the query as the result will still come * through at some point...and it could get messy if we play with invalid pointers... */ delete res; } results.pop_front(); } }