Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
eos
QuarkDB
Commits
fc2ab04e
Commit
fc2ab04e
authored
Dec 13, 2019
by
Georgios Bitzes
Browse files
Replace ThreadSafeString with generic Synchronized class
parent
eb4f16d9
Pipeline
#1294531
passed with stages
in 53 minutes and 56 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
fc2ab04e
...
...
@@ -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.
...
...
src/raft/RaftReplicator.hh
View file @
fc2ab04e
...
...
@@ -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
};
ThreadSafeS
tring
statusNodeVersion
{
"N/A"
};
Synchronized
<
std
::
s
tring
>
statusNodeVersion
{
"N/A"
};
RaftJournal
&
journal
;
RaftState
&
state
;
...
...
src/utils/
ThreadSafeString
.hh
→
src/utils/
Synchronized
.hh
View file @
fc2ab04e
// ----------------------------------------------------------------------
// 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
test/utils.cc
View file @
fc2ab04e
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment