Merge pull request #12660 from alalek:flann_drop_useless_mutex

This commit is contained in:
Alexander Alekhin 2018-09-27 19:46:59 +00:00
commit 9ba659af84

View File

@ -276,7 +276,7 @@ public:
public: public:
KMeansDistanceComputer(Distance _distance, const Matrix<ElementType>& _dataset, KMeansDistanceComputer(Distance _distance, const Matrix<ElementType>& _dataset,
const int _branching, const int* _indices, const Matrix<double>& _dcenters, const size_t _veclen, const int _branching, const int* _indices, const Matrix<double>& _dcenters, const size_t _veclen,
int* _count, int* _belongs_to, std::vector<DistanceType>& _radiuses, bool& _converged, cv::Mutex& _mtx) int* _count, int* _belongs_to, std::vector<DistanceType>& _radiuses, bool& _converged)
: distance(_distance) : distance(_distance)
, dataset(_dataset) , dataset(_dataset)
, branching(_branching) , branching(_branching)
@ -287,7 +287,6 @@ public:
, belongs_to(_belongs_to) , belongs_to(_belongs_to)
, radiuses(_radiuses) , radiuses(_radiuses)
, converged(_converged) , converged(_converged)
, mtx(_mtx)
{ {
} }
@ -311,12 +310,10 @@ public:
radiuses[new_centroid] = sq_dist; radiuses[new_centroid] = sq_dist;
} }
if (new_centroid != belongs_to[i]) { if (new_centroid != belongs_to[i]) {
count[belongs_to[i]]--; CV_XADD(&count[belongs_to[i]], -1);
count[new_centroid]++; CV_XADD(&count[new_centroid], 1);
belongs_to[i] = new_centroid; belongs_to[i] = new_centroid;
mtx.lock();
converged = false; converged = false;
mtx.unlock();
} }
} }
} }
@ -332,7 +329,6 @@ public:
int* belongs_to; int* belongs_to;
std::vector<DistanceType>& radiuses; std::vector<DistanceType>& radiuses;
bool& converged; bool& converged;
cv::Mutex& mtx;
KMeansDistanceComputer& operator=( const KMeansDistanceComputer & ) { return *this; } KMeansDistanceComputer& operator=( const KMeansDistanceComputer & ) { return *this; }
}; };
@ -801,8 +797,7 @@ private:
} }
// reassign points to clusters // reassign points to clusters
cv::Mutex mtx; KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, count, belongs_to, radiuses, converged);
KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, count, belongs_to, radiuses, converged, mtx);
parallel_for_(cv::Range(0, (int)indices_length), invoker); parallel_for_(cv::Range(0, (int)indices_length), invoker);
for (int i=0; i<branching; ++i) { for (int i=0; i<branching; ++i) {