-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from resilientdb/client_memory
Client Memory #11 and config file bug fixed
- Loading branch information
Showing
12 changed files
with
271 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#ifndef _HASH_MAP_H_ | ||
#define _HASH_MAPS_H_ | ||
|
||
#include <iostream> | ||
#include <unordered_map> | ||
#include <mutex> | ||
|
||
template <class _key, class _val> | ||
class SpinLockMap | ||
{ | ||
public: | ||
SpinLockMap(){}; | ||
~SpinLockMap() { this->map.clear(); } | ||
|
||
bool exists(_key key) | ||
{ | ||
bool result = false; | ||
this->lock.lock(); | ||
result = this->map.count(key); | ||
this->lock.unlock(); | ||
return result; | ||
} | ||
bool check_and_get(_key key, _val &val) | ||
{ | ||
bool result = false; | ||
this->lock.lock(); | ||
result = this->map.count(key); | ||
if (result) | ||
val = this->map[key]; | ||
this->lock.unlock(); | ||
return result; | ||
} | ||
_val get(_key key) | ||
{ | ||
this->lock.lock(); | ||
|
||
assert(this->map.count(key)); | ||
_val temp = this->map[key]; | ||
|
||
this->lock.unlock(); | ||
return temp; | ||
}; | ||
|
||
void add(_key key, _val value) | ||
{ | ||
this->lock.lock(); | ||
this->map[key] = value; | ||
this->lock.unlock(); | ||
}; | ||
int remove(_key key) | ||
{ | ||
|
||
this->lock.lock(); | ||
|
||
int result = this->map.erase(key); | ||
|
||
this->lock.unlock(); | ||
return result; | ||
} | ||
|
||
_val pop(_key key) | ||
{ | ||
_val temp; | ||
|
||
this->lock.lock(); | ||
if (this->map.count(key)) | ||
{ | ||
temp = this->map[key]; | ||
this->map.erase(key); | ||
} | ||
else | ||
{ | ||
temp = 0; | ||
} | ||
this->lock.unlock(); | ||
return temp; | ||
} | ||
int size() | ||
{ | ||
return map.size(); | ||
} | ||
|
||
private: | ||
std::unordered_map<_key, _val> map; | ||
std::mutex lock; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef _HASH_MAP_H_ | ||
#define _HASH_MAPS_H_ | ||
|
||
#include <iostream> | ||
#include <set> | ||
#include <mutex> | ||
|
||
template <class _type> | ||
class SpinLockSet | ||
{ | ||
public: | ||
SpinLockSet(){}; | ||
~SpinLockSet() { this->set.clear(); } | ||
|
||
int exists(_type key) | ||
{ | ||
bool result = false; | ||
this->lock.lock(); | ||
result = this->set.count(key); | ||
this->lock.unlock(); | ||
return result; | ||
} | ||
void add(_type key) | ||
{ | ||
this->lock.lock(); | ||
this->set.insert(key); | ||
this->lock.unlock(); | ||
}; | ||
int check_and_add(_type key) | ||
{ | ||
bool result = false; | ||
this->lock.lock(); | ||
result = this->set.count(key); | ||
this->set.insert(key); | ||
this->lock.unlock(); | ||
return result; | ||
} | ||
int remove(_type key) | ||
{ | ||
this->lock.lock(); | ||
|
||
int result = this->set.erase(key); | ||
|
||
this->lock.unlock(); | ||
return result; | ||
} | ||
|
||
int size() | ||
{ | ||
return set.size(); | ||
} | ||
|
||
private: | ||
std::set<_type> set; | ||
std::mutex lock; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef _HASH_MAP_H_ | ||
#define _HASH_MAPS_H_ | ||
|
||
#include <iostream> | ||
#include <unordered_map> | ||
#include <mutex> | ||
|
||
class SharedInt | ||
{ | ||
public: | ||
SharedInt(){}; | ||
~SharedInt() {} | ||
|
||
uint64_t get() | ||
{ | ||
uint64_t result; | ||
this->lock.lock(); | ||
result = this->value; | ||
this->lock.unlock(); | ||
return result; | ||
}; | ||
void set(uint64_t val) | ||
{ | ||
this->lock.lock(); | ||
this->value = val; | ||
this->lock.unlock(); | ||
}; | ||
|
||
void add(uint64_t val) | ||
{ | ||
this->lock.lock(); | ||
this->value += val; | ||
this->lock.unlock(); | ||
}; | ||
void sub(uint64_t val) | ||
{ | ||
this->lock.lock(); | ||
this->value -= val; | ||
this->lock.unlock(); | ||
} | ||
|
||
private: | ||
uint64_t value; | ||
std::mutex lock; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.