From 7c21e0b6b184e4dd0b7e119f470089a4149b6e2d Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Thu, 5 Jul 2018 12:17:45 -0400 Subject: [PATCH] CPU works less if queues are full or empty --- doc/release_notes.md | 1 + include/openpose/thread/subThreadQueueIn.hpp | 5 ++++- include/openpose/thread/subThreadQueueInOut.hpp | 5 +++++ include/openpose/thread/subThreadQueueOut.hpp | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.md b/doc/release_notes.md index 58e1c727d..62e7e1b4b 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -243,6 +243,7 @@ OpenPose Library - Release Notes 18. Speed up of cvMatToOpOutput and opOutputToCvMat: op::Datum::outputData is now H x W x C instead of C x H x W, making it much faster to be copied to/from op::Datum::cvOutputData. 19. Much faster GUI display by adding the `WITH_OPENCV_WITH_OPENGL` flag to tell whether to use OpenGL support for OpenCV. 20. Turned security check error into warning when using dynamic `net_resolution` for `image_dir` in CPU/OpenCL versions. + 21. Minimized CPU usage when queues are empty or full, in order to prevent problems such as general computer slow down, overheating, or excesive power usage. 2. Functions or parameters renamed: 1. Removed scale parameter from hand and face rectangle extractor (causing wrong results if custom `--output_resolution`). 2. Functions `scaleKeypoints`, other than `scaleKeypoints(Array& keypoints, const float scale)`, renamed as `scaleKeypoints2d`. diff --git a/include/openpose/thread/subThreadQueueIn.hpp b/include/openpose/thread/subThreadQueueIn.hpp index b2e3df831..3786426f8 100644 --- a/include/openpose/thread/subThreadQueueIn.hpp +++ b/include/openpose/thread/subThreadQueueIn.hpp @@ -31,7 +31,8 @@ namespace op namespace op { template - SubThreadQueueIn::SubThreadQueueIn(const std::vector& tWorkers, const std::shared_ptr& tQueueIn) : + SubThreadQueueIn::SubThreadQueueIn(const std::vector& tWorkers, + const std::shared_ptr& tQueueIn) : SubThread{tWorkers}, spTQueueIn{tQueueIn} { @@ -44,6 +45,8 @@ namespace op try { // Pop TDatums + if (spTQueueIn->empty()) + std::this_thread::sleep_for(std::chrono::microseconds{100}); TDatums tDatums; bool queueIsRunning = spTQueueIn->tryPop(tDatums); // Check queue not empty diff --git a/include/openpose/thread/subThreadQueueInOut.hpp b/include/openpose/thread/subThreadQueueInOut.hpp index ce6310c22..edf44fc41 100644 --- a/include/openpose/thread/subThreadQueueInOut.hpp +++ b/include/openpose/thread/subThreadQueueInOut.hpp @@ -61,6 +61,8 @@ namespace op if (!spTQueueOut->isFull()) { // Pop TDatums + if (spTQueueIn->empty()) + std::this_thread::sleep_for(std::chrono::microseconds{100}); TDatums tDatums; bool workersAreRunning = spTQueueIn->tryPop(tDatums); // Check queue not stopped @@ -83,7 +85,10 @@ namespace op return workersAreRunning; } else + { + std::this_thread::sleep_for(std::chrono::microseconds{100}); return true; + } } } catch (const std::exception& e) diff --git a/include/openpose/thread/subThreadQueueOut.hpp b/include/openpose/thread/subThreadQueueOut.hpp index 289aefbb2..bd02480c2 100644 --- a/include/openpose/thread/subThreadQueueOut.hpp +++ b/include/openpose/thread/subThreadQueueOut.hpp @@ -68,7 +68,10 @@ namespace op return workersAreRunning; } else + { + std::this_thread::sleep_for(std::chrono::microseconds{100}); return true; + } } } catch (const std::exception& e)