summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-10-08 18:56:55 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-10-08 18:56:55 +0000
commit32286c1b4f19b0db0e899155dd26af8cde8a6b5b (patch)
tree26d715ea60d2bcb77e10e05985125241c8ef70f0 /staging_vespalib
parent2e3515a187d0b3aae7ae1afd2708f011b9b8bf22 (diff)
Use std::mutex
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/CMakeLists.txt1
-rw-r--r--staging_vespalib/src/tests/librarypool/.gitignore1
-rw-r--r--staging_vespalib/src/tests/librarypool/CMakeLists.txt8
-rw-r--r--staging_vespalib/src/tests/librarypool/librarypool_test.cpp38
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.cpp13
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.h5
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp11
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_health_producer.h6
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.cpp12
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.h10
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/librarypool.cpp58
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/librarypool.h39
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp8
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h5
15 files changed, 33 insertions, 183 deletions
diff --git a/staging_vespalib/CMakeLists.txt b/staging_vespalib/CMakeLists.txt
index f2f8a41b68d..efb57618823 100644
--- a/staging_vespalib/CMakeLists.txt
+++ b/staging_vespalib/CMakeLists.txt
@@ -23,7 +23,6 @@ vespa_define_module(
src/tests/floatingpointtype
src/tests/growablebytebuffer
src/tests/json
- src/tests/librarypool
src/tests/memorydatastore
src/tests/metrics
src/tests/objectdump
diff --git a/staging_vespalib/src/tests/librarypool/.gitignore b/staging_vespalib/src/tests/librarypool/.gitignore
deleted file mode 100644
index 1a1aea2fda0..00000000000
--- a/staging_vespalib/src/tests/librarypool/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-staging_vespalib_librarypool_test_app
diff --git a/staging_vespalib/src/tests/librarypool/CMakeLists.txt b/staging_vespalib/src/tests/librarypool/CMakeLists.txt
deleted file mode 100644
index 83e1e92e680..00000000000
--- a/staging_vespalib/src/tests/librarypool/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(staging_vespalib_librarypool_test_app TEST
- SOURCES
- librarypool_test.cpp
- DEPENDS
- staging_vespalib
-)
-vespa_add_test(NAME staging_vespalib_librarypool_test_app COMMAND staging_vespalib_librarypool_test_app)
diff --git a/staging_vespalib/src/tests/librarypool/librarypool_test.cpp b/staging_vespalib/src/tests/librarypool/librarypool_test.cpp
deleted file mode 100644
index adefdf3aa6b..00000000000
--- a/staging_vespalib/src/tests/librarypool/librarypool_test.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
-#include <vespa/vespalib/util/librarypool.h>
-#include <vespa/vespalib/util/exceptions.h>
-
-using namespace vespalib;
-
-class Test : public TestApp
-{
-public:
- int Main() override;
-};
-
-int
-Test::Main()
-{
- TEST_INIT("librarypool_test");
- LibraryPool p;
- ASSERT_TRUE(p.get("z") == NULL);
- p.loadLibrary("z");
- ASSERT_TRUE(p.get("z") != NULL);
- ASSERT_TRUE(p.get("z")->GetSymbol("some_symbol_that_is_not_there") == NULL);
- ASSERT_TRUE(p.get("z")->GetSymbol("compress") != NULL);
- try {
- p.loadLibrary("not_found");
- ASSERT_TRUE(false);
- } catch (const IllegalArgumentException & e) {
- ASSERT_TRUE(p.get("not_found") == NULL);
- }
- {
- const LibraryPool & c(p);
- ASSERT_TRUE(c.get("z") != NULL);
- ASSERT_TRUE(c.get("not_found") == NULL);
- }
- TEST_DONE();
-}
-
-TEST_APPHOOK(Test)
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.cpp b/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.cpp
index d016b052dae..d4fe0ef43e1 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.cpp
@@ -10,27 +10,28 @@ SimpleComponentConfigProducer::SimpleComponentConfigProducer()
{
}
+SimpleComponentConfigProducer::~SimpleComponentConfigProducer() = default;
+
void
SimpleComponentConfigProducer::addConfig(const Config &config)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_state.insert(std::make_pair(config.name, config)).first->second = config;
}
void
SimpleComponentConfigProducer::removeConfig(const vespalib::string &name)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_state.erase(name);
}
void
SimpleComponentConfigProducer::getComponentConfig(Consumer &consumer)
{
- typedef std::map<vespalib::string, Config>::const_iterator ITR;
- LockGuard guard(_lock);
- for (ITR itr = _state.begin(); itr != _state.end(); ++itr) {
- consumer.add(itr->second);
+ std::lock_guard guard(_lock);
+ for (const auto & entry : _state) {
+ consumer.add(entry.second);
}
}
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.h b/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.h
index 5783139c9d5..70dd00a8792 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.h
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_component_config_producer.h
@@ -3,19 +3,20 @@
#pragma once
#include "component_config_producer.h"
-#include <vespa/vespalib/util/sync.h>
#include <map>
+#include <mutex>
namespace vespalib {
class SimpleComponentConfigProducer : public ComponentConfigProducer
{
private:
- Lock _lock;
+ std::mutex _lock;
std::map<vespalib::string, Config> _state;
public:
SimpleComponentConfigProducer();
+ ~SimpleComponentConfigProducer() override;
void addConfig(const Config &config);
void removeConfig(const vespalib::string &name);
void getComponentConfig(Consumer &consumer) override;
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp
index 651dab97e68..a25888399c1 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.cpp
@@ -4,7 +4,6 @@
#include <vespa/defaults.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
namespace {
@@ -51,28 +50,26 @@ SimpleHealthProducer::SimpleHealthProducer()
setOk();
}
-SimpleHealthProducer::~SimpleHealthProducer()
-{
-}
+SimpleHealthProducer::~SimpleHealthProducer() = default;
void
SimpleHealthProducer::setOk()
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_health = Health(true, "All OK");
}
void
SimpleHealthProducer::setFailed(const vespalib::string &msg)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_health = Health(false, msg);
}
HealthProducer::Health
SimpleHealthProducer::getHealth() const
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
if (_health.ok && diskFailed()) {
return Health(false, "disk ping failed");
}
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.h b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.h
index 90fe2489b0a..fc89f5c7644 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.h
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_health_producer.h
@@ -3,19 +3,19 @@
#pragma once
#include "health_producer.h"
-#include <vespa/vespalib/util/sync.h>
+#include <mutex>
namespace vespalib {
class SimpleHealthProducer : public HealthProducer
{
private:
- Lock _lock;
+ mutable std::mutex _lock;
HealthProducer::Health _health;
public:
SimpleHealthProducer();
- ~SimpleHealthProducer();
+ ~SimpleHealthProducer() override;
void setOk();
void setFailed(const vespalib::string &msg);
Health getHealth() const override;
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.cpp b/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.cpp
index 97be2a61235..b39bc96a5b6 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.cpp
@@ -11,35 +11,33 @@ SimpleMetricsProducer::SimpleMetricsProducer()
{
}
-SimpleMetricsProducer::~SimpleMetricsProducer()
-{
-}
+SimpleMetricsProducer::~SimpleMetricsProducer() = default;
void
SimpleMetricsProducer::setMetrics(const vespalib::string &metrics)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_metrics = metrics;
}
vespalib::string
SimpleMetricsProducer::getMetrics(const vespalib::string &)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
return _metrics;
}
void
SimpleMetricsProducer::setTotalMetrics(const vespalib::string &metrics)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_totalMetrics = metrics;
}
vespalib::string
SimpleMetricsProducer::getTotalMetrics(const vespalib::string &)
{
- LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
return _totalMetrics;
}
diff --git a/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.h b/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.h
index 1dd1452c32f..fdcf1dce6b6 100644
--- a/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.h
+++ b/staging_vespalib/src/vespa/vespalib/net/simple_metrics_producer.h
@@ -3,24 +3,24 @@
#pragma once
#include "metrics_producer.h"
-#include <vespa/vespalib/util/sync.h>
+#include <mutex>
namespace vespalib {
class SimpleMetricsProducer : public MetricsProducer
{
private:
- Lock _lock;
+ std::mutex _lock;
vespalib::string _metrics;
vespalib::string _totalMetrics;
public:
SimpleMetricsProducer();
- ~SimpleMetricsProducer();
+ ~SimpleMetricsProducer() override;
void setMetrics(const vespalib::string &metrics);
- virtual vespalib::string getMetrics(const vespalib::string &consumer) override;
+ vespalib::string getMetrics(const vespalib::string &consumer) override;
void setTotalMetrics(const vespalib::string &metrics);
- virtual vespalib::string getTotalMetrics(const vespalib::string &consumer) override;
+ vespalib::string getTotalMetrics(const vespalib::string &consumer) override;
};
} // namespace vespalib
diff --git a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
index 586e06396e7..70f17f76e4c 100644
--- a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -12,7 +12,6 @@ vespa_add_library(staging_vespalib_vespalib_util OBJECT
jsonexception.cpp
jsonstream.cpp
jsonwriter.cpp
- librarypool.cpp
process_memory_stats.cpp
programoptions.cpp
programoptions_testutils.cpp
diff --git a/staging_vespalib/src/vespa/vespalib/util/librarypool.cpp b/staging_vespalib/src/vespa/vespalib/util/librarypool.cpp
deleted file mode 100644
index 2a3ca21c369..00000000000
--- a/staging_vespalib/src/vespa/vespalib/util/librarypool.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vespalib/util/librarypool.h>
-#include <vespa/vespalib/util/exceptions.h>
-#include <vespa/vespalib/util/stringfmt.h>
-
-namespace vespalib {
-
-LibraryPool::LibraryPool() :
- _libraries(),
- _lock()
-{
-}
-
-LibraryPool::~LibraryPool()
-{
- LockGuard guard(_lock);
- _libraries.clear();
-}
-
-void
-LibraryPool::loadLibrary(stringref libName)
-{
- LockGuard guard(_lock);
- if (_libraries.find(libName) == _libraries.end()) {
- DynamicLibrarySP lib(new FastOS_DynamicLibrary);
- string file(libName);
- if (!lib->Open(file.c_str())) {
- string error = lib->GetLastErrorString();
- throw IllegalArgumentException(make_string("Failed loading dynamic library '%s' due to '%s'.",
- file.c_str(), error.c_str()));
- } else {
- _libraries[libName] = lib;
- }
- }
-}
-
-FastOS_DynamicLibrary *
-LibraryPool::get(stringref name)
-{
- LockGuard guard(_lock);
- LibraryMap::const_iterator found(_libraries.find(name));
- return (found != _libraries.end())
- ? found->second.get()
- : NULL;
-}
-
-const FastOS_DynamicLibrary *
-LibraryPool::get(stringref name) const
-{
- LockGuard guard(_lock);
- LibraryMap::const_iterator found(_libraries.find(name));
- return (found != _libraries.end())
- ? found->second.get()
- : NULL;
-}
-
-}
diff --git a/staging_vespalib/src/vespa/vespalib/util/librarypool.h b/staging_vespalib/src/vespa/vespalib/util/librarypool.h
deleted file mode 100644
index f9149589338..00000000000
--- a/staging_vespalib/src/vespa/vespalib/util/librarypool.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/vespalib/util/sync.h>
-#include <vespa/vespalib/stllike/string.h>
-#include <vespa/fastos/dynamiclibrary.h>
-#include <map>
-
-namespace vespalib {
-
-class LibraryPool
-{
-public:
- LibraryPool();
- ~LibraryPool();
- /**
- * This will load the library with the name given.
- * - It will verify linkage at load time.
- * - Symbols will be private.
- * @param name The name of the library to load. That is without the 'lib' prefix and the '.so' extension.
- * @throws IllegalArgumentException if there are any errors.
- */
- void loadLibrary(stringref name);
- /**
- * Will return the library requested. NULL if not found.
- * @param name The name of the library as given in the @ref loadLibrary call.
- * @return The library that has already been loaded. NULL if not found.
- */
- FastOS_DynamicLibrary *get(stringref name);
- const FastOS_DynamicLibrary *get(stringref name) const;
-private:
- typedef std::shared_ptr<FastOS_DynamicLibrary> DynamicLibrarySP;
- typedef std::map<vespalib::string, DynamicLibrarySP> LibraryMap;
- LibraryMap _libraries;
- Lock _lock;
-};
-
-}
-
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
index d9b4feda293..3f5b3b79656 100644
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.cpp
@@ -45,7 +45,7 @@ ScheduledExecutor::ScheduledExecutor()
ScheduledExecutor::~ScheduledExecutor()
{
- vespalib::LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_transport->ShutDown(true);
_threadPool.Close();
_taskList.clear();
@@ -55,7 +55,7 @@ ScheduledExecutor::~ScheduledExecutor()
void
ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, duration delay, duration interval)
{
- vespalib::LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
TimerTaskPtr tTask(new TimerTask(_transport->GetScheduler(), std::move(task), interval));
_taskList.push_back(std::move(tTask));
_taskList.back()->Schedule(to_s(delay));
@@ -64,10 +64,10 @@ ScheduledExecutor::scheduleAtFixedRate(vespalib::Executor::Task::UP task, durati
void
ScheduledExecutor::reset()
{
- vespalib::LockGuard guard(_lock);
+ std::lock_guard guard(_lock);
_transport->ShutDown(true);
_taskList.clear();
- _transport.reset(new FNET_Transport());
+ _transport = std::make_unique<FNET_Transport>();
_transport->Start(&_threadPool);
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
index 0f052c762a7..0b98a236f74 100644
--- a/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
+++ b/staging_vespalib/src/vespa/vespalib/util/scheduledexecutor.h
@@ -2,7 +2,6 @@
#pragma once
#include <vespa/vespalib/util/executor.h>
-#include <vespa/vespalib/util/sync.h>
#include <vespa/vespalib/util/time.h>
#include <vespa/fastos/thread.h>
#include <vector>
@@ -25,8 +24,8 @@ private:
typedef std::vector<TimerTaskPtr> TaskList;
FastOS_ThreadPool _threadPool;
std::unique_ptr<FNET_Transport> _transport;
- vespalib::Lock _lock;
- TaskList _taskList;
+ std::mutex _lock;
+ TaskList _taskList;
public:
/**