Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ab4fd0

Browse files
committed
Removed all tests of CV_CXX11, now assume it's always true
This allowed removing a lot of dead code. Updated some documentation consequently.
1 parent 00af518 commit 4ab4fd0

File tree

28 files changed

+21
-405
lines changed

28 files changed

+21
-405
lines changed

doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,10 @@ This splitting is done automatically to distribute equally the computation load.
165165
to a 2D `[row, col]` coordinate. Also note that we have to keep a reference on the mat image to be able to modify in-place
166166
the image.
167167

168-
The parallel execution is called with:
168+
The parallel execution is called with a lambda expression:
169169

170170
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call
171171

172-
Here, the range represents the total number of operations to be executed, so the total number of pixels in the image.
173-
To set the number of threads, you can use: @ref cv::setNumThreads. You can also specify the number of splitting using the
174-
nstripes parameter in @ref cv::parallel_for_. For instance, if your processor has 4 threads, setting `cv::setNumThreads(2)`
175-
or setting `nstripes=2` should be the same as by default it will use all the processor threads available but will split the
176-
workload only on two threads.
177-
178-
@note
179-
C++ 11 standard allows to simplify the parallel implementation by get rid of the `ParallelMandelbrot` class and replacing it with lambda expression:
180-
181-
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11
182-
183172
Results
184173
-----------
185174

doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,10 @@ When looking at the sequential implementation, we can notice that each pixel dep
9696

9797
@note Although values of a pixel in a particular stripe may depend on pixel values outside the stripe, these are only read only operations and hence will not cause undefined behaviour.
9898

99+
C++ 11 standard allows a parallel implementation with a lambda expression:
99100

100-
We first declare a custom class that inherits from @ref cv::ParallelLoopBody and override the `virtual void operator ()(const cv::Range& range) const`.
101101
@snippet how_to_use_OpenCV_parallel_for_new.cpp convolution-parallel
102102

103-
The range in the `operator ()` represents the subset of values that will be treated by an individual thread. Based on the requirement, there may be different ways of splitting the range which in turn changes the computation.
104-
105-
For example, we can either
106-
1. Split the entire traversal of the image and obtain the [row, col] coordinate in the following way (as shown in the above code):
107-
108-
@snippet how_to_use_OpenCV_parallel_for_new.cpp overload-full
109-
110-
We would then call the parallel_for_ function in the following way:
111-
@snippet how_to_use_OpenCV_parallel_for_new.cpp convolution-parallel-function
112-
<br>
113-
114-
2. Split the rows and compute for each row:
115-
116-
@snippet how_to_use_OpenCV_parallel_for_new.cpp overload-row-split
117-
118-
In this case, we call the parallel_for_ function with a different range:
119-
@snippet how_to_use_OpenCV_parallel_for_new.cpp convolution-parallel-function-row
120-
121-
@note In our case, both implementations perform similarly. Some cases may allow better memory access patterns or other performance benefits.
122-
123-
To set the number of threads, you can use: @ref cv::setNumThreads. You can also specify the number of splitting using the nstripes parameter in @ref cv::parallel_for_. For instance, if your processor has 4 threads, setting `cv::setNumThreads(2)` or setting `nstripes=2` should be the same as by default it will use all the processor threads available but will split the workload only on two threads.
124-
125-
@note C++ 11 standard allows to simplify the parallel implementation by get rid of the `parallelConvolution` class and replacing it with lambda expression:
126-
127-
@snippet how_to_use_OpenCV_parallel_for_new.cpp convolution-parallel-cxx11
128-
129103
Results
130104
-----------
131105

modules/core/include/opencv2/core/async.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
#include <opencv2/core/mat.hpp>
99

10-
#ifdef CV_CXX11
1110
//#include <future>
1211
#include <chrono>
13-
#endif
1412

1513
namespace cv {
1614

@@ -69,7 +67,6 @@ class CV_EXPORTS_W AsyncArray
6967

7068
CV_WRAP bool valid() const CV_NOEXCEPT;
7169

72-
#ifdef CV_CXX11
7370
inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; }
7471
inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
7572

@@ -89,7 +86,6 @@ class CV_EXPORTS_W AsyncArray
8986
std::future<Mat> getFutureMat() const;
9087
std::future<UMat> getFutureUMat() const;
9188
#endif
92-
#endif
9389

9490

9591
// PImpl

modules/core/include/opencv2/core/detail/async_promise.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ class CV_EXPORTS AsyncPromise
5252
*/
5353
void setException(const cv::Exception& exception);
5454

55-
#ifdef CV_CXX11
5655
explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; }
5756
AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
58-
#endif
5957

6058

6159
// PImpl

modules/core/include/opencv2/core/detail/exception_ptr.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88
#ifndef CV__EXCEPTION_PTR
99
# if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2
1010
# define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938
11-
# elif defined(CV_CXX11)
11+
# else
1212
# define CV__EXCEPTION_PTR 1
13-
# elif defined(_MSC_VER)
14-
# define CV__EXCEPTION_PTR (_MSC_VER >= 1600)
15-
# elif defined(__clang__)
16-
# define CV__EXCEPTION_PTR 0 // C++11 only (see above)
17-
# elif defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
18-
# define CV__EXCEPTION_PTR (__GXX_EXPERIMENTAL_CXX0X__ > 0)
1913
# endif
2014
#endif
2115
#ifndef CV__EXCEPTION_PTR

modules/core/include/opencv2/core/eigen.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
#endif
6262

6363
#if !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT)
64-
#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \
65-
&& defined(CV_CXX11)
64+
#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3
6665
#include <unsupported/Eigen/CXX11/Tensor>
6766
#define OPENCV_EIGEN_TENSOR_SUPPORT 1
6867
#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3

modules/core/include/opencv2/core/matx.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,8 @@ template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>
376376
static Vec randn(_Tp a, _Tp b);
377377
static Vec randu(_Tp a, _Tp b);
378378
static Vec zeros();
379-
#ifdef CV_CXX11
380379
static Vec diag(_Tp alpha) = delete;
381380
static Vec eye() = delete;
382-
#endif
383381

384382
//! per-element multiplication
385383
Vec mul(const Vec<_Tp, cn>& v) const;
@@ -402,9 +400,7 @@ template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>
402400
const _Tp& operator ()(int i) const;
403401
_Tp& operator ()(int i);
404402

405-
#ifdef CV_CXX11
406403
Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default;
407-
#endif
408404

409405
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp);
410406
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp);

modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
//#define OPENCV_DISABLE_ALLOCATOR_STATS
1111

12-
#ifdef CV_CXX11
13-
1412
#include <atomic>
1513

1614
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
@@ -26,14 +24,6 @@
2624
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long
2725
#endif
2826

29-
#else // CV_CXX11
30-
31-
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
32-
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int // CV_XADD supports int only
33-
#endif
34-
35-
#endif // CV_CXX11
36-
3727
namespace cv { namespace utils {
3828

3929
#ifdef CV__ALLOCATOR_STATS_LOG
@@ -59,7 +49,7 @@ class AllocatorStatistics : public AllocatorStatisticsInterface
5949
void onAllocate(size_t /*sz*/) {}
6050
void onFree(size_t /*sz*/) {}
6151

62-
#elif defined(CV_CXX11)
52+
#else
6353

6454
protected:
6555
typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
@@ -104,49 +94,7 @@ class AllocatorStatistics : public AllocatorStatisticsInterface
10494
#endif
10595
curr -= (counter_t)sz;
10696
}
107-
108-
#else // non C++11
109-
110-
protected:
111-
typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
112-
volatile counter_t curr, total, total_allocs, peak; // overflow is possible, CV_XADD operates with 'int' only
113-
public:
114-
AllocatorStatistics()
115-
: curr(0), total(0), total_allocs(0), peak(0)
116-
{}
117-
~AllocatorStatistics() CV_OVERRIDE {}
118-
119-
uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr; }
120-
uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total; }
121-
uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs; }
122-
uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak; }
123-
124-
void resetPeakUsage() CV_OVERRIDE { peak = curr; }
125-
126-
// Controller interface
127-
void onAllocate(size_t sz)
128-
{
129-
#ifdef CV__ALLOCATOR_STATS_LOG
130-
CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr));
131-
#endif
132-
133-
counter_t new_curr = (counter_t)CV_XADD(&curr, (counter_t)sz) + (counter_t)sz;
134-
135-
peak = std::max((counter_t)peak, new_curr); // non-thread safe
136-
137-
//CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable...
138-
total += sz;
139-
140-
CV_XADD(&total_allocs, (counter_t)1);
141-
}
142-
void onFree(size_t sz)
143-
{
144-
#ifdef CV__ALLOCATOR_STATS_LOG
145-
CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr));
146-
#endif
147-
CV_XADD(&curr, (counter_t)-sz);
148-
}
149-
#endif
97+
#endif // OPENCV_DISABLE_ALLOCATOR_STATS
15098
};
15199

152100
#ifdef CV__ALLOCATOR_STATS_LOG

modules/core/src/async.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// of this distribution and at http://opencv.org/license.html.
44

55
#include "precomp.hpp"
6-
//#undef CV_CXX11 // debug non C++11 mode
76
#include "opencv2/core/async.hpp"
87
#include "opencv2/core/detail/async_promise.hpp"
98

@@ -16,11 +15,9 @@
1615

1716
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
1817

19-
#ifdef CV_CXX11
2018
#include <mutex>
2119
#include <condition_variable>
2220
#include <chrono>
23-
#endif
2421

2522
namespace cv {
2623

@@ -37,12 +34,8 @@ struct AsyncArray::Impl
3734
void releasePromise() CV_NOEXCEPT { CV_XADD(&refcount_promise, -1); if(1 == CV_XADD(&refcount, -1)) delete this; } \
3835
int refcount_promise;
3936

40-
#ifdef CV_CXX11
4137
mutable std::mutex mtx;
4238
mutable std::condition_variable cond_var;
43-
#else
44-
mutable cv::Mutex mtx;
45-
#endif
4639

4740
mutable bool has_result; // Mat, UMat or exception
4841

@@ -88,11 +81,7 @@ struct AsyncArray::Impl
8881
if (!wait_for(timeoutNs))
8982
return false;
9083
}
91-
#ifdef CV_CXX11
9284
std::unique_lock<std::mutex> lock(mtx);
93-
#else
94-
cv::AutoLock lock(mtx);
95-
#endif
9685
if (has_result)
9786
{
9887
if (!result_mat.empty())
@@ -145,7 +134,6 @@ struct AsyncArray::Impl
145134
if (timeoutNs == 0)
146135
return has_result;
147136
CV_LOG_INFO(NULL, "Waiting for async result ...");
148-
#ifdef CV_CXX11
149137
std::unique_lock<std::mutex> lock(mtx);
150138
const auto cond_pred = [&]{ return has_result == true; };
151139
if (timeoutNs > 0)
@@ -156,9 +144,6 @@ struct AsyncArray::Impl
156144
CV_Assert(has_result);
157145
return true;
158146
}
159-
#else
160-
CV_Error(Error::StsNotImplemented, "OpenCV has been built without async waiting support (C++11 is required)");
161-
#endif
162147
}
163148

164149
AsyncArray getArrayResult()
@@ -175,11 +160,7 @@ struct AsyncArray::Impl
175160
{
176161
if (future_is_returned && refcount_future == 0)
177162
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
178-
#ifdef CV_CXX11
179163
std::unique_lock<std::mutex> lock(mtx);
180-
#else
181-
cv::AutoLock lock(mtx);
182-
#endif
183164
CV_Assert(!has_result);
184165
int k = value.kind();
185166
if (k == _InputArray::UMAT)
@@ -193,47 +174,33 @@ struct AsyncArray::Impl
193174
value.copyTo(*result_mat.get());
194175
}
195176
has_result = true;
196-
#ifdef CV_CXX11
197177
cond_var.notify_all();
198-
#endif
199178
}
200179

201180
#if CV__EXCEPTION_PTR
202181
void setException(std::exception_ptr e)
203182
{
204183
if (future_is_returned && refcount_future == 0)
205184
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
206-
#ifdef CV_CXX11
207185
std::unique_lock<std::mutex> lock(mtx);
208-
#else
209-
cv::AutoLock lock(mtx);
210-
#endif
211186
CV_Assert(!has_result);
212187
has_exception = true;
213188
exception = e;
214189
has_result = true;
215-
#ifdef CV_CXX11
216190
cond_var.notify_all();
217-
#endif
218191
}
219192
#endif
220193

221194
void setException(const cv::Exception e)
222195
{
223196
if (future_is_returned && refcount_future == 0)
224197
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
225-
#ifdef CV_CXX11
226198
std::unique_lock<std::mutex> lock(mtx);
227-
#else
228-
cv::AutoLock lock(mtx);
229-
#endif
230199
CV_Assert(!has_result);
231200
has_exception = true;
232201
cv_exception = e;
233202
has_result = true;
234-
#ifdef CV_CXX11
235203
cond_var.notify_all();
236-
#endif
237204
}
238205
};
239206

modules/core/src/matrix_wrap.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,12 +1919,7 @@ void _OutputArray::move(UMat& u) const
19191919
int k = kind();
19201920
if (k == UMAT)
19211921
{
1922-
#ifdef CV_CXX11
19231922
*(UMat*)obj = std::move(u);
1924-
#else
1925-
*(UMat*)obj = u;
1926-
u.release();
1927-
#endif
19281923
}
19291924
else if (k == MAT)
19301925
{
@@ -1959,12 +1954,7 @@ void _OutputArray::move(Mat& m) const
19591954
}
19601955
else if (k == MAT)
19611956
{
1962-
#ifdef CV_CXX11
19631957
*(Mat*)obj = std::move(m);
1964-
#else
1965-
*(Mat*)obj = m;
1966-
m.release();
1967-
#endif
19681958
}
19691959
else if (k == MATX)
19701960
{

0 commit comments

Comments
 (0)