domfarolino / browser

Simple browser components
4 stars 1 forks source link

Fix & simplify base::SimpleThread + add tests + fix race condition #31

Closed domfarolino closed 3 years ago

domfarolino commented 3 years ago

This PR closes #27, the fact that base::SimpleThread could only accept parameters by std::ref() or rvalue reference. I fix this by greatly simplifying how we take in functions and parameters, and store all of this in a std::function<void()> and invoke it during SimpleThreadDelegate::Run(). At the same time we get to remove the entire base::helper namespace, and rename base/helper.h to base/callback.h.

This PR also fixes a race condition in TaskLoopForWorker::Quit(), by grabbing a lock before setting quit_ = true. This was causing the RunQuitRunQuit test to occasionally timeout.

Inspiration: https://stackoverflow.com/questions/66501654/