Replace usages of std::list with std::queue in Node extension

pull/8981/head
murgatroid99 8 years ago
parent 93904c0dc8
commit c6bbc4708c
  1. 12
      src/node/ext/call_credentials.cc
  2. 4
      src/node/ext/call_credentials.h
  3. 14
      src/node/ext/node_grpc.cc

@ -35,7 +35,7 @@
#include <nan.h>
#include <uv.h>
#include <list>
#include <queue>
#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<Function>());
state->pending_callbacks = new std::list<plugin_callback_data*>();
state->pending_callbacks = new std::queue<plugin_callback_data*>();
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<plugin_state*>(async->data);
std::list<plugin_callback_data*> callbacks;
std::queue<plugin_callback_data*> 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<Object> callback_data = Nan::New<Object>();
Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(),
Nan::New<v8::External>(reinterpret_cast<void*>(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);

@ -34,7 +34,7 @@
#ifndef GRPC_NODE_CALL_CREDENTIALS_H_
#define GRPC_NODE_CALL_CREDENTIALS_H_
#include <list>
#include <queue>
#include <node.h>
#include <nan.h>
@ -84,7 +84,7 @@ typedef struct plugin_callback_data {
typedef struct plugin_state {
Nan::Callback *callback;
std::list<plugin_callback_data*> *pending_callbacks;
std::queue<plugin_callback_data*> *pending_callbacks;
uv_mutex_t plugin_mutex;
// async.data == this
uv_async_t plugin_async;

@ -31,7 +31,7 @@
*
*/
#include <list>
#include <queue>
#include <node.h>
#include <nan.h>
@ -66,7 +66,7 @@ typedef struct log_args {
typedef struct logger_state {
Nan::Callback *callback;
std::list<log_args *> *pending_args;
std::queue<log_args *> *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<log_args *> args;
std::queue<log_args *> 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<Value> file = Nan::New(arg->core_args.file).ToLocalChecked();
Local<Value> line = Nan::New<Uint32, uint32_t>(arg->core_args.line);
Local<Value> 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<log_args *>();
grpc_logger_state.pending_args = new std::queue<log_args *>();
uv_mutex_init(&grpc_logger_state.mutex);
uv_async_init(uv_default_loop(),
&grpc_logger_state.async,

Loading…
Cancel
Save