aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkCountdown.cpp
blob: 98b35450717721d3baefe661defd004d82bcb042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkCountdown.h"
#include "SkThread.h"

SkCountdown::SkCountdown(int32_t count)
: fCount(count) {}

void SkCountdown::reset(int32_t count) {
    fCount = count;
}

void SkCountdown::run() {
    if (sk_atomic_dec(&fCount) == 1) {
        fReady.lock();
        fReady.signal();
        fReady.unlock();
    }
}

void SkCountdown::wait() {
    fReady.lock();
    while (fCount > 0) {
        fReady.wait();
    }
    fReady.unlock();
}