Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate the use and implementation of nni_timer #1730

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ nng_sources(
tcp.h
thread.c
thread.h
timer.c
timer.h
url.c
url.h
)
Expand Down
40 changes: 28 additions & 12 deletions src/core/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void
nni_aio_fini(nni_aio *aio)
{
nni_aio_cancel_fn fn;
void *arg;
void *arg;
nni_aio_expire_q *eq = aio->a_expire_q;

// This is like aio_close, but we don't want to dispatch
Expand Down Expand Up @@ -247,7 +247,21 @@ nni_aio_close(nni_aio *aio)
void
nni_aio_set_timeout(nni_aio *aio, nni_duration when)
{
aio->a_timeout = when;
aio->a_timeout = when;
aio->a_use_expire = false;
}

void
nni_aio_set_expire(nni_aio *aio, nni_time expire)
{
aio->a_expire = expire;
aio->a_use_expire = true;
}

nng_duration
nni_aio_get_timeout(nni_aio *aio)
{
return (aio->a_timeout);
}

void
Expand Down Expand Up @@ -369,7 +383,7 @@ nni_aio_schedule(nni_aio *aio, nni_aio_cancel_fn cancel, void *data)
{
nni_aio_expire_q *eq = aio->a_expire_q;

if (!aio->a_sleep) {
if ((!aio->a_sleep) && (!aio->a_use_expire)) {
// Convert the relative timeout to an absolute timeout.
switch (aio->a_timeout) {
case NNG_DURATION_ZERO:
Expand Down Expand Up @@ -411,7 +425,7 @@ void
nni_aio_abort(nni_aio *aio, int rv)
{
nni_aio_cancel_fn fn;
void *arg;
void *arg;
nni_aio_expire_q *eq = aio->a_expire_q;

nni_mtx_lock(&eq->eq_mtx);
Expand Down Expand Up @@ -447,8 +461,9 @@ nni_aio_finish_impl(
aio->a_msg = msg;
}

aio->a_expire = NNI_TIME_NEVER;
aio->a_sleep = false;
aio->a_expire = NNI_TIME_NEVER;
aio->a_sleep = false;
aio->a_use_expire = false;
nni_mtx_unlock(&eq->eq_mtx);

if (sync) {
Expand Down Expand Up @@ -518,24 +533,25 @@ nni_aio_completions_init(nni_aio_completions *clp)
}

void
nni_aio_completions_add(nni_aio_completions *clp, nni_aio *aio, int result, size_t count)
nni_aio_completions_add(
nni_aio_completions *clp, nni_aio *aio, int result, size_t count)
{
NNI_ASSERT(!nni_aio_list_active(aio));
aio->a_reap_node.rn_next = *clp;
aio->a_result = result;
aio->a_count = count;
*clp = aio;
aio->a_result = result;
aio->a_count = count;
*clp = aio;
}

void
nni_aio_completions_run(nni_aio_completions *clp)
{
nni_aio *aio;
nni_aio *cl = *clp;
*clp = NULL;
*clp = NULL;

while ((aio = cl) != NULL) {
cl = (void *)aio->a_reap_node.rn_next;
cl = (void *) aio->a_reap_node.rn_next;
aio->a_reap_node.rn_next = NULL;
nni_aio_finish_sync(aio, aio->a_result, aio->a_count);
}
Expand Down
35 changes: 19 additions & 16 deletions src/core/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ extern size_t nni_aio_iov_count(nni_aio *);

extern int nni_aio_set_iov(nni_aio *, unsigned, const nni_iov *);

extern void nni_aio_set_timeout(nni_aio *, nng_duration);
extern void nni_aio_get_iov(nni_aio *, unsigned *, nni_iov **);
extern void nni_aio_normalize_timeout(nni_aio *, nng_duration);
extern void nni_aio_bump_count(nni_aio *, size_t);
extern void nni_aio_set_timeout(nni_aio *, nng_duration);
extern void nni_aio_set_expire(nni_aio *, nni_time);
extern nng_duration nni_aio_get_timeout(nni_aio *);
extern void nni_aio_get_iov(nni_aio *, unsigned *, nni_iov **);
extern void nni_aio_normalize_timeout(nni_aio *, nng_duration);
extern void nni_aio_bump_count(nni_aio *, size_t);

// nni_aio_schedule indicates that the AIO has begun, and is scheduled for
// asynchronous completion. This also starts the expiration timer. Note that
Expand Down Expand Up @@ -187,8 +189,8 @@ extern void nni_aio_completions_run(nni_aio_completions *);
// nni_aio_completions_add adds an aio (with the result code and length as
// appropriate) to the completion list. This should be done while the
// appropriate lock is held. The aio must not be scheduled.
extern void nni_aio_completions_add(nni_aio_completions *, nni_aio *,
int, size_t);
extern void nni_aio_completions_add(
nni_aio_completions *, nni_aio *, int, size_t);

extern int nni_aio_sys_init(void);
extern void nni_aio_sys_fini(void);
Expand All @@ -202,14 +204,15 @@ typedef struct nni_aio_expire_q nni_aio_expire_q;
// any of these members -- the definition is provided here to facilitate
// inlining, but that should be the only use.
struct nng_aio {
size_t a_count; // Bytes transferred (I/O only)
nni_time a_expire; // Absolute timeout
nni_duration a_timeout; // Relative timeout
int a_result; // Result code (nng_errno)
bool a_stop; // Shutting down (no new operations)
bool a_sleep; // Sleeping with no action
bool a_expire_ok; // Expire from sleep is ok
bool a_expiring; // Expiration in progress
size_t a_count; // Bytes transferred (I/O only)
nni_time a_expire; // Absolute timeout
nni_duration a_timeout; // Relative timeout
int a_result; // Result code (nng_errno)
bool a_stop; // Shutting down (no new operations)
bool a_sleep; // Sleeping with no action
bool a_expire_ok; // Expire from sleep is ok
bool a_expiring; // Expiration in progress
bool a_use_expire; // Use expire instead of timeout
nni_task a_task;

// Read/write operations.
Expand All @@ -227,8 +230,8 @@ struct nng_aio {

// Provider-use fields.
nni_aio_cancel_fn a_cancel_fn;
void *a_cancel_arg;
void *a_prov_data;
void *a_cancel_arg;
void *a_prov_data;
nni_list_node a_prov_node; // Linkage on provider list.
nni_aio_expire_q *a_expire_q;
nni_list_node a_expire_node; // Expiration node
Expand Down
4 changes: 1 addition & 3 deletions src/core/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2023 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/core/nng_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Garrett D'Amore <[email protected]>
// Copyright 2023 Staysail Systems, Inc. <[email protected]>
// Copyright 2017 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -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
Expand Down
177 changes: 0 additions & 177 deletions src/core/timer.c

This file was deleted.

Loading
Loading