IImage *AsyncRenderer::RegisterImage(const char *filename) { SPADES_MARK_FUNCTION(); class RegisterImageDispatch: public ConcurrentDispatch { IRenderer *base; const char *fn; IImage *result; std::string error; public: RegisterImageDispatch(IRenderer *base, const char *fn): base(base), fn(fn), result(NULL){} virtual void Run(){ try{ result = base->RegisterImage(fn); }catch(const std::exception& ex){ error = ex.what(); } } IImage *GetResult() { if(!error.empty()){ SPRaise("Error while RegisterImageDispatch:\n%s", error.c_str()); }else{ return result; } } }; std::map<std::string, IImage *>::iterator it = images.find(filename); if(it == images.end()) { FlushCommands(); RegisterImageDispatch dispatch(base, filename); dispatch.StartOn(queue); dispatch.Join(); IImage *img = dispatch.GetResult(); images[filename] = img; img->AddRef(); return img; } return it->second; }