Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
sds-keyval
Commits
864e49c9
Commit
864e49c9
authored
Mar 27, 2019
by
Shane Snyder
Browse files
make mapdb thread-safe
parent
262e79b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/datastore/map_datastore.h
View file @
864e49c9
...
...
@@ -29,13 +29,18 @@ class MapDataStore : public AbstractDataStore {
public:
MapDataStore
()
:
AbstractDataStore
(),
_less
(
nullptr
),
_map
(
keycmp
(
this
))
{}
:
AbstractDataStore
(),
_less
(
nullptr
),
_map
(
keycmp
(
this
))
{
ABT_mutex_create
(
&
_insert_mutex
);
}
MapDataStore
(
Duplicates
duplicates
,
bool
eraseOnGet
,
bool
debug
)
:
AbstractDataStore
(
duplicates
,
eraseOnGet
,
debug
),
_less
(
nullptr
),
_map
(
keycmp
(
this
))
{}
:
AbstractDataStore
(
duplicates
,
eraseOnGet
,
debug
),
_less
(
nullptr
),
_map
(
keycmp
(
this
)){
ABT_mutex_create
(
&
_insert_mutex
);
}
~
MapDataStore
()
=
default
;
~
MapDataStore
()
{
ABT_mutex_free
(
&
_insert_mutex
);
}
virtual
bool
openDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
)
{
_name
=
db_name
;
...
...
@@ -54,7 +59,9 @@ class MapDataStore : public AbstractDataStore {
if
(
_duplicates
==
Duplicates
::
IGNORE
&&
(
x
!=
0
))
{
return
false
;
}
ABT_mutex_lock
(
_insert_mutex
);
_map
.
insert
(
std
::
make_pair
(
key
,
data
));
ABT_mutex_unlock
(
_insert_mutex
);
return
true
;
}
...
...
@@ -194,6 +201,7 @@ class MapDataStore : public AbstractDataStore {
private:
AbstractDataStore
::
comparator_fn
_less
;
std
::
map
<
ds_bulk_t
,
ds_bulk_t
,
keycmp
>
_map
;
ABT_mutex
_insert_mutex
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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