src: handle last event before exiting status threads

- Avoid 2 consecutive calls to uv_async_send when exiting the cardreader.cpp
  check status thread.
- Fix mutex unlock location in cardreader.cpp check status thread.

PR-URL: https://github.com/santigimeno/node-pcsclite/pull/46
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Florian Ramillien
2015-09-24 16:33:59 +02:00
committed by Santiago Gimeno
parent 0a3eaafb2b
commit 3800c39291
2 changed files with 29 additions and 26 deletions

View File

@@ -124,11 +124,6 @@ void PCSCLite::HandleReaderStatusChange(uv_async_t *handle, int status) {
AsyncBaton* async_baton = static_cast<AsyncBaton*>(handle->data);
AsyncResult* ar = async_baton->async_result;
if (ar->do_exit) {
uv_close(reinterpret_cast<uv_handle_t*>(&async_baton->async), CloseCallback); // necessary otherwise UV will block
return;
}
if ((ar->result == SCARD_S_SUCCESS) || (ar->result == (LONG)SCARD_E_NO_READERS_AVAILABLE)) {
const unsigned argc = 2;
Local<Value> argv[argc] = {
@@ -145,6 +140,12 @@ void PCSCLite::HandleReaderStatusChange(uv_async_t *handle, int status) {
Nan::Callback(Nan::New(async_baton->callback)).Call(argc, argv);
}
// Do exit, after throwing last events
if (ar->do_exit) {
uv_close(reinterpret_cast<uv_handle_t*>(&async_baton->async), CloseCallback); // necessary otherwise UV will block
return;
}
/* reset AsyncResult */
delete [] ar->readers_name;
ar->readers_name = NULL;