diff options
Diffstat (limited to 'src/common/Utilities')
| -rw-r--r-- | src/common/Utilities/Containers.h | 22 | ||||
| -rw-r--r-- | src/common/Utilities/StartProcess.cpp | 12 | ||||
| -rw-r--r-- | src/common/Utilities/Timer.h | 4 |
3 files changed, 26 insertions, 12 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index 7c889068011..5edb245fd87 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -31,9 +31,9 @@ namespace Trinity namespace Containers { template<class T> - void RandomResizeList(std::list<T> &list, uint32 size) + void RandomResizeList(std::list<T>& list, uint32 size) { - size_t list_size = list.size(); + uint32 list_size = uint32(list.size()); while (list_size > size) { @@ -56,7 +56,7 @@ namespace Trinity if (size) RandomResizeList(listCopy, size); - list = listCopy; + list = std::move(listCopy); } /* @@ -68,7 +68,7 @@ namespace Trinity typename C::value_type const& SelectRandomContainerElement(C const& container) { typename C::const_iterator it = container.begin(); - std::advance(it, urand(0, container.size() - 1)); + std::advance(it, urand(0, uint32(container.size()) - 1)); return *it; } @@ -118,6 +118,19 @@ namespace Trinity } /** + * @fn void Trinity::Containers::RandomShuffle(C& container) + * + * @brief Reorder the elements of the container randomly. + * + * @param container Container to reorder + */ + template <class C> + void RandomShuffle(C& container) + { + std::shuffle(container.begin(), container.end(), SFMTEngine::Instance()); + } + + /** * @fn bool Trinity::Containers::Intersects(Iterator first1, Iterator last1, Iterator first2, Iterator last2) * * @brief Checks if two SORTED containers have a common element @@ -157,7 +170,6 @@ namespace Trinity ++itr; } } - } //! namespace Containers } diff --git a/src/common/Utilities/StartProcess.cpp b/src/common/Utilities/StartProcess.cpp index c47c02bbe87..f35c6de3b5c 100644 --- a/src/common/Utilities/StartProcess.cpp +++ b/src/common/Utilities/StartProcess.cpp @@ -78,7 +78,7 @@ static int CreateChildProcess(T waiter, std::string const& executable, if (!secure) { - TC_LOG_TRACE(logger.c_str(), "Starting process \"%s\" with arguments: \"%s\".", + TC_LOG_TRACE(logger, "Starting process \"%s\" with arguments: \"%s\".", executable.c_str(), boost::algorithm::join(args, " ").c_str()); } @@ -92,6 +92,7 @@ static int CreateChildProcess(T waiter, std::string const& executable, // With binding stdin return execute(run_exe(boost::filesystem::absolute(executable)), set_args(args), + inherit_env(), bind_stdin(*inputSource), bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)), bind_stderr(file_descriptor_sink(errPipe.sink, close_handle))); @@ -101,6 +102,7 @@ static int CreateChildProcess(T waiter, std::string const& executable, // Without binding stdin return execute(run_exe(boost::filesystem::absolute(executable)), set_args(args), + inherit_env(), bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)), bind_stderr(file_descriptor_sink(errPipe.sink, close_handle))); } @@ -111,12 +113,12 @@ static int CreateChildProcess(T waiter, std::string const& executable, auto outInfo = MakeTCLogSink([&](std::string msg) { - TC_LOG_INFO(logger.c_str(), "%s", msg.c_str()); + TC_LOG_INFO(logger, "%s", msg.c_str()); }); auto outError = MakeTCLogSink([&](std::string msg) { - TC_LOG_ERROR(logger.c_str(), "%s", msg.c_str()); + TC_LOG_ERROR(logger, "%s", msg.c_str()); }); copy(outFd, outInfo); @@ -128,7 +130,7 @@ static int CreateChildProcess(T waiter, std::string const& executable, if (!secure) { - TC_LOG_TRACE(logger.c_str(), ">> Process \"%s\" finished with return value %i.", + TC_LOG_TRACE(logger, ">> Process \"%s\" finished with return value %i.", executable.c_str(), result); } @@ -237,7 +239,7 @@ public: } }; -TC_COMMON_API std::shared_ptr<AsyncProcessResult> +std::shared_ptr<AsyncProcessResult> StartAsyncProcess(std::string executable, std::vector<std::string> args, std::string logger, std::string input_file, bool secure) { diff --git a/src/common/Utilities/Timer.h b/src/common/Utilities/Timer.h index cdce08caaf0..f66bb90c98e 100644 --- a/src/common/Utilities/Timer.h +++ b/src/common/Utilities/Timer.h @@ -25,9 +25,9 @@ inline uint32 getMSTime() { using namespace std::chrono; - static const system_clock::time_point ApplicationStartTime = system_clock::now(); + static const steady_clock::time_point ApplicationStartTime = steady_clock::now(); - return uint32(duration_cast<milliseconds>(system_clock::now() - ApplicationStartTime).count()); + return uint32(duration_cast<milliseconds>(steady_clock::now() - ApplicationStartTime).count()); } inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime) |
