Commit fc2ab04e authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Replace ThreadSafeString with generic Synchronized class

parent eb4f16d9
Pipeline #1294531 passed with stages
in 53 minutes and 56 seconds
......@@ -10,6 +10,7 @@ to escape field separators (#).
### New features
- Addition of ``quarkdb-server`` binary to allow running QDB without XRootD.
- Add support for ``CLIENT SETNAME`` command as aid in debugging.
### Improvements
- Improvements to replication behaviour when one of the followers is very far behind the leader.
......
......@@ -31,7 +31,7 @@
#include "raft/RaftState.hh"
#include "raft/RaftTrimmer.hh"
#include "utils/AssistedThread.hh"
#include "utils/ThreadSafeString.hh"
#include "utils/Synchronized.hh"
namespace quarkdb {
......@@ -97,7 +97,7 @@ private:
// overhead of atomics.
std::atomic<bool> statusOnline {false};
std::atomic<LogIndex> statusNextIndex {-1};
ThreadSafeString statusNodeVersion {"N/A"};
Synchronized<std::string> statusNodeVersion {"N/A"};
RaftJournal &journal;
RaftState &state;
......
// ----------------------------------------------------------------------
// File: ThreadSafeString.hh
// File: Synchronized.hh
// Author: Georgios Bitzes - CERN
// ----------------------------------------------------------------------
......@@ -21,35 +21,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef QUARKDB_THREAD_SAFE_STRING_HH
#define QUARKDB_THREAD_SAFE_STRING_HH
#ifndef QUARKDB_SYNCHRONIZED_HH
#define QUARKDB_SYNCHRONIZED_HH
#include <string>
#include <shared_mutex>
namespace quarkdb {
class ThreadSafeString {
template<typename T>
class Synchronized {
public:
ThreadSafeString(const std::string &val) : contents(val) {}
ThreadSafeString() {}
Synchronized(const T& t) {}
void set(const std::string &value) {
Synchronized() {}
void set(const T& t) {
std::unique_lock<std::shared_mutex> lock(mtx);
contents = value;
contents = t;
}
std::string get() const {
T get() const {
std::shared_lock<std::shared_mutex> lock(mtx);
return contents;
}
private:
T contents;
mutable std::shared_mutex mtx;
std::string contents;
};
}
#endif
......@@ -35,6 +35,7 @@
#include "utils/Random.hh"
#include "utils/AssistedThread.hh"
#include "utils/CoreLocalArray.hh"
#include "utils/Synchronized.hh"
#include "redis/Transaction.hh"
#include "redis/Authenticator.hh"
#include "redis/LeaseFilter.hh"
......@@ -1095,4 +1096,11 @@ TEST(HistoricalStatistics, BasicSanity) {
);
}
TEST(Synchronized, String) {
Synchronized<std::string> syncstr;
ASSERT_EQ(syncstr.get(), "");
syncstr.set("test");
ASSERT_EQ(syncstr.get(), "test");
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment