aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-11-30 13:46:16 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-11-30 13:46:16 +0000
commit7c4816f80a4e65e03689ec7daa8778451f192cb8 (patch)
treef5d054cc023ab40b781427317f1ef7f197cdd71f /vespalib
parent08b36c530fc44251cbb9d22d214a43040991eb6c (diff)
- Use std::move(func).
- Remove redunadnt test code.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/invokeservice/invokeservice_test.cpp7
-rw-r--r--vespalib/src/vespa/vespalib/util/invokeserviceimpl.cpp14
-rw-r--r--vespalib/src/vespa/vespalib/util/invokeserviceimpl.h2
3 files changed, 9 insertions, 14 deletions
diff --git a/vespalib/src/tests/invokeservice/invokeservice_test.cpp b/vespalib/src/tests/invokeservice/invokeservice_test.cpp
index f0f8a21204d..22063281950 100644
--- a/vespalib/src/tests/invokeservice/invokeservice_test.cpp
+++ b/vespalib/src/tests/invokeservice/invokeservice_test.cpp
@@ -21,9 +21,7 @@ TEST("require that wakeup is called") {
EXPECT_EQUAL(0u, a._count);
auto ra = service.registerInvoke([&a]() noexcept { a.inc(); });
EXPECT_TRUE(ra);
- while (a._count == 0) {
- std::this_thread::sleep_for(1ms);
- }
+ a.wait_for_atleast(1);
ra.reset();
uint64_t countAtStop = a._count;
std::this_thread::sleep_for(1s);
@@ -47,9 +45,6 @@ TEST("require that same wakeup can be registered multiple times.") {
c.wait_for_atleast(1);
auto ra2 = service.registerInvoke([&a]() noexcept { a.inc(); });
EXPECT_TRUE(ra2);
- a.wait_for_atleast(1);
- b.wait_for_atleast(1);
- c.wait_for_atleast(1);
rb.reset();
uint64_t countAtStop = b._count;
diff --git a/vespalib/src/vespa/vespalib/util/invokeserviceimpl.cpp b/vespalib/src/vespa/vespalib/util/invokeserviceimpl.cpp
index ad8d9973356..ffa0825c950 100644
--- a/vespalib/src/vespa/vespalib/util/invokeserviceimpl.cpp
+++ b/vespalib/src/vespa/vespalib/util/invokeserviceimpl.cpp
@@ -10,7 +10,7 @@ InvokeServiceImpl::InvokeServiceImpl(duration napTime)
_lock(),
_currId(0),
_closed(false),
- _toWakeup(),
+ _toInvoke(),
_thread()
{
}
@@ -19,7 +19,7 @@ InvokeServiceImpl::~InvokeServiceImpl()
{
{
std::lock_guard guard(_lock);
- assert(_toWakeup.empty());
+ assert(_toInvoke.empty());
_closed = true;
}
if (_thread) {
@@ -47,7 +47,7 @@ std::unique_ptr<IDestructorCallback>
InvokeServiceImpl::registerInvoke(VoidFunc func) {
std::lock_guard guard(_lock);
uint64_t id = _currId++;
- _toWakeup.emplace_back(id, func);
+ _toInvoke.emplace_back(id, std::move(func));
if ( ! _thread) {
_thread = std::make_unique<std::thread>([this]() { runLoop(); });
}
@@ -57,11 +57,11 @@ InvokeServiceImpl::registerInvoke(VoidFunc func) {
void
InvokeServiceImpl::unregister(uint64_t id) {
std::lock_guard guard(_lock);
- auto found = std::find_if(_toWakeup.begin(), _toWakeup.end(), [id](const std::pair<uint64_t, VoidFunc> & a) {
+ auto found = std::find_if(_toInvoke.begin(), _toInvoke.end(), [id](const std::pair<uint64_t, VoidFunc> & a) {
return id == a.first;
});
- assert (found != _toWakeup.end());
- _toWakeup.erase(found);
+ assert (found != _toInvoke.end());
+ _toInvoke.erase(found);
}
void
@@ -70,7 +70,7 @@ InvokeServiceImpl::runLoop() {
while ( ! done ) {
{
std::lock_guard guard(_lock);
- for (auto & func: _toWakeup) {
+ for (auto & func: _toInvoke) {
func.second();
}
done = _closed;
diff --git a/vespalib/src/vespa/vespalib/util/invokeserviceimpl.h b/vespalib/src/vespa/vespalib/util/invokeserviceimpl.h
index 36347e47d3e..3b0c7690731 100644
--- a/vespalib/src/vespa/vespalib/util/invokeserviceimpl.h
+++ b/vespalib/src/vespa/vespalib/util/invokeserviceimpl.h
@@ -29,7 +29,7 @@ private:
std::mutex _lock;
uint64_t _currId;
bool _closed;
- std::vector<std::pair<uint64_t, VoidFunc>> _toWakeup;
+ std::vector<std::pair<uint64_t, VoidFunc>> _toInvoke;
std::unique_ptr<std::thread> _thread;
};