From c6bbc4708c1b2a8fa41e593e2aca5863a144daca Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 6 Dec 2016 11:00:39 -0800 Subject: Replace usages of std::list with std::queue in Node extension --- src/node/ext/call_credentials.cc | 12 ++++++------ src/node/ext/call_credentials.h | 4 ++-- src/node/ext/node_grpc.cc | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/node') diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 81fc552fd1..41f6c29f7d 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -35,7 +35,7 @@ #include #include -#include +#include #include "grpc/grpc.h" #include "grpc/grpc_security.h" @@ -170,7 +170,7 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) { grpc_metadata_credentials_plugin plugin; plugin_state *state = new plugin_state; state->callback = new Nan::Callback(info[0].As()); - state->pending_callbacks = new std::list(); + state->pending_callbacks = new std::queue(); uv_mutex_init(&state->plugin_mutex); uv_async_init(uv_default_loop(), &state->plugin_async, @@ -232,13 +232,13 @@ NAN_METHOD(PluginCallback) { NAUV_WORK_CB(SendPluginCallback) { Nan::HandleScope scope; plugin_state *state = reinterpret_cast(async->data); - std::list callbacks; + std::queue callbacks; uv_mutex_lock(&state->plugin_mutex); - callbacks.splice(callbacks.begin(), *state->pending_callbacks); + state->pending_callbacks->swap(callbacks); uv_mutex_unlock(&state->plugin_mutex); while (!callbacks.empty()) { plugin_callback_data *data = callbacks.front(); - callbacks.pop_front(); + callbacks.pop(); Local callback_data = Nan::New(); Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(), Nan::New(reinterpret_cast(data->cb))); @@ -267,7 +267,7 @@ void plugin_get_metadata(void *state, grpc_auth_metadata_context context, data->user_data = user_data; uv_mutex_lock(&p_state->plugin_mutex); - p_state->pending_callbacks->push_back(data); + p_state->pending_callbacks->push(data); uv_mutex_unlock(&p_state->plugin_mutex); uv_async_send(&p_state->plugin_async); diff --git a/src/node/ext/call_credentials.h b/src/node/ext/call_credentials.h index 04c852bea1..21a4b8923e 100644 --- a/src/node/ext/call_credentials.h +++ b/src/node/ext/call_credentials.h @@ -34,7 +34,7 @@ #ifndef GRPC_NODE_CALL_CREDENTIALS_H_ #define GRPC_NODE_CALL_CREDENTIALS_H_ -#include +#include #include #include @@ -84,7 +84,7 @@ typedef struct plugin_callback_data { typedef struct plugin_state { Nan::Callback *callback; - std::list *pending_callbacks; + std::queue *pending_callbacks; uv_mutex_t plugin_mutex; // async.data == this uv_async_t plugin_async; diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 848c601587..620b086915 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -31,7 +31,7 @@ * */ -#include +#include #include #include @@ -66,7 +66,7 @@ typedef struct log_args { typedef struct logger_state { Nan::Callback *callback; - std::list *pending_args; + std::queue *pending_args; uv_mutex_t mutex; uv_async_t async; // Indicates that a logger has been set @@ -334,14 +334,14 @@ NAN_METHOD(SetDefaultRootsPem) { NAUV_WORK_CB(LogMessagesCallback) { Nan::HandleScope scope; - std::list args; + std::queue args; uv_mutex_lock(&grpc_logger_state.mutex); - args.splice(args.begin(), *grpc_logger_state.pending_args); + grpc_logger_state.pending_args->swap(args); uv_mutex_unlock(&grpc_logger_state.mutex); /* Call the callback with each log message */ while (!args.empty()) { log_args *arg = args.front(); - args.pop_front(); + args.pop(); Local file = Nan::New(arg->core_args.file).ToLocalChecked(); Local line = Nan::New(arg->core_args.line); Local severity = Nan::New( @@ -368,7 +368,7 @@ void node_log_func(gpr_log_func_args *args) { args_copy->timestamp = gpr_now(GPR_CLOCK_REALTIME); uv_mutex_lock(&grpc_logger_state.mutex); - grpc_logger_state.pending_args->push_back(args_copy); + grpc_logger_state.pending_args->push(args_copy); uv_mutex_unlock(&grpc_logger_state.mutex); uv_async_send(&grpc_logger_state.async); @@ -376,7 +376,7 @@ void node_log_func(gpr_log_func_args *args) { void init_logger() { memset(&grpc_logger_state, 0, sizeof(logger_state)); - grpc_logger_state.pending_args = new std::list(); + grpc_logger_state.pending_args = new std::queue(); uv_mutex_init(&grpc_logger_state.mutex); uv_async_init(uv_default_loop(), &grpc_logger_state.async, -- cgit v1.2.3