-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
54 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 |
---|---|---|
@@ -1,38 +1,41 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include <utility> | ||
|
||
#include "cct_const.hpp" | ||
#include "cct_fixedcapacityvector.hpp" | ||
#include "cct_json.hpp" | ||
#include "cct_string.hpp" | ||
#include "cct_vector.hpp" | ||
|
||
namespace cct::schema { | ||
|
||
struct AccountOwner { | ||
using trivially_relocatable = is_trivially_relocatable<string>::type; | ||
|
||
string enName; | ||
string koName; | ||
|
||
using trivially_relocatable = is_trivially_relocatable<string>::type; | ||
}; | ||
|
||
struct APIKey { | ||
using trivially_relocatable = is_trivially_relocatable<string>::type; | ||
|
||
string key; | ||
string priv; // private is a reserved keyword - we override the json field name below | ||
string passphrase; | ||
AccountOwner accountOwner; | ||
|
||
using trivially_relocatable = is_trivially_relocatable<string>::type; | ||
bool enabled = true; | ||
}; | ||
|
||
using APIKeys = std::unordered_map<string, APIKey>; | ||
using APIKeys = vector<std::pair<string, APIKey>>; | ||
|
||
using APIKeysPerExchangeMap = std::unordered_map<ExchangeNameEnum, APIKeys>; | ||
using APIKeysPerExchange = std::unordered_map<ExchangeNameEnum, APIKeys>; | ||
|
||
} // namespace cct::schema | ||
|
||
template <> | ||
struct glz::meta<::cct::schema::APIKey> { | ||
using V = ::cct::schema::APIKey; | ||
static constexpr auto value = | ||
object("key", &V::key, "private", &V::priv, "passphrase", &V::passphrase, "accountOwner", &V::accountOwner); | ||
static constexpr auto value = object("key", &V::key, "private", &V::priv, "passphrase", &V::passphrase, | ||
"accountOwner", &V::accountOwner, "enabled", &V::enabled); | ||
}; |
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,43 @@ | ||
#include "threadpool.hpp" | ||
|
||
#include <mutex> | ||
#include <utility> | ||
|
||
#include "cct_invalid_argument_exception.hpp" | ||
|
||
namespace cct { | ||
|
||
ThreadPool::ThreadPool(int nbThreads) { | ||
if (nbThreads < 1) { | ||
throw invalid_argument("number of threads should be strictly positive"); | ||
} | ||
_workers.reserve(static_cast<decltype(_workers)::size_type>(nbThreads)); | ||
for (decltype(nbThreads) threadPos = 0; threadPos < nbThreads; ++threadPos) { | ||
_workers.emplace_back([this] { | ||
while (true) { | ||
TasksQueue::value_type task; | ||
|
||
{ | ||
std::unique_lock<std::mutex> lock(this->_queueMutex); | ||
this->_condition.wait(lock, [this] { return this->_stop || !this->_tasks.empty(); }); | ||
if (this->_stop && this->_tasks.empty()) { | ||
break; | ||
} | ||
task = std::move(this->_tasks.front()); | ||
this->_tasks.pop(); | ||
} | ||
task(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
ThreadPool::~ThreadPool() { | ||
{ | ||
std::unique_lock<std::mutex> lock(_queueMutex); | ||
_stop = true; | ||
} | ||
_condition.notify_all(); | ||
} | ||
|
||
} // namespace cct |