gfx/skia/trunk/src/core/SkTLS.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkTLS.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +//
     1.5 +//  SkTLS.h
     1.6 +//
     1.7 +//
     1.8 +//  Created by Mike Reed on 4/21/12.
     1.9 +//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#ifndef SkTLS_DEFINED
    1.13 +#define SkTLS_DEFINED
    1.14 +
    1.15 +#include "SkTypes.h"
    1.16 +
    1.17 +/**
    1.18 + *  Maintains a per-thread cache, using a CreateProc as the key into that cache.
    1.19 + */
    1.20 +class SkTLS {
    1.21 +public:
    1.22 +    typedef void* (*CreateProc)();
    1.23 +    typedef void  (*DeleteProc)(void*);
    1.24 +
    1.25 +    /**
    1.26 +     *  If Get() has previously been called with this CreateProc, then this
    1.27 +     *  returns its cached data, otherwise it returns NULL. The CreateProc is
    1.28 +     *  never invoked in Find, it is only used as a key for searching the
    1.29 +     *  cache.
    1.30 +     */
    1.31 +    static void* Find(CreateProc);
    1.32 +
    1.33 +    /**
    1.34 +     *  Return the cached data that was returned by the CreateProc. This proc
    1.35 +     *  is only called the first time Get is called, and there after it is
    1.36 +     *  cached (per-thread), using the CreateProc as a key to look it up.
    1.37 +     *
    1.38 +     *  When this thread, or Delete is called, the cached data is removed, and
    1.39 +     *  if a DeleteProc was specified, it is passed the pointer to the cached
    1.40 +     *  data.
    1.41 +     */
    1.42 +    static void* Get(CreateProc, DeleteProc);
    1.43 +
    1.44 +    /**
    1.45 +     *  Remove (optionally calling the DeleteProc if it was specificed in Get)
    1.46 +     *  the cached data associated with this CreateProc. If no associated cached
    1.47 +     *  data is found, do nothing.
    1.48 +     */
    1.49 +    static void Delete(CreateProc);
    1.50 +
    1.51 +private:
    1.52 +    // Our implementation requires only 1 TLS slot, as we manage multiple values
    1.53 +    // ourselves in a list, with the platform specific value as our head.
    1.54 +
    1.55 +    /**
    1.56 +     *  Implemented by the platform, to return the value of our (one) slot per-thread
    1.57 +     *
    1.58 +     *  If forceCreateTheSlot is true, then we must have created the "slot" for
    1.59 +     *  our TLS, even though we know that the return value will be NULL in that
    1.60 +     *  case (i.e. no-slot and first-time-slot both return NULL). This ensures
    1.61 +     *  that after calling GetSpecific, we know that we can legally call
    1.62 +     *  SetSpecific.
    1.63 +     *
    1.64 +     *  If forceCreateTheSlot is false, then the impl can either create the
    1.65 +     *  slot or not.
    1.66 +     */
    1.67 +    static void* PlatformGetSpecific(bool forceCreateTheSlot);
    1.68 +
    1.69 +    /**
    1.70 +     *  Implemented by the platform, to set the value for our (one) slot per-thread
    1.71 +     *
    1.72 +     *  The implementation can rely on GetSpecific(true) having been previously
    1.73 +     *  called before SetSpecific is called.
    1.74 +     */
    1.75 +    static void  PlatformSetSpecific(void*);
    1.76 +
    1.77 +public:
    1.78 +    /**
    1.79 +     *  Will delete our internal list. To be called by the platform if/when its
    1.80 +     *  TLS slot is deleted (often at thread shutdown).
    1.81 +     *
    1.82 +     *  Public *only* for the platform's use, not to be called by a client.
    1.83 +     */
    1.84 +    static void Destructor(void* ptr);
    1.85 +};
    1.86 +
    1.87 +#endif

mercurial