-
Notifications
You must be signed in to change notification settings - Fork 197
Conversation
That's a brilliant work. I have some questions which I'll post inline. |
Basically this is just removing the custom class and using a typedef to keep the name. Most of the changes are just case for the lock/unlock methods.
Just use Mutex and remove the need to call Thread::Init()
Use a typedef to maintain the name and use Guard for simple scoped lock guards and UniqueLock when it needs to be movable.
Thanks for applying the changes and a special thank for updating the commits instead of adding new commits with small corrections. I like the clean history. I have one more small thing - will post an inline comment. |
else | ||
{ | ||
// Wait until we get the stop signal or more jobs in the queue | ||
std::unique_lock<std::mutex> lk(m_pauseMutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be:
UniqueLock lk(m_pauseMutex);
Maybe also better to use name guard
just like in all other places? Not sure about that though.
Consequently m_pauseMutex
should be declared as Mutex
instead of std::mutex
.
And similarly in FeedCoordinator.cpp/.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also better to use name guard just like in all other places? Not sure about that though.
Yeah, I thought about that but as the type is std::unique_lock lock I left it like that because it better matches the real type.
Changed the rest.
Before only m_threadCount was protected by a mutex but not the rest of the bools that are read/written from different threads. This replaces them by atomic values removing the need for the mutex and protecting the previously unprotected bools, except for m_autoDestroy that it's only set before starting the thread.
Simplify thread handling by using std::thread.
When in deamon mode, just wait for the Stop signal instead of looping constantly, in a way that doesn't affect responsiveness.
Wait until new jobs or a Stop signal instead of looping, in a way that doesn't reduce responsiveness.
Loop every second waiting on a condition variable to reduce the number of CPU wake ups and keep responsiveness.
I've run into an issue when compiling for linux installer package (cross compiling for many CPU architectures). The compilation for armel breaks with:
After searching found this explanation. In short (read the link for details):
Do you have an alternative solution without promise/future maybe? If you don't I would need to |
I think we can use |
Yes, it can be replaced by condition_variable, but it's a shame that it doesn't work for armel because that means we won't be able to use async or packed_task either probably. I'll see what I can find about it. |
Apparently it's already fixed in gcc https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64735 Which compiler version is failing? |
It's GCC 5.2. Even though the problem seems to be fixed in GCC 7.0 I cannot easily drop support of older GCC versions. Armel is an important platform. It was a pain for some users when I migrated to C 11/14 with requirement for GCC 4.9. Even GCC 4.8 supported (but only when compiling in release mode) and I intentionally don't use some C features not available on GCC 4.8 in order to maintain compatibility. Changing system requirements of NZBGet to higher GCC version is possible but it has to bring a big advantage to the project. A simple "there is one place where we could use a new compiler feature" isn't such case. The switch from C 98 to C 11/14 was such case. If promise/future or async or packed_task will allow to for example increase performance to 10% then the switch may be worth it. If these features just allow to save a couple of lines of code then no. Maintaining compatibility with many platforms is indeed painful and has costs. |
debian has backported it to gcc-6 but I see your point. It's a shame because it's not really a requirement of a higher c standard but a bug in gcc. In any case, it's not a big deal to use condition_variable instead. |
in GCC 5 for armel. Promise/future are not supported there and were replaced with condition_variable.
This PRs simplifies mutex and threads, fixes some unprotected members and includes a few changes to improve CPU usage when idle.
Part of a solution to #351