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 | |
| 14 | class SkTLS { |
| 15 | public: |
| 16 | typedef void* (*CreateProc)(); |
| 17 | typedef void (*DeleteProc)(void*); |
| 18 | |
| 19 | /** |
| 20 | * Create proc is called once per thread, and its return value is cached |
| 21 | * and returned by this call, treating the proc as a key. When this thread |
| 22 | * exists, if DeleteProc is not NULL, it is called and passed the value |
| 23 | * that was returned by CreateProc. |
| 24 | */ |
| 25 | static void* Get(CreateProc, DeleteProc); |
| 26 | |
| 27 | /** |
| 28 | * If Get() has previously been called with this CreateProc, then this |
| 29 | * returns its cached data, otherwise it returns NULL. The CreateProc is |
| 30 | * never invoked in Find, it is only used as a key for searching the |
| 31 | * cache. |
| 32 | */ |
| 33 | static void* Find(CreateProc); |
| 34 | }; |
| 35 | |
| 36 | #endif |