Commit f5ae0517 authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Reduce scope of the lock

parent 7cbd515c
......@@ -133,8 +133,10 @@ bool GDALRPCTransformer::ForwardTransform(double* x, double* y, double* z, int n
if (this->m_Modified)
this->Update();
std::vector<int> success(nPointCount);
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, false, nPointCount, x, y, z, success.data());
{
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, false, nPointCount, x, y, z, success.data());
}
bool finalSuccess = std::all_of(success.begin(), success.end(), [](int i){return i;});
return finalSuccess;
}
......@@ -144,8 +146,10 @@ GDALRPCTransformer::PointType GDALRPCTransformer::ForwardTransform(GDALRPCTransf
if (m_Modified)
this->Update();
int success;
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, false, 1, &p[0], &p[1], &p[2], &success);
{
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, false, 1, &p[0], &p[1], &p[2], &success);
}
if (!success)
throw std::runtime_error("GDALRPCTransform was not able to process the ForwardTransform.");
return p;
......@@ -160,8 +164,10 @@ bool GDALRPCTransformer::InverseTransform(double* x, double* y, double* z, int n
if (this->m_Modified)
this->Update();
std::vector<int> success(nPointCount);
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, true, nPointCount, x, y, z, success.data());
{
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, true, nPointCount, x, y, z, success.data());
}
bool finalSuccess = std::all_of(success.begin(), success.end(), [](int i){return i;});
return finalSuccess;
}
......@@ -171,8 +177,10 @@ GDALRPCTransformer::PointType GDALRPCTransformer::InverseTransform(GDALRPCTransf
if (m_Modified)
this->Update();
int success;
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, true, 1, &p[0], &p[1], &p[2], &success);
{
const std::lock_guard<std::mutex> lock(m_Mutex);
GDALRPCTransform(this->m_TransformArg, true, 1, &p[0], &p[1], &p[2], &success);
}
if (!success)
throw std::runtime_error("GDALRPCTransform was not able to process the InverseTransform.");
return p;
......
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