Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Implement dcn_stop_threads #34

Merged
merged 1 commit into from
Jul 27, 2018
Merged

Implement dcn_stop_threads #34

merged 1 commit into from
Jul 27, 2018

Conversation

ralphtheninja
Copy link
Member

@ralphtheninja ralphtheninja commented Jul 27, 2018

Also see comments in code below.

Output:

screenshot from 2018-07-27 15-47-51

Note that the last output is written to stdout after we are back on the js side.

NAPI_STATUS_THROWS(napi_create_threadsafe_function(
env,
callback,
0,
async_resource_name,
0,
3,
100,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set something for queue size. If we set to 0 it means we get an unlimited queue and this will crash.

0,
3,
100,
1,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed this from 3 to 1, since we haven't actually started the threads yet, so can't assume there are three threads running.

dcn_context_t* dcn_context = (dcn_context_t*)arg;
dc_context_t* dc_context = dcn_context->dc_context;

napi_acquire_threadsafe_function(dcn_context->napi_event_handler);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will bump internal thread count.

dc_perform_imap_jobs(dc_context);
dc_perform_imap_fetch(dc_context);
dc_perform_imap_idle(dc_context);
}

napi_release_threadsafe_function(dcn_context->napi_event_handler, napi_tsfn_release);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reduce thread count.

dc_perform_smtp_jobs(dc_context);
dc_perform_smtp_idle(dc_context);
}

napi_release_threadsafe_function(dcn_context->napi_event_handler, napi_tsfn_release);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for this function.

@@ -266,6 +297,7 @@ NAPI_METHOD(dcn_context_new) {
dcn_context->napi_event_handler = NULL;
dcn_context->imap_thread = 0;
dcn_context->smtp_thread = 0;
dcn_context->loop_thread = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should be 0, since we don't have any threads running atm. It doesn't really matter though.

dcn_context->dc_context);
uv_thread_create(&dcn_context->smtp_thread, smtp_thread_func,
dcn_context->dc_context);
dcn_context->loop_thread = 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we set it to 1.

@ralphtheninja ralphtheninja requested a review from r10s July 27, 2018 13:55
@ralphtheninja
Copy link
Member Author

We can probably tweak this more later, but at least we can now stop gracefully, which is needed in order to implement tests properly.

@ralphtheninja
Copy link
Member Author

ralphtheninja commented Jul 27, 2018

Also see nodejs/help#1387 and nodejs/node@45816c5 for reference

@ralphtheninja ralphtheninja merged commit 7743f07 into master Jul 27, 2018
@ralphtheninja ralphtheninja deleted the stop-threads branch July 27, 2018 15:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant