summaryrefslogtreecommitdiff
path: root/main/taskprocessor.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2016-01-07 16:15:35 -0600
committerRichard Mudgett <rmudgett@digium.com>2016-01-08 22:11:01 -0600
commit3e857bb3476dbf5ae88e808591c5934a8876f9d6 (patch)
treed86f029f850295a00b2ab17d5bf0874f18e36886 /main/taskprocessor.c
parent71bb7b9c401d4e1fc9bdfea65948de3c82bb08d2 (diff)
taskprocessor.c: New API for human friendly taskprocessor names.
* Add new API call to get a sequence number for use in human friendly taskprocessor names. * Add new API call to create a taskprocessor name in a given buffer and append a sequence number. Change-Id: Iac458f05b45232315ed64aa31b1df05b875537a9
Diffstat (limited to 'main/taskprocessor.c')
-rw-r--r--main/taskprocessor.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 0b67c0f7a..9a4424ea3 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -879,3 +879,37 @@ int ast_taskprocessor_is_task(struct ast_taskprocessor *tps)
ao2_unlock(tps);
return is_task;
}
+
+unsigned int ast_taskprocessor_seq_num(void)
+{
+ static int seq_num;
+
+ return (unsigned int) ast_atomic_fetchadd_int(&seq_num, +1);
+}
+
+void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format, ...)
+{
+ va_list ap;
+ int user_size;
+#define SEQ_STR_SIZE (1 + 8 + 1) /* Dash plus 8 hex digits plus null terminator */
+
+ ast_assert(buf != NULL);
+ ast_assert(SEQ_STR_SIZE <= size);
+
+ va_start(ap, format);
+ user_size = vsnprintf(buf, size - (SEQ_STR_SIZE - 1), format, ap);
+ va_end(ap);
+ if (user_size < 0) {
+ /*
+ * Wow! We got an output error to a memory buffer.
+ * Assume no user part of name written.
+ */
+ user_size = 0;
+ } else if (size < user_size + SEQ_STR_SIZE) {
+ /* Truncate user part of name to make sequence number fit. */
+ user_size = size - SEQ_STR_SIZE;
+ }
+
+ /* Append sequence number to end of user name. */
+ snprintf(buf + user_size, SEQ_STR_SIZE, "-%08x", ast_taskprocessor_seq_num());
+}