1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

next: drop CV_CXX11 conditions

define itself is still here for compatibility
This commit is contained in:
Alexander Alekhin
2018-03-22 14:51:39 +03:00
parent 2b2fa58f97
commit 98c8584b88
18 changed files with 6 additions and 281 deletions
+3 -44
View File
@@ -21,27 +21,15 @@
//#define CV_USE_GLOBAL_WORKERS_COND_VAR // not effective on many-core systems (10+)
#ifdef CV_CXX11
#include <atomic>
#else
#include <unistd.h> // _POSIX_PRIORITY_SCHEDULING
#endif
// Spin lock's OS-level yield
#ifdef DECLARE_CV_YIELD
DECLARE_CV_YIELD
#endif
#ifndef CV_YIELD
# ifdef CV_CXX11
# include <thread>
# define CV_YIELD() std::this_thread::yield()
# elif defined(_POSIX_PRIORITY_SCHEDULING)
# include <sched.h>
# define CV_YIELD() sched_yield()
# else
# warning "Can't detect sched_yield() on the target platform. Specify CV_YIELD() definition via compiler flags."
# define CV_YIELD() /* no-op: works, but not effective */
# endif
# include <thread>
# define CV_YIELD() std::this_thread::yield()
#endif // CV_YIELD
// Spin lock's CPU-level yield (required for Hyper-Threading)
@@ -290,15 +278,9 @@ public:
is_completed(false)
{
CV_LOG_VERBOSE(NULL, 5, "ParallelJob::ParallelJob(" << (void*)this << ")");
#ifdef CV_CXX11
current_task.store(0, std::memory_order_relaxed);
active_thread_count.store(0, std::memory_order_relaxed);
completed_thread_count.store(0, std::memory_order_relaxed);
#else
current_task = 0;
active_thread_count = 0;
completed_thread_count = 0;
#endif
dummy0_[0] = 0, dummy1_[0] = 0, dummy2_[0] = 0; // compiler warning
}
@@ -319,11 +301,7 @@ public:
for (;;)
{
int chunk_size = std::max(1, (task_count - current_task) / remaining_multiplier);
#ifdef CV_CXX11
int id = current_task.fetch_add(chunk_size, std::memory_order_seq_cst);
#else
int id = (int)CV_XADD(&current_task, chunk_size);
#endif
if (id >= task_count)
break; // no more free tasks
@@ -349,7 +327,7 @@ public:
const ParallelLoopBody& body;
const Range range;
const unsigned nstripes;
#ifdef CV_CXX11
std::atomic<int> current_task; // next free part of job
int64 dummy0_[8]; // avoid cache-line reusing for the same atomics
@@ -358,16 +336,6 @@ public:
std::atomic<int> completed_thread_count; // number of threads completed any activities on this job
int64 dummy2_[8]; // avoid cache-line reusing for the same atomics
#else
/*CV_DECL_ALIGNED(64)*/ volatile int current_task; // next free part of job
int64 dummy0_[8]; // avoid cache-line reusing for the same atomics
/*CV_DECL_ALIGNED(64)*/ volatile int active_thread_count; // number of threads worked on this job
int64 dummy1_[8]; // avoid cache-line reusing for the same atomics
/*CV_DECL_ALIGNED(64)*/ volatile int completed_thread_count; // number of threads completed any activities on this job
int64 dummy2_[8]; // avoid cache-line reusing for the same atomics
#endif
volatile bool is_completed; // std::atomic_flag ?
@@ -437,11 +405,7 @@ void WorkerThread::thread_body()
CV_LOG_VERBOSE(NULL, 5, "Thread: job size=" << j->range.size() << " done=" << j->current_task);
if (j->current_task < j->range.size())
{
#ifdef CV_CXX11
int other = j->active_thread_count.fetch_add(1, std::memory_order_seq_cst);
#else
int other = CV_XADD(&j->active_thread_count, 1);
#endif
CV_LOG_VERBOSE(NULL, 5, "Thread: processing new job (with " << other << " other threads)"); CV_UNUSED(other);
#ifdef CV_PROFILE_THREADS
stat.threadExecuteStart = getTickCount();
@@ -450,13 +414,8 @@ void WorkerThread::thread_body()
#else
j->execute(true);
#endif
#ifdef CV_CXX11
int completed = j->completed_thread_count.fetch_add(1, std::memory_order_seq_cst) + 1;
int active = j->active_thread_count.load(std::memory_order_acquire);
#else
int completed = (int)CV_XADD(&j->completed_thread_count, 1) + 1;
int active = j->active_thread_count;
#endif
if (CV_WORKER_ACTIVE_WAIT_THREADS_LIMIT > 0)
{
allow_active_wait = true;