X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8e80bb9cec2c90dd61f810fb1525932a434288eb..be1b46cc784e43cd28c5521bdcde79bd7463fb40:/projects/stargazer/traffcounter_impl.h?ds=sidebyside diff --git a/projects/stargazer/traffcounter_impl.h b/projects/stargazer/traffcounter_impl.h index 78027cb5..ed639f5c 100644 --- a/projects/stargazer/traffcounter_impl.h +++ b/projects/stargazer/traffcounter_impl.h @@ -33,10 +33,13 @@ #include #include #include +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop #include -#include - #define PROTOMAX (5) namespace STG @@ -185,7 +188,7 @@ class TraffCounterImpl : public TraffCounter { void FreeRules(); bool ReadRules(bool test = false); - static void * Run(void * data); + void Run(std::stop_token token); void DeterminateDir(const RawPacket & packet, int * dirU, // Direction for upload @@ -223,10 +226,9 @@ class TraffCounterImpl : public TraffCounter { UsersImpl * users; - bool running; bool stopped; - pthread_mutex_t mutex; - pthread_t thread; + std::mutex m_mutex; + std::jthread m_thread; std::list ipBeforeNotifiers; std::list ipAfterNotifiers; @@ -242,7 +244,7 @@ void TRF_IP_BEFORE::Notify(const uint32_t & oldValue, const uint32_t &) if (!oldValue) return; -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TraffCounterImpl::DelUser, oldValue); +EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::DelUser, oldValue); } //----------------------------------------------------------------------------- inline @@ -252,20 +254,20 @@ void TRF_IP_AFTER::Notify(const uint32_t &, const uint32_t & newValue) if (!newValue) return; -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TraffCounterImpl::AddUser, user); +EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::AddUser, user); } //----------------------------------------------------------------------------- inline void ADD_USER_NONIFIER::Notify(const UserImplPtr & user) { -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TraffCounterImpl::SetUserNotifiers, user); +EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::SetUserNotifiers, user); } //----------------------------------------------------------------------------- inline void DEL_USER_NONIFIER::Notify(const UserImplPtr & user) { -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TraffCounterImpl::UnSetUserNotifiers, user); -EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TraffCounterImpl::DelUser, user->GetCurrIP()); +EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::UnSetUserNotifiers, user); +EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::DelUser, user->GetCurrIP()); } //----------------------------------------------------------------------------- }