summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2017-10-26 20:46:05 +0200
committerTor Egge <Tor.Egge@oath.com>2017-10-27 08:50:13 +0000
commitfaef2c4997d45789a43eb3b8c8ed002fce20288a (patch)
tree18233a34ef9ec6c263669cbe0c6a14d8cb86f187 /searchcore
parentaa6c4b5f9247de4c3d7f1923c68a25f723a09fa8 (diff)
Use std::unique_lock<std::mutex> to guard engine.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp54
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/engine_base.h3
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp1
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h3
4 files changed, 30 insertions, 31 deletions
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
index 1863b2f20e5..83312a41875 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
@@ -91,7 +91,8 @@ FastS_EngineBase::FastS_EngineBase(FastS_EngineDesc *desc,
_dataset(dataset),
_nextds(NULL),
_prevpart(NULL),
- _nextpart(NULL)
+ _nextpart(NULL),
+ _lock()
{
FastS_assert(_dataset != NULL);
}
@@ -110,10 +111,11 @@ FastS_EngineBase::~FastS_EngineBase()
void
FastS_EngineBase::SlowQuery(double limit, double secs, bool silent)
{
- LockEngine();
- _stats._slowQueryCnt++;
- _stats._slowQuerySecs += secs;
- UnlockEngine();
+ {
+ std::unique_lock<std::mutex> engineGuard(_lock);
+ _stats._slowQueryCnt++;
+ _stats._slowQuerySecs += secs;
+ }
if (!silent)
LOG(warning,
"engine %s query slow by %.3fs + %.3fs",
@@ -124,10 +126,11 @@ FastS_EngineBase::SlowQuery(double limit, double secs, bool silent)
void
FastS_EngineBase::SlowDocsum(double limit, double secs)
{
- LockEngine();
- _stats._slowDocsumCnt++;
- _stats._slowDocsumSecs += secs;
- UnlockEngine();
+ {
+ std::unique_lock<std::mutex> engineGuard(_lock);
+ _stats._slowDocsumCnt++;
+ _stats._slowDocsumSecs += secs;
+ }
LOG(warning,
"engine %s docsum slow by %.3fs + %.3fs",
_config._name, limit, secs);
@@ -170,7 +173,7 @@ FastS_EngineBase::SampleQueueLens()
double queueLen;
double activecnt;
- LockEngine();
+ std::unique_lock<std::mutex> engineGuard(_lock);
if (_stats._queueLenSampleCnt > 0)
queueLen = (double) _stats._queueLenSampleAcc / (double) _stats._queueLenSampleCnt;
else
@@ -198,7 +201,6 @@ FastS_EngineBase::SampleQueueLens()
_stats._queueLenIdx = 0;
if (_stats._queueLenValid < _stats._queuestatsize)
_stats._queueLenValid++;
- UnlockEngine();
}
void
@@ -214,12 +216,13 @@ FastS_EngineBase::MarkBad(uint32_t badness)
{
bool worse = false;
- LockEngine();
- if (badness > _badness) {
- _badness = badness;
- worse = true;
+ {
+ std::unique_lock<std::mutex> engineGuard(_lock);
+ if (badness > _badness) {
+ _badness = badness;
+ worse = true;
+ }
}
- UnlockEngine();
if (worse) {
if (badness <= BAD_NOT) {
@@ -233,16 +236,17 @@ FastS_EngineBase::MarkBad(uint32_t badness)
void
FastS_EngineBase::ClearBad()
{
- LockEngine();
- if (_badness >= BAD_CONFIG) {
- UnlockEngine();
- LOG(warning,
- "engine %s still bad due to illegal config",
- _config._name);
- return;
+ {
+ std::unique_lock<std::mutex> engineGuard(_lock);
+ if (_badness >= BAD_CONFIG) {
+ engineGuard.unlock();
+ LOG(warning,
+ "engine %s still bad due to illegal config",
+ _config._name);
+ return;
+ }
+ _badness = BAD_NOT;
}
- _badness = BAD_NOT;
- UnlockEngine();
HandleClearedBad();
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.h b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.h
index 5dbbddb3bb7..7c109cb99c0 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.h
@@ -138,6 +138,7 @@ protected:
FastS_EngineBase *_nextds; // list of engines in dataset
FastS_EngineBase *_prevpart; // list of engines in partition
FastS_EngineBase *_nextpart; // list of engines in partition
+ std::mutex _lock;
public:
FastS_EngineBase(FastS_EngineDesc *desc, FastS_PlainDataSet *dataset);
@@ -181,8 +182,6 @@ public:
// common engine API
//------------------
- virtual void LockEngine() = 0;
- virtual void UnlockEngine() = 0;
virtual void Ping();
virtual void HandleClearedBad() {}
virtual void HandleUp() {}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
index 1f60c38ca10..c2f8cbfbae5 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
@@ -92,7 +92,6 @@ FastS_FNET_Engine::Disconnect()
FastS_FNET_Engine::FastS_FNET_Engine(FastS_EngineDesc *desc,
FastS_FNET_DataSet *dataset)
: FastS_EngineBase(desc, dataset),
- _lock(),
_spec(),
_transport(dataset->GetTransport()),
_conn(NULL),
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
index 54df953ad9d..4374deb2642 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
@@ -67,7 +67,6 @@ public:
friend class FastS_FNET_Engine::ConnectTask;
private:
- FastOS_Mutex _lock;
std::string _hostName;
int _portNumber;
std::string _spec;
@@ -97,8 +96,6 @@ public:
// common engine API
//------------------
- virtual void LockEngine() override { _lock.Lock(); }
- virtual void UnlockEngine() override { _lock.Unlock(); }
virtual void Ping() override;
virtual void HandleClearedBad() override;
virtual void HandleUp() override;