diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 |
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 |
| commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
| tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /tests/lib/test_heavy_wq.c | |
| parent | 888ac268a0077fc9ebd1218cec6ae472af0bfc40 (diff) | |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/lib/test_heavy_wq.c')
| -rw-r--r-- | tests/lib/test_heavy_wq.c | 197 |
1 files changed, 92 insertions, 105 deletions
diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c index 18b80d0810..0f474dc5d2 100644 --- a/tests/lib/test_heavy_wq.c +++ b/tests/lib/test_heavy_wq.c @@ -44,97 +44,88 @@ DEFINE_MTYPE_STATIC(TEST_HEAVYWQ, WQ_NODE_STR, "heavy_wq_node->str") extern struct thread_master *master; static struct work_queue *heavy_wq; -struct heavy_wq_node -{ - char *str; - int i; +struct heavy_wq_node { + char *str; + int i; }; -enum -{ - ITERS_FIRST = 0, - ITERS_ERR = 100, - ITERS_LATER = 400, - ITERS_PRINT = 10, - ITERS_MAX = 1000, +enum { ITERS_FIRST = 0, + ITERS_ERR = 100, + ITERS_LATER = 400, + ITERS_PRINT = 10, + ITERS_MAX = 1000, }; -static void -heavy_wq_add (struct vty *vty, const char *str, int i) +static void heavy_wq_add(struct vty *vty, const char *str, int i) { - struct heavy_wq_node *hn; - - if ((hn = XCALLOC (MTYPE_WQ_NODE, sizeof(struct heavy_wq_node))) == NULL) - { - zlog_err ("%s: unable to allocate hn", __func__); - return; - } - - hn->i = i; - if (!(hn->str = XSTRDUP (MTYPE_WQ_NODE_STR, str))) - { - zlog_err ("%s: unable to xstrdup", __func__); - XFREE (MTYPE_WQ_NODE, hn); - return; - } - - work_queue_add (heavy_wq, hn); - - return; + struct heavy_wq_node *hn; + + if ((hn = XCALLOC(MTYPE_WQ_NODE, sizeof(struct heavy_wq_node))) + == NULL) { + zlog_err("%s: unable to allocate hn", __func__); + return; + } + + hn->i = i; + if (!(hn->str = XSTRDUP(MTYPE_WQ_NODE_STR, str))) { + zlog_err("%s: unable to xstrdup", __func__); + XFREE(MTYPE_WQ_NODE, hn); + return; + } + + work_queue_add(heavy_wq, hn); + + return; } -static void -slow_func_err (struct work_queue *wq, struct work_queue_item *item) +static void slow_func_err(struct work_queue *wq, struct work_queue_item *item) { - printf ("%s: running error function\n", __func__); + printf("%s: running error function\n", __func__); } -static void -slow_func_del (struct work_queue *wq, void *data) +static void slow_func_del(struct work_queue *wq, void *data) { - struct heavy_wq_node *hn = data; - assert (hn && hn->str); - printf ("%s: %s\n", __func__, hn->str); - XFREE (MTYPE_WQ_NODE_STR, hn->str); - hn->str = NULL; - XFREE(MTYPE_WQ_NODE, hn); + struct heavy_wq_node *hn = data; + assert(hn && hn->str); + printf("%s: %s\n", __func__, hn->str); + XFREE(MTYPE_WQ_NODE_STR, hn->str); + hn->str = NULL; + XFREE(MTYPE_WQ_NODE, hn); } -static wq_item_status -slow_func (struct work_queue *wq, void *data) +static wq_item_status slow_func(struct work_queue *wq, void *data) { - struct heavy_wq_node *hn = data; - double x = 1; - int j; - - assert (hn && hn->str); - - for (j = 0; j < 300; j++) - x += sin(x)*j; - - if ((hn->i % ITERS_LATER) == 0) - return WQ_RETRY_LATER; - - if ((hn->i % ITERS_ERR) == 0) - return WQ_RETRY_NOW; - - if ((hn->i % ITERS_PRINT) == 0) - printf ("%s did %d, x = %g\n", hn->str, hn->i, x); - - return WQ_SUCCESS; + struct heavy_wq_node *hn = data; + double x = 1; + int j; + + assert(hn && hn->str); + + for (j = 0; j < 300; j++) + x += sin(x) * j; + + if ((hn->i % ITERS_LATER) == 0) + return WQ_RETRY_LATER; + + if ((hn->i % ITERS_ERR) == 0) + return WQ_RETRY_NOW; + + if ((hn->i % ITERS_PRINT) == 0) + printf("%s did %d, x = %g\n", hn->str, hn->i, x); + + return WQ_SUCCESS; } -static void -clear_something (struct vty *vty, const char *str) +static void clear_something(struct vty *vty, const char *str) { - int i; - - /* this could be like iterating through 150k of route_table - * or worse, iterating through a list of peers, to bgp_stop them with - * each having 150k route tables to process... - */ - for (i = ITERS_FIRST; i < ITERS_MAX; i++) - heavy_wq_add (vty, str, i); + int i; + + /* this could be like iterating through 150k of route_table + * or worse, iterating through a list of peers, to bgp_stop them with + * each having 150k route tables to process... + */ + for (i = ITERS_FIRST; i < ITERS_MAX; i++) + heavy_wq_add(vty, str, i); } DEFUN (clear_foo, @@ -143,41 +134,37 @@ DEFUN (clear_foo, "clear command\n" "arbitrary string\n") { - char *str; - if (!argc) - { - vty_out (vty, "%% string argument required\n"); - return CMD_WARNING; - } - - str = argv_concat (argv, argc, 0); - - clear_something (vty, str); - XFREE (MTYPE_TMP, str); - return CMD_SUCCESS; + char *str; + if (!argc) { + vty_out(vty, "%% string argument required\n"); + return CMD_WARNING; + } + + str = argv_concat(argv, argc, 0); + + clear_something(vty, str); + XFREE(MTYPE_TMP, str); + return CMD_SUCCESS; } -static int -heavy_wq_init () +static int heavy_wq_init() { - if (! (heavy_wq = work_queue_new (master, "heavy_work_queue"))) - { - zlog_err ("%s: could not get new work queue!", __func__); - return -1; - } - - heavy_wq->spec.workfunc = &slow_func; - heavy_wq->spec.errorfunc = &slow_func_err; - heavy_wq->spec.del_item_data = &slow_func_del; - heavy_wq->spec.max_retries = 3; - heavy_wq->spec.hold = 1000; - - return 0; + if (!(heavy_wq = work_queue_new(master, "heavy_work_queue"))) { + zlog_err("%s: could not get new work queue!", __func__); + return -1; + } + + heavy_wq->spec.workfunc = &slow_func; + heavy_wq->spec.errorfunc = &slow_func_err; + heavy_wq->spec.del_item_data = &slow_func_del; + heavy_wq->spec.max_retries = 3; + heavy_wq->spec.hold = 1000; + + return 0; } -void -test_init() +void test_init() { - install_element (VIEW_NODE, &clear_foo_cmd); - heavy_wq_init(); + install_element(VIEW_NODE, &clear_foo_cmd); + heavy_wq_init(); } |
