void Table_GENERAL_OPTIONS::ModifyDisplayAbsoluteTimeColumns(sqlite3 * db) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); std::string sqlAdd("UPDATE GENERAL_OPTIONS SET "); sqlAdd += GENERAL_OPTIONS__DISPLAY_ABSOLUTE_TIME_COLUMNS; sqlAdd += "="; sqlAdd += boost::lexical_cast<std::string>(display_absolute_time_columns ? 1 : 0); sqlite3_stmt * stmt = NULL; sqlite3_prepare_v2(db, sqlAdd.c_str(), sqlAdd.size() + 1, &stmt, NULL); if (stmt == NULL) { return; } sqlite3_step(stmt); if (stmt) { sqlite3_finalize(stmt); stmt = nullptr; } }
void Table_GENERAL_OPTIONS::ModifyConsolidateRows(sqlite3 * db) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); std::string sqlAdd("UPDATE GENERAL_OPTIONS SET "); sqlAdd += GENERAL_OPTIONS__CONSOLIDATE_ROWS; sqlAdd += "="; sqlAdd += boost::lexical_cast<std::string>(consolidate_rows ? 1 : 0); sqlite3_stmt * stmt = NULL; sqlite3_prepare_v2(db, sqlAdd.c_str(), sqlAdd.size() + 1, &stmt, NULL); if (stmt == NULL) { return; } sqlite3_step(stmt); if (stmt) { sqlite3_finalize(stmt); stmt = nullptr; } }
void Table_GENERAL_OPTIONS::ModifyRandomSamplingCount(sqlite3 * db) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); std::string sqlAdd("UPDATE GENERAL_OPTIONS SET "); sqlAdd += GENERAL_OPTIONS__RANDOM_SAMPLING_COUNT_PER_STAGE; sqlAdd += "="; sqlAdd += boost::lexical_cast<std::string>(random_sampling_count_per_stage); sqlite3_stmt * stmt = NULL; sqlite3_prepare_v2(db, sqlAdd.c_str(), sqlAdd.size() + 1, &stmt, NULL); if (stmt == NULL) { return; } sqlite3_step(stmt); if (stmt) { sqlite3_finalize(stmt); stmt = nullptr; } }
bool Table_GENERAL_OPTIONS::UpdateDoRandomSampling(sqlite3 * db, OutputModel & output_model_, InputModel & input_model_, DataChangeMessage & change_message) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); //Executor theExecutor(db); std::for_each(change_message.changes.cbegin(), change_message.changes.cend(), [&db, &input_model_, this](DataChange const & change) { switch (change.change_type) { case DATA_CHANGE_TYPE::DATA_CHANGE_TYPE__OUTPUT_MODEL__DO_RANDOM_SAMPLING_CHANGE: { switch (change.change_intention) { case DATA_CHANGE_INTENTION__ADD: case DATA_CHANGE_INTENTION__REMOVE: { // Should never receive this. } break; case DATA_CHANGE_INTENTION__UPDATE: { DataChangePacket_bool * packet = static_cast<DataChangePacket_bool *>(change.getPacket()); if (packet) { do_random_sampling = packet->getValue(); ModifyDoRandomSampling(db); } else { // error condition ... todo } } case DATA_CHANGE_INTENTION__RESET_ALL: { // Ditto above. } break; } } break; } }); //theExecutor.success(); //return theExecutor.succeeded(); return true; }
Thread_Pool::~Thread_Pool() { queue.clear(); std::unique_lock<std::mutex> pool_lock (pool_mtx); std::unique_lock<std::mutex> data_lock (data_mtx); for (auto &th : pool) { auto locked = th.second.lock(); if (locked != nullptr) { th.first.detach(); *locked = static_cast<Work_State_Overlay> ( RaptorQ__v1::Work_State::ABORT_COMPUTATION); } } cond.notify_all(); // unlock threads stuck on condition_wait data_lock.unlock(); pool_lock.unlock(); pool.clear(); }
std::tuple<bool, std::int64_t, bool, bool> Table_GENERAL_OPTIONS::getKadSamplerInfo(sqlite3 * db) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); sqlite3_stmt * stmt = NULL; std::string sql("SELECT * FROM GENERAL_OPTIONS"); sqlite3_prepare_v2(db, sql.c_str(), sql.size() + 1, &stmt, NULL); if (stmt == NULL) { std::tuple<bool, std::int64_t, bool, bool> ret(false, 1, true, false); return ret; } int step_result = 0; if ((step_result = sqlite3_step(stmt)) == SQLITE_ROW) { // ****************************************************************************************// // Use codes as foreign keys, not NewGeneUUID's, so that this output model can be shared with others // ****************************************************************************************// do_random_sampling = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__DO_RANDOM_SAMPLING) != 0); random_sampling_count_per_stage = sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__RANDOM_SAMPLING_COUNT_PER_STAGE); consolidate_rows = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__CONSOLIDATE_ROWS) != 0); display_absolute_time_columns = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__DISPLAY_ABSOLUTE_TIME_COLUMNS) != 0); } if (stmt) { sqlite3_finalize(stmt); stmt = nullptr; } // workaround compiler bug that will not allow temporary tuple with bool param std::tuple<bool, std::int64_t, bool, bool> ret(do_random_sampling, random_sampling_count_per_stage, consolidate_rows, display_absolute_time_columns); return ret; }
void Table_GENERAL_OPTIONS::Load(sqlite3 * db, OutputModel * output_model_, InputModel * input_model_) { std::lock_guard<std::recursive_mutex> data_lock(data_mutex); sqlite3_stmt * stmt = NULL; std::string sql("SELECT * FROM GENERAL_OPTIONS"); sqlite3_prepare_v2(db, sql.c_str(), sql.size() + 1, &stmt, NULL); if (stmt == NULL) { return; } int step_result = 0; if ((step_result = sqlite3_step(stmt)) == SQLITE_ROW) { // ****************************************************************************************// // Use codes as foreign keys, not NewGeneUUID's, so that this output model can be shared with others // ****************************************************************************************// do_random_sampling = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__DO_RANDOM_SAMPLING) != 0); random_sampling_count_per_stage = sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__RANDOM_SAMPLING_COUNT_PER_STAGE); consolidate_rows = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__CONSOLIDATE_ROWS) != 0); display_absolute_time_columns = (sqlite3_column_int(stmt, INDEX__GENERAL_OPTIONS__DISPLAY_ABSOLUTE_TIME_COLUMNS) != 0); } if (stmt) { sqlite3_finalize(stmt); stmt = nullptr; } }