Definitions to aid in the use of thread local storage. More...
#include "asterisk/utils.h"
#include "asterisk/inline_api.h"
Go to the source code of this file.
Data Structures | |
struct | ast_threadstorage |
data for a thread locally stored variable More... | |
Defines | |
#define | AST_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT |
#define | AST_THREADSTORAGE(name) AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr, static) |
Define a thread storage variable. | |
#define | AST_THREADSTORAGE_CUSTOM(a, b, c) AST_THREADSTORAGE_CUSTOM_SCOPE(a,b,c,static) |
Define a thread storage variable, with custom initialization and cleanup. | |
#define | AST_THREADSTORAGE_CUSTOM_SCOPE(name, c_init, c_cleanup, scope) |
#define | AST_THREADSTORAGE_EXTERNAL(name) extern struct ast_threadstorage name |
#define | AST_THREADSTORAGE_PUBLIC(name) AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr,) |
Functions | |
void * | ast_threadstorage_get (struct ast_threadstorage *ts, size_t init_size) |
Retrieve thread storage. |
Definitions to aid in the use of thread local storage.
Definition in file threadstorage.h.
#define AST_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT |
Definition at line 109 of file threadstorage.h.
Define a thread storage variable.
name | The name of the thread storage object |
This macro would be used to declare an instance of thread storage in a file.
Example usage:
AST_THREADSTORAGE(my_buf);
Definition at line 81 of file threadstorage.h.
#define AST_THREADSTORAGE_CUSTOM | ( | a, | |
b, | |||
c | |||
) | AST_THREADSTORAGE_CUSTOM_SCOPE(a,b,c,static) |
Define a thread storage variable, with custom initialization and cleanup.
name | The name of the thread storage object |
init | This is a custom function that will be called after each thread specific object is allocated, with the allocated block of memory passed as the argument. |
cleanup | This is a custom function that will be called instead of ast_free when the thread goes away. Note that if this is used, it *MUST* call free on the allocated memory. |
Example usage:
AST_THREADSTORAGE_CUSTOM(my_buf, my_init, my_cleanup);
Definition at line 104 of file threadstorage.h.
#define AST_THREADSTORAGE_CUSTOM_SCOPE | ( | name, | |
c_init, | |||
c_cleanup, | |||
scope | |||
) |
Definition at line 113 of file threadstorage.h.
#define AST_THREADSTORAGE_EXTERNAL | ( | name | ) | extern struct ast_threadstorage name |
Definition at line 85 of file threadstorage.h.
Definition at line 83 of file threadstorage.h.
void * ast_threadstorage_get | ( | struct ast_threadstorage * | ts, |
size_t | init_size | ||
) | [inline] |
Retrieve thread storage.
ts | This is a pointer to the thread storage structure declared by using the AST_THREADSTORAGE macro. If declared with AST_THREADSTORAGE(my_buf), then this argument would be (&my_buf). |
init_size | This is the amount of space to be allocated the first time this thread requests its data. Thus, this should be the size that the code accessing this thread storage is assuming the size to be. |
Example usage:
AST_THREADSTORAGE(my_buf); #define MY_BUF_SIZE 128 ... void my_func(const char *fmt, ...) { void *buf; if (!(buf = ast_threadstorage_get(&my_buf, MY_BUF_SIZE))) return; ... }
Definition at line 191 of file threadstorage.h.
References ast_calloc, buf, ast_threadstorage::custom_init, free, ast_threadstorage::key, ast_threadstorage::key_init, and ast_threadstorage::once.
Referenced by __frame_free(), acf_curl_exec(), ast_frame_header_new(), ast_frdup(), ast_inet_ntoa(), ast_state2str(), control2str(), device2str(), dummy_start(), iax_frame_free(), iax_frame_new(), process_sdp(), process_text_line(), and transmit_response_using_temp().
{