summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2023-12-17 10:00:52 -0800
committerGarrett D'Amore <garrett@damore.org>2023-12-17 10:00:52 -0800
commitca6323109ba0c76e13ed629350348dfc6d144932 (patch)
tree5d6da790bdee3332d66b29b2f3ffbf0c3638aed1 /src/core
parentdc499882e82827f39a77669fb7dc5cd7a70aaf40 (diff)
downloadnng-ca6323109ba0c76e13ed629350348dfc6d144932.tar.gz
nng-ca6323109ba0c76e13ed629350348dfc6d144932.tar.bz2
nng-ca6323109ba0c76e13ed629350348dfc6d144932.zip
fixes #1729 remove nni_timer
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/init.c4
-rw-r--r--src/core/nng_impl.h3
-rw-r--r--src/core/timer.c177
-rw-r--r--src/core/timer.h34
5 files changed, 2 insertions, 218 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index eb511a83..f003d756 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -68,8 +68,6 @@ nng_sources(
tcp.h
thread.c
thread.h
- timer.c
- timer.h
url.c
url.h
)
diff --git a/src/core/init.c b/src/core/init.c
index f8ecb385..f2195bcb 100644
--- a/src/core/init.c
+++ b/src/core/init.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -34,7 +34,6 @@ nni_init_helper(void)
if (((rv = nni_taskq_sys_init()) != 0) ||
((rv = nni_reap_sys_init()) != 0) ||
- ((rv = nni_timer_sys_init()) != 0) ||
((rv = nni_aio_sys_init()) != 0) ||
((rv = nni_tls_sys_init()) != 0)) {
nni_fini();
@@ -65,7 +64,6 @@ nni_fini(void)
nni_tls_sys_fini();
nni_reap_drain();
nni_aio_sys_fini();
- nni_timer_sys_fini();
nni_taskq_sys_fini();
nni_reap_sys_fini(); // must be before timer and aio (expire)
nni_id_map_sys_fini();
diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h
index 15db8d16..0eceaf0b 100644
--- a/src/core/nng_impl.h
+++ b/src/core/nng_impl.h
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Garrett D'Amore <garrett@damore.org>
+// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -45,7 +45,6 @@
#include "core/strs.h"
#include "core/taskq.h"
#include "core/thread.h"
-#include "core/timer.h"
#include "core/url.h"
// transport needs to come after url
diff --git a/src/core/timer.c b/src/core/timer.c
deleted file mode 100644
index 36024817..00000000
--- a/src/core/timer.c
+++ /dev/null
@@ -1,177 +0,0 @@
-//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-//
-// 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.
-//
-
-#include "core/nng_impl.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-static void nni_timer_loop(void *);
-
-// XXX: replace this timer list with a minHeap based priority queue.
-struct nni_timer {
- nni_mtx t_mx;
- nni_cv t_wait_cv;
- nni_cv t_sched_cv;
- nni_list t_entries;
- nni_thr t_thr;
- int t_run;
- int t_waiting;
- nni_timer_node *t_active; // Must never ever be dereferenced!
-};
-
-typedef struct nni_timer nni_timer;
-
-static nni_timer nni_global_timer;
-
-int
-nni_timer_sys_init(void)
-{
- int rv;
- nni_timer *timer = &nni_global_timer;
-
- memset(timer, 0, sizeof(*timer));
- NNI_LIST_INIT(&timer->t_entries, nni_timer_node, t_node);
-
- nni_mtx_init(&timer->t_mx);
- nni_cv_init(&timer->t_sched_cv, &timer->t_mx);
- nni_cv_init(&timer->t_wait_cv, &timer->t_mx);
-
- if ((rv = nni_thr_init(&timer->t_thr, nni_timer_loop, timer)) != 0) {
- nni_timer_sys_fini();
- return (rv);
- }
- timer->t_run = 1;
- nni_thr_run(&timer->t_thr);
- return (0);
-}
-
-void
-nni_timer_sys_fini(void)
-{
- nni_timer *timer = &nni_global_timer;
-
- if (timer->t_run) {
- nni_mtx_lock(&timer->t_mx);
- timer->t_run = 0;
- nni_cv_wake(&timer->t_sched_cv);
- nni_mtx_unlock(&timer->t_mx);
- }
-
- nni_thr_fini(&timer->t_thr);
- nni_cv_fini(&timer->t_wait_cv);
- nni_cv_fini(&timer->t_sched_cv);
- nni_mtx_fini(&timer->t_mx);
-}
-
-void
-nni_timer_init(nni_timer_node *node, nni_cb cb, void *arg)
-{
- node->t_cb = cb;
- node->t_arg = arg;
-}
-
-void
-nni_timer_fini(nni_timer_node *node)
-{
- NNI_ARG_UNUSED(node);
-}
-
-void
-nni_timer_cancel(nni_timer_node *node)
-{
- nni_timer *timer = &nni_global_timer;
-
- nni_mtx_lock(&timer->t_mx);
- while (timer->t_active == node) {
- timer->t_waiting = 1;
- nni_cv_wait(&timer->t_wait_cv);
- }
- if (nni_list_active(&timer->t_entries, node)) {
- nni_list_remove(&timer->t_entries, node);
- }
- nni_mtx_unlock(&timer->t_mx);
-}
-
-void
-nni_timer_schedule(nni_timer_node *node, nni_time when)
-{
- nni_timer *timer = &nni_global_timer;
-
- nni_mtx_lock(&timer->t_mx);
- node->t_expire = when;
-
- if (nni_list_active(&timer->t_entries, node)) {
- nni_list_remove(&timer->t_entries, node);
- }
-
- if (when != NNI_TIME_NEVER) {
- nni_timer_node *srch = nni_list_first(&timer->t_entries);
- while ((srch != NULL) && (srch->t_expire < node->t_expire)) {
- srch = nni_list_next(&timer->t_entries, srch);
- }
- if (srch != NULL) {
- nni_list_insert_before(&timer->t_entries, node, srch);
- } else {
- nni_list_append(&timer->t_entries, node);
- }
- if (nni_list_first(&timer->t_entries) == node) {
- nni_cv_wake1(&timer->t_sched_cv);
- }
- }
- nni_mtx_unlock(&timer->t_mx);
-}
-
-static void
-nni_timer_loop(void *arg)
-{
- nni_timer * timer = arg;
- nni_time now;
- nni_timer_node *node;
-
- nni_thr_set_name(NULL, "nng:timer");
-
- for (;;) {
- nni_mtx_lock(&timer->t_mx);
- timer->t_active = NULL;
- if (timer->t_waiting) {
- timer->t_waiting = 0;
- nni_cv_wake(&timer->t_wait_cv);
- }
- if (!timer->t_run) {
- nni_mtx_unlock(&timer->t_mx);
- break;
- }
-
- now = nni_clock();
- if ((node = nni_list_first(&timer->t_entries)) == NULL) {
- nni_cv_wait(&timer->t_sched_cv);
- nni_mtx_unlock(&timer->t_mx);
- continue;
- }
- if (now < node->t_expire) {
- // End of run, we have to wait for next.
- nni_cv_until(&timer->t_sched_cv, node->t_expire);
- nni_mtx_unlock(&timer->t_mx);
- continue;
- }
-
- nni_list_remove(&timer->t_entries, node);
-
- // Save the active node. Note that the timer callback can
- // free this memory or do something else with it, so it is
- // important that we never dereference this pointer, but
- // just compare the value of the pointer itself.
- timer->t_active = node;
- nni_mtx_unlock(&timer->t_mx);
-
- node->t_cb(node->t_arg);
- }
-}
diff --git a/src/core/timer.h b/src/core/timer.h
deleted file mode 100644
index a8108d5f..00000000
--- a/src/core/timer.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Copyright 2017 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.
-//
-
-#ifndef CORE_TIMER_H
-#define CORE_TIMER_H
-
-#include "core/defs.h"
-#include "core/list.h"
-
-// For the sake of simplicity, we just maintain a single global timer thread.
-
-struct nni_timer_node {
- nni_time t_expire;
- nni_cb t_cb;
- void * t_arg;
- nni_list_node t_node;
-};
-
-typedef struct nni_timer_node nni_timer_node;
-
-extern void nni_timer_init(nni_timer_node *, nni_cb, void *);
-extern void nni_timer_fini(nni_timer_node *);
-extern void nni_timer_schedule(nni_timer_node *, nni_time);
-extern void nni_timer_cancel(nni_timer_node *);
-extern int nni_timer_sys_init(void);
-extern void nni_timer_sys_fini(void);
-
-#endif // CORE_TIMER_H