aboutsummaryrefslogtreecommitdiff
path: root/src/core/thread.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-01 14:34:29 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-01 14:34:29 -0800
commit3fd43c488b47874db22a87a1d87eed94bbd85725 (patch)
treeed9fe38b370c9a6162ac05596b91adfac9cb5579 /src/core/thread.c
parentc7b541af4a1a2c410dc63a638a17adb31d7342a3 (diff)
downloadnng-3fd43c488b47874db22a87a1d87eed94bbd85725.tar.gz
nng-3fd43c488b47874db22a87a1d87eed94bbd85725.tar.bz2
nng-3fd43c488b47874db22a87a1d87eed94bbd85725.zip
Pipe simplifications for thread management.
This may also address a race in closing down pipes. Now pipes are always registered with the socket. They also always have both a sender and receiver thread. If the protocol doesn't need one or the other, the stock thread just exits early.
Diffstat (limited to 'src/core/thread.c')
-rw-r--r--src/core/thread.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/core/thread.c b/src/core/thread.c
index 4f714341..d1f46e3f 100644
--- a/src/core/thread.c
+++ b/src/core/thread.c
@@ -15,48 +15,56 @@ nni_mtx_init(nni_mtx *mtx)
return (nni_plat_mtx_init(&mtx->mtx));
}
+
void
nni_mtx_fini(nni_mtx *mtx)
{
nni_plat_mtx_fini(&mtx->mtx);
}
+
void
nni_mtx_lock(nni_mtx *mtx)
{
nni_plat_mtx_lock(&mtx->mtx);
}
+
void
nni_mtx_unlock(nni_mtx *mtx)
{
nni_plat_mtx_unlock(&mtx->mtx);
}
+
int
nni_mtx_trylock(nni_mtx *mtx)
{
return (nni_plat_mtx_trylock(&mtx->mtx));
}
+
int
nni_cv_init(nni_cv *cv, nni_mtx *mtx)
{
return (nni_plat_cv_init(&cv->cv, &mtx->mtx));
}
+
void
nni_cv_fini(nni_cv *cv)
{
nni_plat_cv_fini(&cv->cv);
}
+
void
nni_cv_wait(nni_cv *cv)
{
nni_plat_cv_wait(&cv->cv);
}
+
int
nni_cv_until(nni_cv *cv, nni_time until)
{
@@ -73,12 +81,14 @@ nni_cv_until(nni_cv *cv, nni_time until)
return (nni_plat_cv_until(&cv->cv, until));
}
+
void
nni_cv_wake(nni_cv *cv)
{
return (nni_plat_cv_wake(&cv->cv));
}
+
static void
nni_thr_wrap(void *arg)
{
@@ -90,7 +100,7 @@ nni_thr_wrap(void *arg)
nni_plat_cv_wait(&thr->cv);
}
nni_plat_mtx_unlock(&thr->mtx);
- if (!stop) {
+ if ((!stop) && (thr->fn != NULL)) {
thr->fn(thr->arg);
}
nni_plat_mtx_lock(&thr->mtx);
@@ -99,6 +109,7 @@ nni_thr_wrap(void *arg)
nni_plat_mtx_unlock(&thr->mtx);
}
+
int
nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg)
{
@@ -125,6 +136,7 @@ nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg)
return (0);
}
+
void
nni_thr_run(nni_thr *thr)
{
@@ -134,6 +146,7 @@ nni_thr_run(nni_thr *thr)
nni_plat_mtx_unlock(&thr->mtx);
}
+
void
nni_thr_fini(nni_thr *thr)
{
@@ -147,4 +160,4 @@ nni_thr_fini(nni_thr *thr)
nni_plat_thr_fini(&thr->thr);
nni_plat_cv_fini(&thr->cv);
nni_plat_mtx_fini(&thr->mtx);
-} \ No newline at end of file
+}