threadstorage.h File Reference

Definitions to aid in the use of thread local storage. More...

#include "asterisk/utils.h"
#include "asterisk/inline_api.h"

Include dependency graph for threadstorage.h:

This graph shows which files directly or indirectly include this file:

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,)
#define AST_THREADSTORAGE_RAW(name)   AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, NULL,)

Functions

void * ast_threadstorage_get (struct ast_threadstorage *ts, size_t init_size)
 Retrieve thread storage.
void * ast_threadstorage_get_ptr (struct ast_threadstorage *ts)
 Retrieve a raw pointer from threadstorage.
int ast_threadstorage_set_ptr (struct ast_threadstorage *ts, void *ptr)
 Set a raw pointer from threadstorage.


Detailed Description

Definitions to aid in the use of thread local storage.

Author:
Russell Bryant <russell@digium.com>

Definition in file threadstorage.h.


Define Documentation

#define AST_PTHREAD_ONCE_INIT   PTHREAD_ONCE_INIT

Definition at line 111 of file threadstorage.h.

#define AST_THREADSTORAGE ( name   )     AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr, static)

Define a thread storage variable.

Parameters:
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:

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.

Parameters:
a The name of the thread storage object
b 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.
c 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 106 of file threadstorage.h.

#define AST_THREADSTORAGE_CUSTOM_SCOPE ( name,
c_init,
c_cleanup,
scope   ) 

Definition at line 115 of file threadstorage.h.

#define AST_THREADSTORAGE_EXTERNAL ( name   )     extern struct ast_threadstorage name

Definition at line 85 of file threadstorage.h.

#define AST_THREADSTORAGE_PUBLIC ( name   )     AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr,)

Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 83 of file threadstorage.h.

#define AST_THREADSTORAGE_RAW ( name   )     AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, NULL,)

Definition at line 87 of file threadstorage.h.


Function Documentation

void * ast_threadstorage_get ( struct ast_threadstorage ts,
size_t  init_size 
) [inline]

Retrieve thread storage.

Parameters:
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.
Returns:
This function will return the thread local storage associated with the thread storage management variable passed as the first argument. The result will be NULL in the case of a memory allocation error.
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 194 of file threadstorage.h.

References ast_calloc, ast_free, buf, ast_threadstorage::custom_init, ast_threadstorage::key, ast_threadstorage::key_init, NULL, and ast_threadstorage::once.

Referenced by __frame_free(), acf_curl_helper(), ast_callid_threadassoc_add(), ast_callid_threadassoc_change(), ast_callid_threadassoc_remove(), ast_frame_header_new(), ast_frdup(), ast_inet_ntoa(), ast_read_threadstorage_callid(), ast_sched_del(), ast_sip_thread_is_servant(), ast_state2str(), ast_term_color(), ast_thread_inhibit_escalations(), ast_verb_console_get(), ast_verb_console_register(), ast_verb_console_set(), ast_verb_console_unregister(), chan_pjsip_get_uniqueid(), console_print(), control2str(), device2str(), dialplan_handle_msg_cb(), dummy_start(), get_auth(), get_transport_list(), iax_frame_free(), iax_frame_new(), json_free_list(), process_text_line(), remove_auth(), sip_thread_start(), store_auth(), substate2str(), thread_inhibits_escalations(), and transmit_response_using_temp().

00198 {

void * ast_threadstorage_get_ptr ( struct ast_threadstorage ts  )  [inline]

Retrieve a raw pointer from threadstorage.

Parameters:
ts Threadstorage object to operate on.
Returns:
A pointer associated with the current thread, NULL if no pointer is associated yet.
Note:
This should only be used on threadstorage declared by AST_THREADSTORAGE_RAW unless you really know what you are doing.

Definition at line 238 of file threadstorage.h.

References ast_threadstorage::key, ast_threadstorage::key_init, and ast_threadstorage::once.

Referenced by ast_log_safe().

00253 {

int ast_threadstorage_set_ptr ( struct ast_threadstorage ts,
void *  ptr 
) [inline]

Set a raw pointer from threadstorage.

Parameters:
ts Threadstorage object to operate on.
Return values:
0 Success
non-zero Failure
Note:
This should only be used on threadstorage declared by AST_THREADSTORAGE_RAW unless you really know what you are doing.

Definition at line 257 of file threadstorage.h.

Referenced by ast_log_safe().


Generated on Thu Apr 16 06:34:31 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6