From 626061fd28e3f78b662bbef0f60d13b15c9acebd Mon Sep 17 00:00:00 2001 From: Manjesh Nilange Date: Mon, 10 Mar 2014 17:49:16 -0700 Subject: [PATCH 1/2] atscppapi: Locking fix in xform and utility macro for logging --- lib/atscppapi/src/TransformationPlugin.cc | 27 ++++++++++++-------- lib/atscppapi/src/include/atscppapi/Logger.h | 11 ++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/atscppapi/src/TransformationPlugin.cc b/lib/atscppapi/src/TransformationPlugin.cc index f859bb396ea..a3a8691ce07 100644 --- a/lib/atscppapi/src/TransformationPlugin.cc +++ b/lib/atscppapi/src/TransformationPlugin.cc @@ -131,7 +131,8 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Now call the client to tell them about data */ if (in_data.length() > 0) { - state->transformation_plugin_.consume(in_data); + ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); + state->transformation_plugin_.consume(in_data); } } @@ -154,11 +155,12 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont) { - TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont) { + TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -167,11 +169,12 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont) { - TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont) { + TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -233,6 +236,7 @@ TransformationPlugin::~TransformationPlugin() { } size_t TransformationPlugin::produce(const std::string &data) { + ScopedSharedMutexLock scopedLock(state_->transformation_plugin_.getMutex()); LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p producing output with length=%ld", this, state_->txn_, data.length()); int64_t write_length = static_cast(data.length()); if (!write_length) { @@ -282,6 +286,7 @@ size_t TransformationPlugin::produce(const std::string &data) { } size_t TransformationPlugin::setOutputComplete() { + ScopedSharedMutexLock scopedLock(state_->transformation_plugin_.getMutex()); int connection_closed = TSVConnClosedGet(state_->vconn_); LOG_DEBUG("OutputComplete TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d, total bytes written=%" PRId64, this, state_->txn_, state_->vconn_, connection_closed,state_->bytes_written_); diff --git a/lib/atscppapi/src/include/atscppapi/Logger.h b/lib/atscppapi/src/include/atscppapi/Logger.h index f5227d0327e..3227b63e518 100644 --- a/lib/atscppapi/src/include/atscppapi/Logger.h +++ b/lib/atscppapi/src/include/atscppapi/Logger.h @@ -125,6 +125,17 @@ extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1,2); TSError("[%s] [%s:%d, %s()] " fmt, tag, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ } while (false) +/** + * A helper macro for Logger objects that allows you to easily add a error level message + * which will include file, line, and function name with the message. This macro will also + * use invoke TS_DEBUG + */ +#define LOG_ERROR2(log, log_tag, fmt, ...) \ + do { \ + (log).logError("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ + TS_DEBUG((log_tag), fmt, ## __VA_ARGS__); \ + } while (false) + namespace atscppapi { struct LoggerState; From b645e2ae2efe2f858d437aa9891f86398a422841 Mon Sep 17 00:00:00 2001 From: Manjesh Nilange Date: Wed, 12 Mar 2014 10:42:09 -0700 Subject: [PATCH 2/2] Revert "atscppapi: Locking fix in xform and utility macro for logging" This reverts commit 626061fd28e3f78b662bbef0f60d13b15c9acebd. --- lib/atscppapi/src/TransformationPlugin.cc | 27 ++++++++------------ lib/atscppapi/src/include/atscppapi/Logger.h | 11 -------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/lib/atscppapi/src/TransformationPlugin.cc b/lib/atscppapi/src/TransformationPlugin.cc index a3a8691ce07..f859bb396ea 100644 --- a/lib/atscppapi/src/TransformationPlugin.cc +++ b/lib/atscppapi/src/TransformationPlugin.cc @@ -131,8 +131,7 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Now call the client to tell them about data */ if (in_data.length() > 0) { - ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); - state->transformation_plugin_.consume(in_data); + state->transformation_plugin_.consume(in_data); } } @@ -155,12 +154,11 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont) { - TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont) { + TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -169,12 +167,11 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - ScopedSharedMutexLock scopedLock(state->transformation_plugin_.getMutex()); - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont) { - TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont) { + TSContCall(vio_cont, static_cast(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -236,7 +233,6 @@ TransformationPlugin::~TransformationPlugin() { } size_t TransformationPlugin::produce(const std::string &data) { - ScopedSharedMutexLock scopedLock(state_->transformation_plugin_.getMutex()); LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p producing output with length=%ld", this, state_->txn_, data.length()); int64_t write_length = static_cast(data.length()); if (!write_length) { @@ -286,7 +282,6 @@ size_t TransformationPlugin::produce(const std::string &data) { } size_t TransformationPlugin::setOutputComplete() { - ScopedSharedMutexLock scopedLock(state_->transformation_plugin_.getMutex()); int connection_closed = TSVConnClosedGet(state_->vconn_); LOG_DEBUG("OutputComplete TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d, total bytes written=%" PRId64, this, state_->txn_, state_->vconn_, connection_closed,state_->bytes_written_); diff --git a/lib/atscppapi/src/include/atscppapi/Logger.h b/lib/atscppapi/src/include/atscppapi/Logger.h index 3227b63e518..f5227d0327e 100644 --- a/lib/atscppapi/src/include/atscppapi/Logger.h +++ b/lib/atscppapi/src/include/atscppapi/Logger.h @@ -125,17 +125,6 @@ extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1,2); TSError("[%s] [%s:%d, %s()] " fmt, tag, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ } while (false) -/** - * A helper macro for Logger objects that allows you to easily add a error level message - * which will include file, line, and function name with the message. This macro will also - * use invoke TS_DEBUG - */ -#define LOG_ERROR2(log, log_tag, fmt, ...) \ - do { \ - (log).logError("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ - TS_DEBUG((log_tag), fmt, ## __VA_ARGS__); \ - } while (false) - namespace atscppapi { struct LoggerState;