mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Move pending futures count's ownership to Command.
This is to make the count global across batches created from the same Command.
This commit is contained in:
parent
960f10c370
commit
43e53c3740
3 changed files with 11 additions and 8 deletions
|
@ -113,24 +113,24 @@ namespace redis {
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
struct Batch::LocalData {
|
struct Batch::LocalData {
|
||||||
LocalData ( void ) :
|
explicit LocalData ( std::atomic_size_t& parPendingFutures ) :
|
||||||
free_cmd_slot(),
|
free_cmd_slot(),
|
||||||
futures_mutex(),
|
futures_mutex(),
|
||||||
pending_futures(0)
|
pending_futures(parPendingFutures)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::condition_variable free_cmd_slot;
|
std::condition_variable free_cmd_slot;
|
||||||
std::mutex futures_mutex;
|
std::mutex futures_mutex;
|
||||||
std::atomic_size_t pending_futures;
|
std::atomic_size_t& pending_futures;
|
||||||
};
|
};
|
||||||
|
|
||||||
Batch::Batch (Batch&&) = default;
|
Batch::Batch (Batch&&) = default;
|
||||||
|
|
||||||
Batch::Batch (AsyncConnection* parConn) :
|
Batch::Batch (AsyncConnection* parConn, std::atomic_size_t& parPendingFutures) :
|
||||||
m_futures(),
|
m_futures(),
|
||||||
m_replies(),
|
m_replies(),
|
||||||
m_local_data(new LocalData),
|
m_local_data(new LocalData(parPendingFutures)),
|
||||||
m_async_conn(parConn)
|
m_async_conn(parConn)
|
||||||
{
|
{
|
||||||
assert(m_async_conn);
|
assert(m_async_conn);
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace redis {
|
||||||
private:
|
private:
|
||||||
struct LocalData;
|
struct LocalData;
|
||||||
|
|
||||||
explicit Batch ( AsyncConnection* parConn );
|
explicit Batch ( AsyncConnection* parConn, std::atomic<std::size_t>& parPendingFutures );
|
||||||
void run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
|
void run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
|
||||||
|
|
||||||
std::vector<std::future<Reply>> m_futures;
|
std::vector<std::future<Reply>> m_futures;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
//See docs directory for info about hiredis/libev with multithreading
|
//See docs directory for info about hiredis/libev with multithreading
|
||||||
|
|
||||||
|
@ -33,12 +34,14 @@ namespace redis {
|
||||||
struct Command::LocalData {
|
struct Command::LocalData {
|
||||||
explicit LocalData (Command* parCommand, std::string&& parAddress, uint16_t parPort) :
|
explicit LocalData (Command* parCommand, std::string&& parAddress, uint16_t parPort) :
|
||||||
async_connection(std::move(parAddress), parPort),
|
async_connection(std::move(parAddress), parPort),
|
||||||
lua_scripts(parCommand)
|
lua_scripts(parCommand),
|
||||||
|
pending_futures(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncConnection async_connection;
|
AsyncConnection async_connection;
|
||||||
ScriptManager lua_scripts;
|
ScriptManager lua_scripts;
|
||||||
|
std::atomic_size_t pending_futures;
|
||||||
};
|
};
|
||||||
|
|
||||||
Command::Command (std::string&& parAddress, uint16_t parPort) :
|
Command::Command (std::string&& parAddress, uint16_t parPort) :
|
||||||
|
@ -79,7 +82,7 @@ namespace redis {
|
||||||
|
|
||||||
Batch Command::make_batch() {
|
Batch Command::make_batch() {
|
||||||
assert(is_connected());
|
assert(is_connected());
|
||||||
return Batch(&m_local_data->async_connection);
|
return Batch(&m_local_data->async_connection, m_local_data->pending_futures);
|
||||||
}
|
}
|
||||||
|
|
||||||
Script Command::make_script (const std::string &parScript) {
|
Script Command::make_script (const std::string &parScript) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue