47 #ifndef ASTERISK_THREADSTORAGE_H 48 #define ASTERISK_THREADSTORAGE_H 63 #if defined(DEBUG_THREADLOCALS) 64 void __ast_threadstorage_object_add(
void *
key,
size_t len,
const char *
file,
const char *
function,
unsigned int line);
65 void __ast_threadstorage_object_remove(
void *
key);
66 void __ast_threadstorage_object_replace(
void *key_old,
void *key_new,
size_t len);
67 #define THREADSTORAGE_RAW_CLEANUP(v) {} 69 #define THREADSTORAGE_RAW_CLEANUP NULL 84 #define AST_THREADSTORAGE(name) \ 85 AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr, static) 86 #define AST_THREADSTORAGE_PUBLIC(name) \ 87 AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr,) 88 #define AST_THREADSTORAGE_EXTERNAL(name) \ 89 extern struct ast_threadstorage name 90 #define AST_THREADSTORAGE_RAW(name) \ 91 AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, THREADSTORAGE_RAW_CLEANUP,) 109 #define AST_THREADSTORAGE_CUSTOM(a,b,c) AST_THREADSTORAGE_CUSTOM_SCOPE(a,b,c,static) 111 #if defined(PTHREAD_ONCE_INIT_NEEDS_BRACES) 112 # define AST_PTHREAD_ONCE_INIT { PTHREAD_ONCE_INIT } 114 # define AST_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT 117 #if !defined(DEBUG_THREADLOCALS) 118 #define AST_THREADSTORAGE_CUSTOM_SCOPE(name, c_init, c_cleanup, scope) \ 119 static void __init_##name(void); \ 120 scope struct ast_threadstorage name = { \ 121 .once = AST_PTHREAD_ONCE_INIT, \ 122 .key_init = __init_##name, \ 123 .custom_init = c_init, \ 125 static void __init_##name(void) \ 127 pthread_key_create(&(name).key, c_cleanup); \ 130 #define AST_THREADSTORAGE_CUSTOM_SCOPE(name, c_init, c_cleanup, scope) \ 131 static void __init_##name(void); \ 132 scope struct ast_threadstorage name = { \ 133 .once = AST_PTHREAD_ONCE_INIT, \ 134 .key_init = __init_##name, \ 135 .custom_init = c_init, \ 137 static void __cleanup_##name(void *data) \ 139 __ast_threadstorage_object_remove(data); \ 142 static void __init_##name(void) \ 144 pthread_key_create(&(name).key, __cleanup_##name); \ 177 #if !defined(DEBUG_THREADLOCALS) 184 if (!(buf = pthread_getspecific(ts->
key))) {
192 pthread_setspecific(ts->
key, buf);
200 void *__ast_threadstorage_get(
struct ast_threadstorage *ts,
size_t init_size,
const char *
file,
const char *
function,
unsigned int line),
205 if (!(buf = pthread_getspecific(ts->
key))) {
213 pthread_setspecific(ts->
key, buf);
214 __ast_threadstorage_object_add(buf, init_size,
file,
function, line);
221 #define
ast_threadstorage_get(ts, init_size) __ast_threadstorage_get(ts, init_size, __FILE__, __PRETTY_FUNCTION__, __LINE__)
239 return pthread_getspecific(ts->
key);
258 return pthread_setspecific(ts->
key, ptr);
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
data for a thread locally stored variable
int(* custom_init)(void *)
int ast_threadstorage_set_ptr(struct ast_threadstorage *ts, void *ptr)
Set a raw pointer from threadstorage.
Inlinable API function macro.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_calloc(num, len)
A wrapper for calloc()
void * ast_threadstorage_get_ptr(struct ast_threadstorage *ts)
Retrieve a raw pointer from threadstorage.
#define AST_INLINE_API(hdr, body)