gfx/skia/trunk/include/core/SkThread.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkThread.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     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 SkThread_DEFINED
    1.12 +#define SkThread_DEFINED
    1.13 +
    1.14 +#include "SkTypes.h"
    1.15 +
    1.16 +// SK_ATOMICS_PLATFORM_H must provide inline implementations for the following declarations.
    1.17 +
    1.18 +/** Atomically adds one to the int referenced by addr and returns the previous value.
    1.19 + *  No additional memory barrier is required; this must act as a compiler barrier.
    1.20 + */
    1.21 +static int32_t sk_atomic_inc(int32_t* addr);
    1.22 +
    1.23 +/** Atomically adds inc to the int referenced by addr and returns the previous value.
    1.24 + *  No additional memory barrier is required; this must act as a compiler barrier.
    1.25 + */
    1.26 +static int32_t sk_atomic_add(int32_t* addr, int32_t inc);
    1.27 +
    1.28 +/** Atomically subtracts one from the int referenced by addr and returns the previous value.
    1.29 + *  This must act as a release (SL/S) memory barrier and as a compiler barrier.
    1.30 + */
    1.31 +static int32_t sk_atomic_dec(int32_t* addr);
    1.32 +
    1.33 +/** Atomically adds one to the int referenced by addr iff the referenced int was not 0
    1.34 + *  and returns the previous value.
    1.35 + *  No additional memory barrier is required; this must act as a compiler barrier.
    1.36 + */
    1.37 +static int32_t sk_atomic_conditional_inc(int32_t* addr);
    1.38 +
    1.39 +/** Atomic compare and set.
    1.40 + *  If *addr == before, set *addr to after and return true, otherwise return false.
    1.41 + *  This must act as a release (SL/S) memory barrier and as a compiler barrier.
    1.42 + */
    1.43 +static bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after);
    1.44 +
    1.45 +/** If sk_atomic_dec does not act as an acquire (L/SL) barrier,
    1.46 + *  this must act as an acquire (L/SL) memory barrier and as a compiler barrier.
    1.47 + */
    1.48 +static void sk_membar_acquire__after_atomic_dec();
    1.49 +
    1.50 +/** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier,
    1.51 + *  this must act as an acquire (L/SL) memory barrier and as a compiler barrier.
    1.52 + */
    1.53 +static void sk_membar_acquire__after_atomic_conditional_inc();
    1.54 +
    1.55 +#include SK_ATOMICS_PLATFORM_H
    1.56 +
    1.57 +/** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations.
    1.58 +
    1.59 +class SkBaseMutex {
    1.60 +public:
    1.61 +    void acquire();
    1.62 +    void release();
    1.63 +};
    1.64 +
    1.65 +class SkMutex : SkBaseMutex {
    1.66 +public:
    1.67 +    SkMutex();
    1.68 +    ~SkMutex();
    1.69 +};
    1.70 +
    1.71 +#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ...
    1.72 +#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = ...
    1.73 +*/
    1.74 +
    1.75 +#include SK_MUTEX_PLATFORM_H
    1.76 +
    1.77 +
    1.78 +class SkAutoMutexAcquire : SkNoncopyable {
    1.79 +public:
    1.80 +    explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) {
    1.81 +        SkASSERT(fMutex != NULL);
    1.82 +        mutex.acquire();
    1.83 +    }
    1.84 +
    1.85 +    explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) {
    1.86 +        if (mutex) {
    1.87 +            mutex->acquire();
    1.88 +        }
    1.89 +    }
    1.90 +
    1.91 +    /** If the mutex has not been released, release it now. */
    1.92 +    ~SkAutoMutexAcquire() {
    1.93 +        if (fMutex) {
    1.94 +            fMutex->release();
    1.95 +        }
    1.96 +    }
    1.97 +
    1.98 +    /** If the mutex has not been released, release it now. */
    1.99 +    void release() {
   1.100 +        if (fMutex) {
   1.101 +            fMutex->release();
   1.102 +            fMutex = NULL;
   1.103 +        }
   1.104 +    }
   1.105 +
   1.106 +private:
   1.107 +    SkBaseMutex* fMutex;
   1.108 +};
   1.109 +#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
   1.110 +
   1.111 +#endif

mercurial