reed@google.com | e6f7d68 | 2012-04-23 12:51:32 +0000 | [diff] [blame] | 1 | // |
| 2 | // SkTLS.h |
| 3 | // |
| 4 | // |
| 5 | // Created by Mike Reed on 4/21/12. |
| 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #ifndef SkTLS_DEFINED |
| 10 | #define SkTLS_DEFINED |
| 11 | |
| 12 | #include "SkTypes.h" |
| 13 | |
reed@google.com | ae1b6b6 | 2012-04-23 15:49:45 +0000 | [diff] [blame^] | 14 | /** |
| 15 | * Maintains a per-thread cache, using a CreateProc as the key into that cache. |
| 16 | */ |
reed@google.com | e6f7d68 | 2012-04-23 12:51:32 +0000 | [diff] [blame] | 17 | class SkTLS { |
| 18 | public: |
| 19 | typedef void* (*CreateProc)(); |
| 20 | typedef void (*DeleteProc)(void*); |
reed@google.com | ae1b6b6 | 2012-04-23 15:49:45 +0000 | [diff] [blame^] | 21 | |
reed@google.com | e6f7d68 | 2012-04-23 12:51:32 +0000 | [diff] [blame] | 22 | /** |
| 23 | * If Get() has previously been called with this CreateProc, then this |
| 24 | * returns its cached data, otherwise it returns NULL. The CreateProc is |
| 25 | * never invoked in Find, it is only used as a key for searching the |
| 26 | * cache. |
| 27 | */ |
| 28 | static void* Find(CreateProc); |
reed@google.com | ae1b6b6 | 2012-04-23 15:49:45 +0000 | [diff] [blame^] | 29 | |
| 30 | /** |
| 31 | * Return the cached data that was returned by the CreateProc. This proc |
| 32 | * is only called the first time Get is called, and there after it is |
| 33 | * cached (per-thread), using the CreateProc as a key to look it up. |
| 34 | * |
| 35 | * When this thread, or Delete is called, the cached data is removed, and |
| 36 | * if a DeleteProc was specified, it is passed the pointer to the cached |
| 37 | * data. |
| 38 | */ |
| 39 | static void* Get(CreateProc, DeleteProc); |
| 40 | |
| 41 | /** |
| 42 | * Remove (optionally calling the DeleteProc if it was specificed in Get) |
| 43 | * the cached data associated with this CreateProc. If no associated cached |
| 44 | * data is found, do nothing. |
| 45 | */ |
| 46 | static void Delete(CreateProc); |
reed@google.com | e6f7d68 | 2012-04-23 12:51:32 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | #endif |