~michihenning/thumbnailer/fix-hit-rate

« back to all changes in this revision

Viewing changes to src/ratelimiter.cpp

  • Committer: Tarmac
  • Author(s): Michi Henning
  • Date: 2015-10-14 05:11:41 UTC
  • mfrom: (278.4.20 qt-rate-limiter)
  • Revision ID: tarmac-20151014051141-kyem0nctbyjgrczs
Moved rate limiter from QML to Qt side.
Fixed bug in libthumbnailer-qt that caused the state of completed request to not be released.
Changed stress test to test the rate limiting via Qt.

Approved by PS Jenkins bot, James Henstridge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    assert(running_ == 0);
42
42
}
43
43
 
44
 
function<void()> RateLimiter::schedule(function<void()> job)
 
44
function<void() noexcept> RateLimiter::schedule(function<void()> job)
45
45
{
46
46
    assert(job);
47
47
 
58
58
    // Returned function clears job when called, provided the job is still in the queue.
59
59
    // done() removes any cleared jobs from the queue without calling them.
60
60
    weak_ptr<function<void()>> weak_p(job_p);
61
 
    return [weak_p]
 
61
    return [weak_p]() noexcept
62
62
    {
63
63
        auto job_p = weak_p.lock();
64
64
        if (job_p)