From ec1910b8cad2e6d355524876ed14c43005ff08f9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 2 Jul 2019 15:00:24 -0400 Subject: [PATCH] remove threadpool.hpp make link layer not use null lock and null mutex --- llarp/link/server.hpp | 8 +-- llarp/router/router.hpp | 2 +- llarp/util/threadpool.cpp | 3 +- llarp/util/threadpool.h | 4 +- llarp/util/threadpool.hpp | 101 -------------------------------------- 5 files changed, 8 insertions(+), 110 deletions(-) delete mode 100644 llarp/util/threadpool.hpp diff --git a/llarp/link/server.hpp b/llarp/link/server.hpp index 20af6c0ae..170c9756e 100644 --- a/llarp/link/server.hpp +++ b/llarp/link/server.hpp @@ -230,8 +230,8 @@ namespace llarp const SecretKey& m_RouterEncSecret; protected: - using Lock = util::NullLock; - using Mutex = util::NullMutex; + using Lock = util::Lock; + using Mutex = util::Mutex; bool PutSession(const std::shared_ptr< ILinkSession >& s); @@ -249,9 +249,9 @@ namespace llarp std::unordered_multimap< llarp::Addr, std::shared_ptr< ILinkSession >, llarp::Addr::Hash >; - Mutex m_AuthedLinksMutex ACQUIRED_BEFORE(m_PendingMutex); + mutable Mutex m_AuthedLinksMutex ACQUIRED_BEFORE(m_PendingMutex); AuthedLinks m_AuthedLinks GUARDED_BY(m_AuthedLinksMutex); - Mutex m_PendingMutex ACQUIRED_AFTER(m_AuthedLinksMutex); + mutable Mutex m_PendingMutex ACQUIRED_AFTER(m_AuthedLinksMutex); Pending m_Pending GUARDED_BY(m_PendingMutex); }; diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 57381576d..0df026967 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include diff --git a/llarp/util/threadpool.cpp b/llarp/util/threadpool.cpp index 5072a7579..3ee0147cb 100644 --- a/llarp/util/threadpool.cpp +++ b/llarp/util/threadpool.cpp @@ -1,6 +1,7 @@ #include -#include #include +#include +#include #include #include diff --git a/llarp/util/threadpool.h b/llarp/util/threadpool.h index 396e3a35f..56f979263 100644 --- a/llarp/util/threadpool.h +++ b/llarp/util/threadpool.h @@ -1,10 +1,8 @@ #ifndef LLARP_THREADPOOL_H #define LLARP_THREADPOOL_H -#include -#include #include - +#include #include #include #include diff --git a/llarp/util/threadpool.hpp b/llarp/util/threadpool.hpp deleted file mode 100644 index 884aca287..000000000 --- a/llarp/util/threadpool.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef LLARP_THREADPOOL_HPP -#define LLARP_THREADPOOL_HPP - -#include -#include -#include - -namespace llarp -{ - namespace thread - { - using Pool = ThreadPool; - - struct IsolatedPool : public Pool - { - IsolatedPool(size_t workers, int flags) - : Pool(workers, workers * 128), m_flags(flags) - { - } - - void - Join(); - - /// isolate current thread - /// return true for success - /// return false for failure - /// set errno on fail - /// override me in subclass - virtual bool - IsolateCurrentProcess() - { - return true; - } - - // override me to do specific setups after isolation - // return true for success - virtual bool - Isolated() - { - return true; - } - - /// called when isolation failed - virtual void - Fail() - { - } - - std::thread* m_isolated = nullptr; - int m_flags; - int m_IsolatedWorkers = 0; - const char* IsolatedName = nullptr; - - virtual void - MainLoop() - { - } - }; - - struct _NetIsolatedPool : public IsolatedPool - { - _NetIsolatedPool(std::function< bool(void*, bool) > setupNet, - std::function< void(void*) > runMain, void* user); - - /// implement me per platform - virtual bool - IsolateNetwork() = 0; - - bool - IsolateCurrentProcess() - { - return IsolateNetwork(); - } - - bool - Isolated() - { - return m_NetSetup(m_user, true); - } - - void - Fail() - { - m_NetSetup(m_user, false); - } - - void - MainLoop() - { - m_RunMain(m_user); - } - - std::function< bool(void*, bool) > m_NetSetup; - std::function< void(void*) > m_RunMain; - void* m_user; - }; - - } // namespace thread -} // namespace llarp - -#endif