aboutsummaryrefslogtreecommitdiff
path: root/src/core/taskq.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-10 15:02:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-10 15:02:38 -0700
commit795aebbee77bb74d8792df96dfe1aa79ec9548fc (patch)
tree58c16424c16b9e71cebdceaee4507ab6608f80da /src/core/taskq.c
parentde90f97167d2df6739db47b2c6aad85f06250270 (diff)
downloadnng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.tar.gz
nng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.tar.bz2
nng-795aebbee77bb74d8792df96dfe1aa79ec9548fc.zip
Give up on uncrustify; switch to clang-format.
Diffstat (limited to 'src/core/taskq.c')
-rw-r--r--src/core/taskq.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/src/core/taskq.c b/src/core/taskq.c
index f4a0beee..e45819b5 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -9,20 +9,20 @@
#include "core/nng_impl.h"
-typedef struct nni_taskq_thr nni_taskq_thr;
+typedef struct nni_taskq_thr nni_taskq_thr;
struct nni_taskq_thr {
- nni_taskq * tqt_tq;
- nni_thr tqt_thread;
- nni_taskq_ent * tqt_running;
- int tqt_wait;
+ nni_taskq * tqt_tq;
+ nni_thr tqt_thread;
+ nni_taskq_ent *tqt_running;
+ int tqt_wait;
};
struct nni_taskq {
- nni_list tq_ents;
- nni_mtx tq_mtx;
- nni_cv tq_cv;
- nni_taskq_thr * tq_threads;
- int tq_nthreads;
- int tq_close;
+ nni_list tq_ents;
+ nni_mtx tq_mtx;
+ nni_cv tq_cv;
+ nni_taskq_thr *tq_threads;
+ int tq_nthreads;
+ int tq_close;
};
static nni_taskq *nni_taskq_systq = NULL;
@@ -31,14 +31,14 @@ static void
nni_taskq_thread(void *self)
{
nni_taskq_thr *thr = self;
- nni_taskq *tq = thr->tqt_tq;
+ nni_taskq * tq = thr->tqt_tq;
nni_taskq_ent *ent;
nni_mtx_lock(&tq->tq_mtx);
for (;;) {
if ((ent = nni_list_first(&tq->tq_ents)) != NULL) {
nni_list_remove(&tq->tq_ents, ent);
- ent->tqe_tq = NULL;
+ ent->tqe_tq = NULL;
thr->tqt_running = ent;
nni_mtx_unlock(&tq->tq_mtx);
ent->tqe_cb(ent->tqe_arg);
@@ -60,13 +60,12 @@ nni_taskq_thread(void *self)
nni_mtx_unlock(&tq->tq_mtx);
}
-
int
nni_taskq_init(nni_taskq **tqp, int nthr)
{
- int rv;
+ int rv;
nni_taskq *tq;
- int i;
+ int i;
if ((tq = NNI_ALLOC_STRUCT(tq)) == NULL) {
return (NNG_ENOMEM);
@@ -83,7 +82,7 @@ nni_taskq_init(nni_taskq **tqp, int nthr)
tq->tq_close = 0;
NNI_LIST_INIT(&tq->tq_ents, nni_taskq_ent, tqe_node);
- tq->tq_threads = nni_alloc(sizeof (nni_taskq_thr) * nthr);
+ tq->tq_threads = nni_alloc(sizeof(nni_taskq_thr) * nthr);
if (tq->tq_threads == NULL) {
nni_cv_fini(&tq->tq_cv);
nni_mtx_fini(&tq->tq_mtx);
@@ -92,10 +91,10 @@ nni_taskq_init(nni_taskq **tqp, int nthr)
}
tq->tq_nthreads = nthr;
for (i = 0; i < nthr; i++) {
- tq->tq_threads[i].tqt_tq = tq;
+ tq->tq_threads[i].tqt_tq = tq;
tq->tq_threads[i].tqt_running = NULL;
rv = nni_thr_init(&tq->tq_threads[i].tqt_thread,
- nni_taskq_thread, &tq->tq_threads[i]);
+ nni_taskq_thread, &tq->tq_threads[i]);
if (rv != 0) {
goto fail;
}
@@ -113,7 +112,6 @@ fail:
return (rv);
}
-
void
nni_taskq_fini(nni_taskq *tq)
{
@@ -126,13 +124,12 @@ nni_taskq_fini(nni_taskq *tq)
for (i = 0; i < tq->tq_nthreads; i++) {
nni_thr_fini(&tq->tq_threads[i].tqt_thread);
}
- nni_free(tq->tq_threads, tq->tq_nthreads * sizeof (nni_taskq_thr));
+ nni_free(tq->tq_threads, tq->tq_nthreads * sizeof(nni_taskq_thr));
nni_cv_fini(&tq->tq_cv);
nni_mtx_fini(&tq->tq_mtx);
NNI_FREE_STRUCT(tq);
}
-
int
nni_taskq_dispatch(nni_taskq *tq, nni_taskq_ent *ent)
{
@@ -155,7 +152,6 @@ nni_taskq_dispatch(nni_taskq *tq, nni_taskq_ent *ent)
return (0);
}
-
int
nni_taskq_cancel(nni_taskq *tq, nni_taskq_ent *ent)
{
@@ -191,17 +187,15 @@ nni_taskq_cancel(nni_taskq *tq, nni_taskq_ent *ent)
return (0);
}
-
void
nni_taskq_ent_init(nni_taskq_ent *ent, nni_cb cb, void *arg)
{
NNI_LIST_NODE_INIT(&ent->tqe_node);
- ent->tqe_cb = cb;
+ ent->tqe_cb = cb;
ent->tqe_arg = arg;
- ent->tqe_tq = NULL;
+ ent->tqe_tq = NULL;
}
-
int
nni_taskq_sys_init(void)
{
@@ -212,7 +206,6 @@ nni_taskq_sys_init(void)
return (rv);
}
-
void
nni_taskq_sys_fini(void)
{