mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #23736 from seanm:c++11-simplifications
Removed all pre-C++11 code, workarounds, and branches #23736 This removes a bunch of pre-C++11 workrarounds that are no longer necessary as C++11 is now required. It is a nice clean up and simplification. * No longer unconditionally #include <array> in cvdef.h, include explicitly where needed * Removed deprecated CV_NODISCARD, already unused in the codebase * Removed some pre-C++11 workarounds, and simplified some backwards compat defines * Removed CV_CXX_STD_ARRAY * Removed CV_CXX_MOVE_SEMANTICS and CV_CXX_MOVE * Removed all tests of CV_CXX11, now assume it's always true. This allowed removing a lot of dead code. * Updated some documentation consequently. * Removed all tests of CV_CXX11, now assume it's always true * Fixed links. --------- Co-authored-by: Maksim Shabunin <maksim.shabunin@gmail.com> Co-authored-by: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "precomp.hpp"
|
||||
//#undef CV_CXX11 // debug non C++11 mode
|
||||
#include "opencv2/core/async.hpp"
|
||||
#include "opencv2/core/detail/async_promise.hpp"
|
||||
|
||||
@@ -16,11 +15,9 @@
|
||||
|
||||
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
|
||||
|
||||
#ifdef CV_CXX11
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
|
||||
@@ -37,12 +34,8 @@ struct AsyncArray::Impl
|
||||
void releasePromise() CV_NOEXCEPT { CV_XADD(&refcount_promise, -1); if(1 == CV_XADD(&refcount, -1)) delete this; } \
|
||||
int refcount_promise;
|
||||
|
||||
#ifdef CV_CXX11
|
||||
mutable std::mutex mtx;
|
||||
mutable std::condition_variable cond_var;
|
||||
#else
|
||||
mutable cv::Mutex mtx;
|
||||
#endif
|
||||
|
||||
mutable bool has_result; // Mat, UMat or exception
|
||||
|
||||
@@ -88,11 +81,7 @@ struct AsyncArray::Impl
|
||||
if (!wait_for(timeoutNs))
|
||||
return false;
|
||||
}
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
if (has_result)
|
||||
{
|
||||
if (!result_mat.empty())
|
||||
@@ -145,7 +134,6 @@ struct AsyncArray::Impl
|
||||
if (timeoutNs == 0)
|
||||
return has_result;
|
||||
CV_LOG_INFO(NULL, "Waiting for async result ...");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
const auto cond_pred = [&]{ return has_result == true; };
|
||||
if (timeoutNs > 0)
|
||||
@@ -156,9 +144,6 @@ struct AsyncArray::Impl
|
||||
CV_Assert(has_result);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
CV_Error(Error::StsNotImplemented, "OpenCV has been built without async waiting support (C++11 is required)");
|
||||
#endif
|
||||
}
|
||||
|
||||
AsyncArray getArrayResult()
|
||||
@@ -175,11 +160,7 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
int k = value.kind();
|
||||
if (k == _InputArray::UMAT)
|
||||
@@ -193,9 +174,7 @@ struct AsyncArray::Impl
|
||||
value.copyTo(*result_mat.get());
|
||||
}
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CV__EXCEPTION_PTR
|
||||
@@ -203,18 +182,12 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
has_exception = true;
|
||||
exception = e;
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -222,18 +195,12 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
has_exception = true;
|
||||
cv_exception = e;
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1919,12 +1919,7 @@ void _OutputArray::move(UMat& u) const
|
||||
int k = kind();
|
||||
if (k == UMAT)
|
||||
{
|
||||
#ifdef CV_CXX11
|
||||
*(UMat*)obj = std::move(u);
|
||||
#else
|
||||
*(UMat*)obj = u;
|
||||
u.release();
|
||||
#endif
|
||||
}
|
||||
else if (k == MAT)
|
||||
{
|
||||
@@ -1959,12 +1954,7 @@ void _OutputArray::move(Mat& m) const
|
||||
}
|
||||
else if (k == MAT)
|
||||
{
|
||||
#ifdef CV_CXX11
|
||||
*(Mat*)obj = std::move(m);
|
||||
#else
|
||||
*(Mat*)obj = m;
|
||||
m.release();
|
||||
#endif
|
||||
}
|
||||
else if (k == MATX)
|
||||
{
|
||||
|
||||
@@ -912,8 +912,7 @@ int getNumberOfCPUs_()
|
||||
* the minimum most value as it has high probablity of being right and safe.
|
||||
* Return 1 if we get 0 or not found on all methods.
|
||||
*/
|
||||
#if defined CV_CXX11 \
|
||||
&& !defined(__MINGW32__) /* not implemented (2020-03) */ \
|
||||
#if !defined(__MINGW32__) /* not implemented (2020-03) */
|
||||
|
||||
/*
|
||||
* Check for this standard C++11 way, we do not return directly because
|
||||
|
||||
@@ -305,9 +305,7 @@ DECLARE_CV_CPUID_X86
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined CV_CXX11
|
||||
#include <chrono>
|
||||
#endif
|
||||
#include <chrono>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -909,50 +907,15 @@ bool useOptimized(void)
|
||||
|
||||
int64 getTickCount(void)
|
||||
{
|
||||
#if defined CV_CXX11
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
return (int64)now.time_since_epoch().count();
|
||||
#elif defined _WIN32 || defined WINCE
|
||||
LARGE_INTEGER counter;
|
||||
QueryPerformanceCounter( &counter );
|
||||
return (int64)counter.QuadPart;
|
||||
#elif defined __MACH__ && defined __APPLE__
|
||||
return (int64)mach_absolute_time();
|
||||
#elif defined __unix__
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
return (int64)tp.tv_sec*1000000000 + tp.tv_nsec;
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (int64)tv.tv_sec*1000000 + tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
double getTickFrequency(void)
|
||||
{
|
||||
#if defined CV_CXX11
|
||||
using clock_period_t = std::chrono::steady_clock::duration::period;
|
||||
double clock_freq = clock_period_t::den / clock_period_t::num;
|
||||
return clock_freq;
|
||||
#elif defined _WIN32 || defined WINCE
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
return (double)freq.QuadPart;
|
||||
#elif defined __MACH__ && defined __APPLE__
|
||||
static double freq = 0;
|
||||
if( freq == 0 )
|
||||
{
|
||||
mach_timebase_info_data_t sTimebaseInfo;
|
||||
mach_timebase_info(&sTimebaseInfo);
|
||||
freq = sTimebaseInfo.denom*1e9/sTimebaseInfo.numer;
|
||||
}
|
||||
return freq;
|
||||
#elif defined __unix__
|
||||
return 1e9;
|
||||
#else
|
||||
return 1e6;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __ppc__)
|
||||
|
||||
Reference in New Issue
Block a user