1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/utils/SkCountdown.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkCountdown.h" 1.12 +#include "SkThread.h" 1.13 + 1.14 +SkCountdown::SkCountdown(int32_t count) 1.15 +: fCount(count) {} 1.16 + 1.17 +void SkCountdown::reset(int32_t count) { 1.18 + fCount = count; 1.19 +} 1.20 + 1.21 +void SkCountdown::run() { 1.22 + if (sk_atomic_dec(&fCount) == 1) { 1.23 + fReady.lock(); 1.24 + fReady.signal(); 1.25 + fReady.unlock(); 1.26 + } 1.27 +} 1.28 + 1.29 +void SkCountdown::wait() { 1.30 + fReady.lock(); 1.31 + while (fCount > 0) { 1.32 + fReady.wait(); 1.33 + } 1.34 + fReady.unlock(); 1.35 +}