mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 12:37:08 +11:00
added drogon
This commit is contained in:
parent
db25d7deb9
commit
80ffdff068
4 changed files with 26 additions and 4 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +1,6 @@
|
||||||
[submodule "parallel-hashmap"]
|
[submodule "parallel-hashmap"]
|
||||||
path = third_party/parallel-hashmap
|
path = third_party/parallel-hashmap
|
||||||
url = https://github.com/greg7mdp/parallel-hashmap
|
url = https://github.com/greg7mdp/parallel-hashmap
|
||||||
|
[submodule "drogon"]
|
||||||
|
path = third_party/drogon
|
||||||
|
url = https://github.com/an-tao/drogon
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||||
add_executable(${PROJECT_NAME} main.cpp)
|
add_executable(${PROJECT_NAME} main.cpp)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC third_party)
|
||||||
|
|
||||||
|
add_subdirectory(third_party/drogon)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||||
|
|
@ -8,6 +8,10 @@ private:
|
||||||
uint_fast64_t balance;
|
uint_fast64_t balance;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
|
||||||
|
//for read/write of object's state concurrently
|
||||||
|
std::mutex bal_lock;
|
||||||
|
std::mutex pass_lock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief User constructor
|
* @brief User constructor
|
||||||
|
|
@ -26,6 +30,7 @@ public:
|
||||||
|
|
||||||
bool ChangePassword(const std::string &attempt, std::string &&new_pass)
|
bool ChangePassword(const std::string &attempt, std::string &&new_pass)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock{pass_lock};
|
||||||
const bool state = (password == attempt);
|
const bool state = (password == attempt);
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +50,14 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool SendFunds(User &a, User &b, uint_fast64_t amount, const std::string &attempt)
|
static bool SendFunds(User &a, User &b, uint_fast64_t amount, const std::string &attempt)
|
||||||
{
|
{
|
||||||
const bool state = (a.password == attempt) && (a.balance >= amount);
|
bool state;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock{a.pass_lock};
|
||||||
|
state = (a.password == attempt);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::scoped_lock<std::mutex, std::mutex> lock{a.bal_lock, b.bal_lock};
|
||||||
|
state = state && (a.balance >= amount);
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
a.balance -= amount;
|
a.balance -= amount;
|
||||||
|
|
@ -59,8 +71,9 @@ public:
|
||||||
*
|
*
|
||||||
* @return the balance
|
* @return the balance
|
||||||
*/
|
*/
|
||||||
uint_fast64_t GetBal() const
|
uint_fast64_t GetBal()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock{bal_lock};
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,8 +83,9 @@ public:
|
||||||
* @param attempt the password
|
* @param attempt the password
|
||||||
* @return wether the passwords match
|
* @return wether the passwords match
|
||||||
*/
|
*/
|
||||||
bool VerifyPassword(const std::string &attempt) const
|
bool VerifyPassword(const std::string &attempt) //for connected services
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock{pass_lock};
|
||||||
return (password == attempt);
|
return (password == attempt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
1
third_party/drogon
vendored
Submodule
1
third_party/drogon
vendored
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit a19d0427ed1fe80f40e5d4d2c8450a48c807be20
|
||||||
Loading…
Reference in a new issue