summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/dbtests/basictests.cpp27
-rw-r--r--src/mongo/util/SConscript1
-rw-r--r--src/mongo/util/progress_meter.cpp8
-rw-r--r--src/mongo/util/progress_meter.h19
-rw-r--r--src/mongo/util/thread_safe_string.cpp42
-rw-r--r--src/mongo/util/thread_safe_string.h81
6 files changed, 17 insertions, 161 deletions
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp
index 6823d42071c..5b5e999d45f 100644
--- a/src/mongo/dbtests/basictests.cpp
+++ b/src/mongo/dbtests/basictests.cpp
@@ -30,6 +30,7 @@
#include "mongo/platform/basic.h"
#include <iostream>
+#include <string>
#include "mongo/db/client.h"
#include "mongo/dbtests/dbtests.h"
@@ -37,7 +38,6 @@
#include "mongo/util/queue.h"
#include "mongo/util/str.h"
#include "mongo/util/text.h"
-#include "mongo/util/thread_safe_string.h"
#include "mongo/util/timer.h"
namespace BasicTests {
@@ -239,31 +239,6 @@ public:
}
};
-class ThreadSafeStringTest {
-public:
- void run() {
- ThreadSafeString s;
- s = "eliot";
- ASSERT_EQUALS(s.toString(), "eliot");
- ASSERT(s.toString() != "eliot2");
-
- ThreadSafeString s2;
- s2 = s.toString().c_str();
- ASSERT_EQUALS(s2.toString(), "eliot");
-
-
- {
- string foo;
- {
- ThreadSafeString bar;
- bar = "eliot2";
- foo = bar.toString();
- }
- ASSERT_EQUALS("eliot2", foo);
- }
- }
-};
-
struct StringSplitterTest {
void test(string s) {
vector<string> v = StringSplitter::split(s, ",");
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index 7634803dff8..66eae72ae20 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -150,7 +150,6 @@ env.Library(
target='progress_meter',
source=[
'progress_meter.cpp',
- 'thread_safe_string.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/util/progress_meter.cpp b/src/mongo/util/progress_meter.cpp
index 5a7fde9f3db..630a6dd8bf6 100644
--- a/src/mongo/util/progress_meter.cpp
+++ b/src/mongo/util/progress_meter.cpp
@@ -66,10 +66,10 @@ bool ProgressMeter::hit(int n) {
return false;
if (_total > 0) {
+ std::string stashedName = getName();
int per = (int)(((double)_done * 100.0) / (double)_total);
-
logv2::DynamicAttributes attrs;
- attrs.add("name", _name);
+ attrs.add("name", stashedName);
attrs.add("done", _done);
if (_showTotal) {
attrs.add("total", _total);
@@ -89,9 +89,9 @@ std::string ProgressMeter::toString() const {
return "";
std::stringstream buf;
if (_total) {
- buf << _name << ": " << _done << '/' << _total << ' ' << (_done * 100) / _total << '%';
+ buf << getName() << ": " << _done << '/' << _total << ' ' << (_done * 100) / _total << '%';
} else {
- buf << _name << ": not started";
+ buf << getName() << ": not started";
}
if (!_units.empty()) {
diff --git a/src/mongo/util/progress_meter.h b/src/mongo/util/progress_meter.h
index 35b3305f94a..1e2e511da72 100644
--- a/src/mongo/util/progress_meter.h
+++ b/src/mongo/util/progress_meter.h
@@ -29,9 +29,11 @@
#pragma once
-#include "mongo/util/thread_safe_string.h"
-
#include <string>
+#include <utility>
+
+#include "mongo/base/string_data.h"
+#include "mongo/stdx/mutex.h"
namespace mongo {
@@ -45,8 +47,7 @@ public:
int checkInterval = 100,
std::string units = "",
std::string name = "Progress")
- : _showTotal(true), _units(units) {
- _name = name.c_str();
+ : _showTotal(true), _units(units), _name(std::move(name)) {
reset(total, secondsBetween, checkInterval);
}
@@ -78,10 +79,12 @@ public:
}
void setName(StringData name) {
- _name = name;
+ stdx::lock_guard lk(_nameMutex);
+ _name = std::string{name};
}
std::string getName() const {
- return _name.toString();
+ stdx::lock_guard lk(_nameMutex);
+ return _name;
}
void setTotalWhileRunning(unsigned long long total) {
@@ -123,7 +126,9 @@ private:
int _lastTime;
std::string _units;
- ThreadSafeString _name;
+
+ mutable stdx::mutex _nameMutex; // NOLINT
+ std::string _name; // guarded by _nameMutex
};
/*
diff --git a/src/mongo/util/thread_safe_string.cpp b/src/mongo/util/thread_safe_string.cpp
deleted file mode 100644
index e82b0353d33..00000000000
--- a/src/mongo/util/thread_safe_string.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include <ostream>
-
-#include "mongo/util/thread_safe_string.h"
-
-namespace mongo {
-
-std::ostream& operator<<(std::ostream& s, const ThreadSafeString& o) {
- return s << o.toString();
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/thread_safe_string.h b/src/mongo/util/thread_safe_string.h
deleted file mode 100644
index 606d0144f7f..00000000000
--- a/src/mongo/util/thread_safe_string.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <cstring>
-#include <iosfwd>
-#include <string>
-
-#include "mongo/base/string_data.h"
-
-namespace mongo {
-
-/**
- * this is a thread safe string
- * you will never get a bad pointer, though data may be mungedd
- */
-class ThreadSafeString {
- ThreadSafeString(const ThreadSafeString&) = delete;
- ThreadSafeString& operator=(const ThreadSafeString&) = delete;
-
-public:
- ThreadSafeString(size_t size = 256) : _size(size), _buf(new char[size]) {
- memset(_buf, '\0', _size);
- }
-
- ~ThreadSafeString() {
- delete[] _buf;
- }
-
- std::string toString() const {
- return _buf;
- }
-
- ThreadSafeString& operator=(StringData str) {
- size_t s = str.size();
- if (s >= _size - 2)
- s = _size - 2;
- strncpy(_buf, str.rawData(), s);
- _buf[s] = '\0';
- return *this;
- }
-
- bool empty() const {
- return _buf[0] == '\0';
- }
-
-private:
- const size_t _size;
- char* const _buf;
-};
-
-std::ostream& operator<<(std::ostream& s, const ThreadSafeString& o);
-
-} // namespace mongo