[build][option] Introduce OPENCV_DISABLE_THREAD_SUPPORT option.#19985
[build][option] Introduce OPENCV_DISABLE_THREAD_SUPPORT option.#19985alalek merged 3 commits intoopencv:masterfrom
OPENCV_DISABLE_THREAD_SUPPORT option.#19985Conversation
|
HI @alalek - I am taking the comment at #19921 (comment) here as it seems specific to this PR.
Are you saying that code that is depending on If that's the case, I think it would make sense to merge the stubs in the |
|
That comment is about stubs for OpenCV types, like |
I see - thank you for explaining @alalek . Are there any other class I should be aware of that I should conditionally redefined based on the macro
Yep, but I thought that was wanted me to do with the "port" file that you wanted me to create in #19921 I didn't get as far as implementing the rest of the If we want the option |
|
@vpisarev - is the arm64 builder at https://build.opencv.org.cn/job/precommit/job/ubuntu-20.04-arm64/ broken? Or is the failure of the latest commit a genuine failure caused by my commit? |
9088150 to
a98c5cd
Compare
a98c5cd to
47d8b59
Compare
5039985 to
efa162f
Compare
efa162f to
9a875e2
Compare
CV_DISABLE_MULTI_THREAD option.OPENCV_DISABLE_THREAD_SUPPORT option.
|
Thank you for the review, @alalek ! |
| #if defined(CV_CXX11) && !defined(OPENCV_DISABLE_THREAD_SUPPORT) | ||
| std::unique_lock<std::mutex> lock(mtx); | ||
| #else | ||
| cv::AutoLock lock(mtx); |
There was a problem hiding this comment.
"#else" non C++11 branch is candidate for removal.
This patch forces to keep this.
IMHO, we need dedicated implementation for AsyncArray for case without threads (or even forbid using of this).
There was a problem hiding this comment.
I am happy to provide an implementation of AsyncArray that does not use threads. I'll give it a go, but I might need some guidance on this.
Just to make sure I am going in the right direction. You want me to have a big #ifundef / #else / #endif switch where the #else branch exposes the curret implementation (threaded) of AsyncArray, while the #ifundef OPENCV_DISABLE_THREAD_SUPPORT will implement AsyncArray without using threads (ro shoudl it be just stubs?).
Also, what the alternative...
even forbid using of this
... consist of? Disabling the use of AsyncArray in all places where it is used?
There was a problem hiding this comment.
Stub with exceptions should work for now (there are no many places which uses AsyncArray)
There was a problem hiding this comment.
I started providing stubs for the API of cv::AsyncArray, and it turned out I also need to provide stubs for cv::AsyncPromise. The approach I followed was to remove the AsyncArray::Impl definition and uses. This however caused writing many #ifundef / #else / #endif cases, which doesn't seem to fit very well with the goal of miniming such cases.
Would it be OK if instead of providing stubs for cv::AsyncArray and cv::AsyncPromise, I would be providing a stub class AsyncArray::Impl that would expose stubs only for the methods used by cv::AsyncArray and cv::AsyncPromise? This solution would still provide useful exception message, and would require just a couple of #ifundef / #else / #endif cases.
|
Thank you for the review @alalek ! |
9a875e2 to
6c73396
Compare
|
@alalek - thank you for the review. The baremetal builds are still running correctly even after the changes you requested, this is very nice. As a matter of fact, I need more feedback from you about #19985 (comment), as I am not 100% sure what I have done is the right thing. Thank you again, Francesco |
6c73396 to
323b07d
Compare
|
@alalek - please note that, once you accept this patch, I think that the commits in this patch should be squashed before merging it into master. |
323b07d to
9b988c3
Compare
CMakeLists.txt
Outdated
| endif() | ||
|
|
||
| if(OPENCV_DISABLE_THREAD_SUPPORT) | ||
| add_definitions(-DOPENCV_DISABLE_THREAD_SUPPORT) |
There was a problem hiding this comment.
The option is not exported to OpenCV-config.cmake and other build configs. All methods in header files will use another pre-processor branch and break user code.
There was a problem hiding this comment.
I am happy to do the export of the variable but I am not sure I understand the issue.
Also, how can I export OPENCV_DISABLE_THREAD_SUPPORT in OpenCV-config.cmake? I have looked a bit into cmake/OpenCVGenConfig.cmake but I am missing the mechanism that does this export.
|
@alalek @asmorkalov - Thank you for the review. Apologies for the delay in getting back to you but I was OoO. Francesco |
a6f0039 to
608fec0
Compare
|
Hi @alalek - thank you for the patch that you have added on top of my changes. Extracting the cmake commands in a separate file and reducing the number of Unfortunately, the changes are breaking the build for the While I am at that, I will also merge all the commits of #19985 marked with "to squash" into a single commit (I won't include your commit in the squash). Francesco |
1b8cbc4 to
bb90145
Compare
|
@alalek @asmorkalov - gentle ping! Francesco |
|
reverted commit with I'm unable to check #19921 (proposed toolchain requires AARCH64 host - I don't have such configured setup for development), please take a look on your side. |
|
Patch is rebased to resolve conflict in |
The option forces the library to build without thread support.
- reduce amount of #if conditions
1ef79f6 to
30a81fd
Compare
|
@alalek , thank you for looking into this code again.
#19921 is still to considered a WIP. There is no need to review it for now. I'd rather have this PR (#19985 ) done and dusted before asking you to look in the baremetal one. We have CI that depends on #19921 , for now I just keep updating it to make our CI happy again when things start failing because of updates or merges. |
CMakeLists.txt
Outdated
|
|
||
| if (OPENCV_DISABLE_THREAD_SUPPORT) | ||
| set(WITH_GSTREAMER OFF) | ||
| endif() |
There was a problem hiding this comment.
Why do we need this?
It should be handled in cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake: https://github.com/opencv/opencv/pull/19985/files#diff-87b6de92e07d14f041e4b331f8936a5d5a4f2f8e499aa71bc3967de40cff9960
Please avoid any specific changes in root CMakeLists.txt - it should not manage details of 3rdparty components (otherwise we would get unsupportable huge mess)
Ensure that you have clean CMake cache (after code update)
There was a problem hiding this comment.
It should be handled in cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake
I agree, sorry, I keep forgetting about this file and I end up running in the same issue everytime I was recompiling after changing branch because...
Ensure that you have clean CMake cache (after code update)
... I was not aware of this trick! Thank you. I am going to remove the last commit with this change.
30a81fd to
0d819b1
Compare
* [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option. The option forces the library to build without thread support. * update handling of OPENCV_DISABLE_THREAD_SUPPORT - reduce amount of #if conditions * [to squash] cmake: apply mode vars in toolchains too Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
The option forces the library to build without the use of
#include <thread>. The modules for which this is not possible has beenconditionally disabled when the option is active.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.