michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkCountdown.h" michael@0: #include "SkThread.h" michael@0: michael@0: SkCountdown::SkCountdown(int32_t count) michael@0: : fCount(count) {} michael@0: michael@0: void SkCountdown::reset(int32_t count) { michael@0: fCount = count; michael@0: } michael@0: michael@0: void SkCountdown::run() { michael@0: if (sk_atomic_dec(&fCount) == 1) { michael@0: fReady.lock(); michael@0: fReady.signal(); michael@0: fReady.unlock(); michael@0: } michael@0: } michael@0: michael@0: void SkCountdown::wait() { michael@0: fReady.lock(); michael@0: while (fCount > 0) { michael@0: fReady.wait(); michael@0: } michael@0: fReady.unlock(); michael@0: }