aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-01 19:48:10 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-01 19:48:10 -0800
commit783470724ed22b315f2ecc4e3b1ac9d199d44ea2 (patch)
treed4883f305b1f2c6f57710cd8900f4b0932ae14c0 /src/platform
parentbbed172a2b38f9227ca9e1c02a933df068e5eaf7 (diff)
downloadnng-783470724ed22b315f2ecc4e3b1ac9d199d44ea2.tar.gz
nng-783470724ed22b315f2ecc4e3b1ac9d199d44ea2.tar.bz2
nng-783470724ed22b315f2ecc4e3b1ac9d199d44ea2.zip
Final purge of old threading & synch stuff.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/posix/posix_synch.c154
-rw-r--r--src/platform/posix/posix_thread.c44
2 files changed, 0 insertions, 198 deletions
diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c
deleted file mode 100644
index d9fed53f..00000000
--- a/src/platform/posix/posix_synch.c
+++ /dev/null
@@ -1,154 +0,0 @@
-//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
-//
-// This software is supplied under the terms of the MIT License, a
-// copy of which should be located in the distribution where this
-// file was obtained (LICENSE.txt). A copy of the license may also be
-// found online at https://opensource.org/licenses/MIT.
-//
-
-// POSIX synchronization (mutexes and condition variables). This uses
-// pthreads.
-
-#include "core/nng_impl.h"
-
-#ifdef PLATFORM_POSIX_SYNCH
-
-#include <pthread.h>
-#include <time.h>
-#include <string.h>
-
-extern pthread_condattr_t nni_cvattr;
-extern pthread_mutexattr_t nni_mxattr;
-
-int
-nni_mutex_init(nni_mutex *mp)
-{
- if (pthread_mutex_init(&mp->mx, &nni_mxattr) != 0) {
- return (NNG_ENOMEM);
- }
- return (0);
-}
-
-
-void
-nni_mutex_fini(nni_mutex *mp)
-{
- int rv;
-
- if ((rv = pthread_mutex_destroy(&mp->mx)) != 0) {
- nni_panic("pthread_mutex_destroy failed: %s", strerror(rv));
- }
-}
-
-
-void
-nni_mutex_enter(nni_mutex *m)
-{
- int rv;
-
- if ((rv = pthread_mutex_lock(&m->mx)) != 0) {
- nni_panic("pthread_mutex_lock failed: %s", strerror(rv));
- }
-}
-
-
-void
-nni_mutex_exit(nni_mutex *m)
-{
- if (pthread_mutex_unlock(&m->mx) != 0) {
- nni_panic("pthread_mutex_unlock failed");
- }
-}
-
-
-int
-nni_mutex_tryenter(nni_mutex *m)
-{
- if (pthread_mutex_trylock(&m->mx) != 0) {
- return (NNG_EBUSY);
- }
- return (0);
-}
-
-
-int
-nni_cond_init(nni_cond *c, nni_mutex *m)
-{
- if (pthread_cond_init(&c->cv, &nni_cvattr) != 0) {
- // In theory could be EAGAIN, but handle like ENOMEM
- return (NNG_ENOMEM);
- }
- c->mx = &m->mx;
- return (0);
-}
-
-
-void
-nni_cond_fini(nni_cond *c)
-{
- if (pthread_cond_destroy(&c->cv) != 0) {
- nni_panic("pthread_cond_destroy failed");
- }
-}
-
-
-void
-nni_cond_signal(nni_cond *c)
-{
- if (pthread_cond_signal(&c->cv) != 0) {
- nni_panic("pthread_cond_signal failed");
- }
-}
-
-
-void
-nni_cond_broadcast(nni_cond *c)
-{
- if (pthread_cond_broadcast(&c->cv) != 0) {
- nni_panic("pthread_cond_broadcast failed");
- }
-}
-
-
-void
-nni_cond_wait(nni_cond *c)
-{
- if (pthread_cond_wait(&c->cv, c->mx) != 0) {
- nni_panic("pthread_cond_wait failed");
- }
-}
-
-
-int
-nni_cond_waituntil(nni_cond *c, nni_time usec)
-{
- struct timespec ts;
- int rv;
- nni_duration delta = usec - nni_clock();
-
-
- if (usec != NNI_TIME_NEVER) {
- ts.tv_sec = usec / 1000000;
- ts.tv_nsec = (usec % 1000000) * 1000;
-
- rv = pthread_cond_timedwait(&c->cv, c->mx, &ts);
- } else {
- rv = pthread_cond_wait(&c->cv, c->mx);
- }
-
- if (rv == ETIMEDOUT) {
- if (nni_clock() < usec) {
- // This only happens if the implementation
- // is buggy.
- nni_panic("Premature wakupe!");
- }
- return (NNG_ETIMEDOUT);
- } else if (rv != 0) {
- nni_panic("pthread_cond_timedwait returned %d", rv);
- }
- return (0);
-}
-
-
-#endif
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index d1944879..0a999326 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -45,50 +45,6 @@ nni_plat_nextid(void)
return (id);
}
-
-static void *
-nni_thrfunc(void *arg)
-{
- nni_thread *thr = arg;
-
- thr->func(thr->arg);
- return (NULL);
-}
-
-
-int
-nni_thread_create(nni_thread **tp, void (*fn)(void *), void *arg)
-{
- nni_thread *thr;
- int rv;
-
- if ((thr = nni_alloc(sizeof (*thr))) == NULL) {
- return (NNG_ENOMEM);
- }
- thr->func = fn;
- thr->arg = arg;
-
- if ((rv = pthread_create(&thr->tid, NULL, nni_thrfunc, thr)) != 0) {
- nni_free(thr, sizeof (*thr));
- return (NNG_ENOMEM);
- }
- *tp = thr;
- return (0);
-}
-
-
-void
-nni_thread_reap(nni_thread *thr)
-{
- int rv;
-
- if ((rv = pthread_join(thr->tid, NULL)) != 0) {
- nni_panic("pthread_thread: %s", strerror(rv));
- }
- nni_free(thr, sizeof (*thr));
-}
-
-
int
nni_plat_mtx_init(nni_plat_mtx *mtx)
{