gfx/skia/trunk/include/utils/SkCondVar.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/utils/SkCondVar.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     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 +#ifndef SkCondVar_DEFINED
    1.12 +#define SkCondVar_DEFINED
    1.13 +
    1.14 +#ifdef SK_USE_POSIX_THREADS
    1.15 +#include <pthread.h>
    1.16 +#elif defined(SK_BUILD_FOR_WIN32)
    1.17 +#include <windows.h>
    1.18 +#endif
    1.19 +
    1.20 +/**
    1.21 + * Condition variable for blocking access to shared data from other threads and
    1.22 + * controlling which threads are awake.
    1.23 + *
    1.24 + * Currently only supported on platforms with posix threads and Windows Vista and
    1.25 + * above.
    1.26 + */
    1.27 +class SkCondVar {
    1.28 +public:
    1.29 +    SkCondVar();
    1.30 +    ~SkCondVar();
    1.31 +
    1.32 +    /**
    1.33 +     * Lock a mutex. Must be done before calling the other functions on this object.
    1.34 +     */
    1.35 +    void lock();
    1.36 +
    1.37 +    /**
    1.38 +     * Unlock the mutex.
    1.39 +     */
    1.40 +    void unlock();
    1.41 +
    1.42 +    /**
    1.43 +     * Pause the calling thread. Will be awoken when signal() or broadcast() is called.
    1.44 +     * Must be called while lock() is held (but gives it up while waiting). Once awoken,
    1.45 +     * the calling thread will hold the lock once again.
    1.46 +     */
    1.47 +    void wait();
    1.48 +
    1.49 +    /**
    1.50 +     * Wake one thread waiting on this condition. Must be called while lock()
    1.51 +     * is held.
    1.52 +     */
    1.53 +    void signal();
    1.54 +
    1.55 +    /**
    1.56 +     * Wake all threads waiting on this condition. Must be called while lock()
    1.57 +     * is held.
    1.58 +     */
    1.59 +    void broadcast();
    1.60 +
    1.61 +private:
    1.62 +#ifdef SK_USE_POSIX_THREADS
    1.63 +    pthread_mutex_t  fMutex;
    1.64 +    pthread_cond_t   fCond;
    1.65 +#elif defined(SK_BUILD_FOR_WIN32)
    1.66 +    CRITICAL_SECTION   fCriticalSection;
    1.67 +    CONDITION_VARIABLE fCondition;
    1.68 +#endif
    1.69 +};
    1.70 +
    1.71 +#endif

mercurial