1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Merge pull request #681 from majestrate/fix-locking

fix locking types
This commit is contained in:
Jeff 2019-07-02 20:13:19 -04:00 committed by GitHub
commit b1fa0135ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 110 deletions

View file

@ -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);
};

View file

@ -24,7 +24,7 @@
#include <util/mem.hpp>
#include <util/status.hpp>
#include <util/str.hpp>
#include <util/threadpool.hpp>
#include <util/threadpool.h>
#include <functional>
#include <list>

View file

@ -1,6 +1,7 @@
#include <util/logger.hpp>
#include <util/threadpool.hpp>
#include <util/time.hpp>
#include <util/threadpool.h>
#include <util/thread_pool.hpp>
#include <cstring>
#include <functional>

View file

@ -1,10 +1,8 @@
#ifndef LLARP_THREADPOOL_H
#define LLARP_THREADPOOL_H
#include <util/threading.hpp>
#include <util/threadpool.hpp>
#include <util/queue.hpp>
#include <util/thread_pool.hpp>
#include <absl/base/thread_annotations.h>
#include <memory>
#include <queue>

View file

@ -1,101 +0,0 @@
#ifndef LLARP_THREADPOOL_HPP
#define LLARP_THREADPOOL_HPP
#include <util/thread_pool.hpp>
#include <util/threading.hpp>
#include <util/threadpool.h>
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