Fixes

parent bbfc9f10
...@@ -43,6 +43,8 @@ LevelDB* levelDb = nullptr; ...@@ -43,6 +43,8 @@ LevelDB* levelDb = nullptr;
std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) { std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto result = std::make_shared<std::string>(); auto result = std::make_shared<std::string>();
if (db == nullptr) { if (db == nullptr) {
...@@ -61,6 +63,8 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) { ...@@ -61,6 +63,8 @@ std::shared_ptr<std::string> LevelDB::readString(const std::string &_key) {
void LevelDB::writeString(const std::string &_key, const std::string &_value) { void LevelDB::writeString(const std::string &_key, const std::string &_value) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Put(writeOptions, Slice(_key), Slice(_value)); auto status = db->Put(writeOptions, Slice(_key), Slice(_value));
throwExceptionOnError(status); throwExceptionOnError(status);
...@@ -69,6 +73,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) { ...@@ -69,6 +73,8 @@ void LevelDB::writeString(const std::string &_key, const std::string &_value) {
void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value, void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value,
size_t _valueLen) { size_t _valueLen) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Put(writeOptions, Slice(_key, _keyLen), Slice(value, _valueLen)); auto status = db->Put(writeOptions, Slice(_key, _keyLen), Slice(value, _valueLen));
throwExceptionOnError(status); throwExceptionOnError(status);
...@@ -78,6 +84,8 @@ void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value ...@@ -78,6 +84,8 @@ void LevelDB::writeByteArray(const char *_key, size_t _keyLen, const char *value
void LevelDB::writeByteArray(std::string &_key, const char *value, void LevelDB::writeByteArray(std::string &_key, const char *value,
size_t _valueLen) { size_t _valueLen) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto status = db->Put(writeOptions, Slice(_key), Slice(value, _valueLen)); auto status = db->Put(writeOptions, Slice(_key), Slice(value, _valueLen));
throwExceptionOnError(status); throwExceptionOnError(status);
...@@ -95,6 +103,8 @@ void LevelDB::throwExceptionOnError(Status _status) { ...@@ -95,6 +103,8 @@ void LevelDB::throwExceptionOnError(Status _status) {
uint64_t LevelDB::visitKeys(LevelDB::KeyVisitor *_visitor, uint64_t _maxKeysToVisit) { uint64_t LevelDB::visitKeys(LevelDB::KeyVisitor *_visitor, uint64_t _maxKeysToVisit) {
std::lock_guard<std::recursive_mutex> lock(mutex);
uint64_t readCounter = 0; uint64_t readCounter = 0;
leveldb::Iterator *it = db->NewIterator(readOptions); leveldb::Iterator *it = db->NewIterator(readOptions);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <mutex>
namespace leveldb { namespace leveldb {
class DB; class DB;
...@@ -36,6 +37,8 @@ namespace leveldb { ...@@ -36,6 +37,8 @@ namespace leveldb {
class LevelDB { class LevelDB {
std::recursive_mutex mutex;
leveldb::DB* db; leveldb::DB* db;
public: public:
......
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