📄 threadstorage.h
字号:
)#else /* defined(DEBUG_THREADLOCALS) */AST_INLINE_API(struct ast_dynamic_str *__ast_dynamic_str_thread_get(struct ast_threadstorage *ts, size_t init_len, const char *file, const char *function, unsigned int line),{ struct ast_dynamic_str *buf; if (!(buf = __ast_threadstorage_get(ts, sizeof(*buf) + init_len, file, function, line))) return NULL; if (!buf->len) buf->len = init_len; return buf;})#define ast_dynamic_str_thread_get(ts, init_len) __ast_dynamic_str_thread_get(ts, init_len, __FILE__, __PRETTY_FUNCTION__, __LINE__)#endif /* defined(DEBUG_THREADLOCALS) */ /*! * \brief Error codes from ast_dynamic_str_thread_build_va() */enum { /*! An error has occured and the contents of the dynamic string * are undefined */ AST_DYNSTR_BUILD_FAILED = -1, /*! The buffer size for the dynamic string had to be increased, and * ast_dynamic_str_thread_build_va() needs to be called again after * a va_end() and va_start(). */ AST_DYNSTR_BUILD_RETRY = -2};/*! * \brief Set a thread locally stored dynamic string from a va_list * * \arg buf This is the address of a pointer to an ast_dynamic_str which should * have been retrieved using ast_dynamic_str_thread_get. It will need to * be updated in the case that the buffer has to be reallocated to * accomodate a longer string than what it currently has space for. * \arg max_len This is the maximum length to allow the string buffer to grow * to. If this is set to 0, then there is no maximum length. * \arg ts This is a pointer to the thread storage structure declared by using * the AST_THREADSTORAGE macro. If declared with * AST_THREADSTORAGE(my_buf, my_buf_init), then this argument would be * (&my_buf). * \arg fmt This is the format string (printf style) * \arg ap This is the va_list * * \return The return value of this function is the same as that of the printf * family of functions. * * Example usage: * \code * AST_THREADSTORAGE(my_str, my_str_init); * #define MY_STR_INIT_SIZE 128 * ... * void my_func(const char *fmt, ...) * { * struct ast_dynamic_str *buf; * va_list ap; * * if (!(buf = ast_dynamic_str_thread_get(&my_str, MY_STR_INIT_SIZE))) * return; * ... * va_start(fmt, ap); * ast_dynamic_str_thread_set_va(&buf, 0, &my_str, fmt, ap); * va_end(ap); * * printf("This is the string we just built: %s\n", buf->str); * ... * } * \endcode */#define ast_dynamic_str_thread_set_va(buf, max_len, ts, fmt, ap) \ ({ \ int __res; \ while ((__res = ast_dynamic_str_thread_build_va(buf, max_len, \ ts, 0, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) { \ va_end(ap); \ va_start(ap, fmt); \ } \ (__res); \ })/*! * \brief Append to a thread local dynamic string using a va_list * * The arguments, return values, and usage of this are the same as those for * ast_dynamic_str_thread_set_va(). However, instead of setting a new value * for the string, this will append to the current value. */#define ast_dynamic_str_thread_append_va(buf, max_len, ts, fmt, ap) \ ({ \ int __res; \ while ((__res = ast_dynamic_str_thread_build_va(buf, max_len, \ ts, 1, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) { \ va_end(ap); \ va_start(ap, fmt); \ } \ (__res); \ })/*! * \brief Core functionality of ast_dynamic_str_thread_(set|append)_va * * The arguments to this function are the same as those described for * ast_dynamic_str_thread_set_va except for an addition argument, append. * If append is non-zero, this will append to the current string instead of * writing over it. */int ast_dynamic_str_thread_build_va(struct ast_dynamic_str **buf, size_t max_len, struct ast_threadstorage *ts, int append, const char *fmt, va_list ap);/*! * \brief Set a thread locally stored dynamic string using variable arguments * * \arg buf This is the address of a pointer to an ast_dynamic_str which should * have been retrieved using ast_dynamic_str_thread_get. It will need to * be updated in the case that the buffer has to be reallocated to * accomodate a longer string than what it currently has space for. * \arg max_len This is the maximum length to allow the string buffer to grow * to. If this is set to 0, then there is no maximum length. * \arg ts This is a pointer to the thread storage structure declared by using * the AST_THREADSTORAGE macro. If declared with * AST_THREADSTORAGE(my_buf, my_buf_init), then this argument would be * (&my_buf). * \arg fmt This is the format string (printf style) * * \return The return value of this function is the same as that of the printf * family of functions. * * Example usage: * \code * AST_THREADSTORAGE(my_str, my_str_init); * #define MY_STR_INIT_SIZE 128 * ... * void my_func(int arg1, int arg2) * { * struct ast_dynamic_str *buf; * va_list ap; * * if (!(buf = ast_dynamic_str_thread_get(&my_str, MY_STR_INIT_SIZE))) * return; * ... * ast_dynamic_str_thread_set(&buf, 0, &my_str, "arg1: %d arg2: %d\n", * arg1, arg2); * * printf("This is the string we just built: %s\n", buf->str); * ... * } * \endcode */AST_INLINE_API(int __attribute__ ((format (printf, 4, 5))) ast_dynamic_str_thread_set( struct ast_dynamic_str **buf, size_t max_len, struct ast_threadstorage *ts, const char *fmt, ...),{ int res; va_list ap; va_start(ap, fmt); res = ast_dynamic_str_thread_set_va(buf, max_len, ts, fmt, ap); va_end(ap); return res;})/*! * \brief Append to a thread local dynamic string * * The arguments, return values, and usage of this function are the same as * ast_dynamic_str_thread_set(). However, instead of setting a new value for * the string, this function appends to the current value. */AST_INLINE_API(int __attribute__ ((format (printf, 4, 5))) ast_dynamic_str_thread_append( struct ast_dynamic_str **buf, size_t max_len, struct ast_threadstorage *ts, const char *fmt, ...),{ int res; va_list ap; va_start(ap, fmt); res = ast_dynamic_str_thread_append_va(buf, max_len, ts, fmt, ap); va_end(ap); return res;})/*! * \brief Set a dynamic string * * \arg buf This is the address of a pointer to an ast_dynamic_str. It will * need to be updated in the case that the buffer has to be reallocated to * accomodate a longer string than what it currently has space for. * \arg max_len This is the maximum length to allow the string buffer to grow * to. If this is set to 0, then there is no maximum length. * * \return The return value of this function is the same as that of the printf * family of functions. */AST_INLINE_API(int __attribute__ ((format (printf, 3, 4))) ast_dynamic_str_set( struct ast_dynamic_str **buf, size_t max_len, const char *fmt, ...),{ int res; va_list ap; va_start(ap, fmt); res = ast_dynamic_str_thread_set_va(buf, max_len, NULL, fmt, ap); va_end(ap); return res;})/*! * \brief Append to a dynatic string * * The arguments, return values, and usage of this function are the same as * ast_dynamic_str_set(). However, this function appends to the string instead * of setting a new value. */AST_INLINE_API(int __attribute__ ((format (printf, 3, 4))) ast_dynamic_str_append( struct ast_dynamic_str **buf, size_t max_len, const char *fmt, ...),{ int res; va_list ap; va_start(ap, fmt); res = ast_dynamic_str_thread_append_va(buf, max_len, NULL, fmt, ap); va_end(ap); return res;})#endif /* ASTERISK_THREADSTORAGE_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -