blob: 7368d7285476097540ad52b0bcfdf584691ec971 [file] [log] [blame]
reed@google.come6f7d682012-04-23 12:51:32 +00001//
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.comae1b6b62012-04-23 15:49:45 +000014/**
15 * Maintains a per-thread cache, using a CreateProc as the key into that cache.
16 */
reed@google.come6f7d682012-04-23 12:51:32 +000017class SkTLS {
18public:
19 typedef void* (*CreateProc)();
20 typedef void (*DeleteProc)(void*);
reed@google.comae1b6b62012-04-23 15:49:45 +000021
reed@google.come6f7d682012-04-23 12:51:32 +000022 /**
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.comae1b6b62012-04-23 15:49:45 +000029
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.come6f7d682012-04-23 12:51:32 +000047};
48
49#endif