Repository: trafficserver Updated Branches: refs/heads/master 2b35ff4b2 -> 47a53bec1
Locking fix in atscppapi transformation code Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/8176151b Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/8176151b Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/8176151b Branch: refs/heads/master Commit: 8176151bf70bbcd480b3f6c0f37f774222fafd16 Parents: 6ad6e5a Author: Brian Geffon <[email protected]> Authored: Tue Mar 11 11:04:45 2014 -0700 Committer: Brian Geffon <[email protected]> Committed: Tue Mar 11 11:04:45 2014 -0700 ---------------------------------------------------------------------- lib/atscppapi/src/TransformationPlugin.cc | 27 ++++++++++++++--------- lib/atscppapi/src/include/atscppapi/Logger.h | 11 +++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8176151b/lib/atscppapi/src/TransformationPlugin.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/TransformationPlugin.cc b/lib/atscppapi/src/TransformationPlugin.cc index f859bb3..a3a8691 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<TSEvent>(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<TSEvent>(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<TSEvent>(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<TSEvent>(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<int64_t>(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_); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8176151b/lib/atscppapi/src/include/atscppapi/Logger.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Logger.h b/lib/atscppapi/src/include/atscppapi/Logger.h index f5227d0..3227b63 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;
