Commit 877a2067 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

manage operations by unique ptr

parent bef94117
...@@ -68,7 +68,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -68,7 +68,7 @@ struct remi_provider : public tl::provider<remi_provider> {
tl::engine* m_engine; tl::engine* m_engine;
tl::pool& m_pool; tl::pool& m_pool;
abt_io_instance_id m_abtio; abt_io_instance_id m_abtio;
std::unordered_map<uuid, operation, uuid_hash> m_op_in_progress; std::unordered_map<uuid, std::unique_ptr<operation>, uuid_hash> m_op_in_progress;
tl::mutex m_op_in_progress_mtx; tl::mutex m_op_in_progress_mtx;
static std::unordered_map<uint16_t, remi_provider*> s_registered_providers; static std::unordered_map<uint16_t, remi_provider*> s_registered_providers;
...@@ -155,11 +155,12 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -155,11 +155,12 @@ struct remi_provider : public tl::provider<remi_provider> {
// store the operation into the map of pending operations // store the operation into the map of pending operations
{ {
std::lock_guard<tl::mutex> guard(m_op_in_progress_mtx); std::lock_guard<tl::mutex> guard(m_op_in_progress_mtx);
auto& op = m_op_in_progress[std::get<2>(result)]; auto r = m_op_in_progress.insert(std::make_pair(std::get<2>(result), std::make_unique<operation>()));
op.m_fileset = std::move(fileset); auto& op = r.first->second;
op.m_filesizes = std::move(filesizes); op->m_fileset = std::move(fileset);
op.m_modes = std::move(theModes); op->m_filesizes = std::move(filesizes);
op.m_fds = std::move(openedFileDescriptors); op->m_modes = std::move(theModes);
op->m_fds = std::move(openedFileDescriptors);
#if 0 #if 0
op.m_devices = std::move(devices); op.m_devices = std::move(devices);
#endif #endif
...@@ -183,7 +184,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -183,7 +184,7 @@ struct remi_provider : public tl::provider<remi_provider> {
req.respond(result); req.respond(result);
return; return;
} }
op = &(it->second); op = it->second.get();
} }
{ {
...@@ -238,7 +239,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -238,7 +239,7 @@ struct remi_provider : public tl::provider<remi_provider> {
req.respond(ret); req.respond(ret);
return; return;
} }
op = &(it->second); op = it->second.get();
} }
// we found the operation, let's mmap some files! // we found the operation, let's mmap some files!
...@@ -251,7 +252,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -251,7 +252,7 @@ struct remi_provider : public tl::provider<remi_provider> {
} }
if(error) { if(error) {
std::lock_guard<tl::mutex> guard(m_op_in_progress_mtx); std::lock_guard<tl::mutex> guard(m_op_in_progress_mtx);
this->m_op_in_progress.erase(operation_id); m_op_in_progress.erase(operation_id);
} }
}; };
...@@ -338,7 +339,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -338,7 +339,7 @@ struct remi_provider : public tl::provider<remi_provider> {
req.respond(ret); req.respond(ret);
return; return;
} }
op = &(it->second); op = it->second.get();
} }
std::lock_guard<tl::mutex> guard(op->m_mutex); std::lock_guard<tl::mutex> guard(op->m_mutex);
...@@ -372,6 +373,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -372,6 +373,7 @@ struct remi_provider : public tl::provider<remi_provider> {
ret = REMI_ERR_IO; ret = REMI_ERR_IO;
std::cerr << "remi-server.cpp: line " std::cerr << "remi-server.cpp: line "
<< __LINE__ << " failed (op->m_filesizes[fileNumber] < writeOffset + data.size())" << std::endl; << __LINE__ << " failed (op->m_filesizes[fileNumber] < writeOffset + data.size())" << std::endl;
std::cerr << "with fileNumber=" << fileNumber << ", writeOffset=" << writeOffset << ", data.size()=" << data.size() << std::endl;
cleanup(true); cleanup(true);
req.respond(ret); req.respond(ret);
return; return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment