mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 11:15:56 +00:00
Use SharedFunction in ProtectedCall
This commit is contained in:
@@ -308,11 +308,12 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n
|
||||
#include "maths/beast_uint24.h"
|
||||
#include "logging/beast_Logger.h"
|
||||
#include "diagnostic/beast_FPUFlags.h"
|
||||
#include "memory/SharedObject.h"
|
||||
#include "memory/SharedPtr.h"
|
||||
#include "functional/SharedFunction.h"
|
||||
#include "diagnostic/beast_ProtectedCall.h"
|
||||
#include "containers/beast_AbstractFifo.h"
|
||||
#include "containers/beast_ArrayAllocationBase.h"
|
||||
#include "memory/SharedObject.h"
|
||||
#include "memory/SharedPtr.h"
|
||||
#include "containers/beast_DynamicObject.h"
|
||||
#include "containers/beast_ElementComparator.h"
|
||||
#include "maths/beast_Random.h"
|
||||
@@ -408,7 +409,6 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n
|
||||
#include "diagnostic/MeasureFunctionCallTime.h"
|
||||
|
||||
#include "functional/beast_Function.h"
|
||||
#include "functional/SharedFunction.h"
|
||||
|
||||
#include "thread/beast_DeadlineTimer.h"
|
||||
|
||||
|
||||
@@ -125,33 +125,15 @@ public:
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct Call
|
||||
typedef SharedFunction <void (void)> FunctionType;
|
||||
typedef FunctionType::Call Call;
|
||||
|
||||
template <class Function>
|
||||
void callf (Function f)
|
||||
{
|
||||
virtual void operator() () = 0;
|
||||
};
|
||||
|
||||
template <class Functor>
|
||||
struct CallType : public Call
|
||||
{
|
||||
public:
|
||||
explicit CallType (Functor f)
|
||||
: m_f (f)
|
||||
{
|
||||
}
|
||||
|
||||
void operator() ()
|
||||
{
|
||||
m_f ();
|
||||
}
|
||||
|
||||
private:
|
||||
Functor m_f;
|
||||
};
|
||||
|
||||
template <class Functor>
|
||||
void callf (Functor f)
|
||||
{
|
||||
CallType <Functor> wrapper (f);
|
||||
//CallType <Functor> wrapper (f);
|
||||
FunctionType::CallType <Function> wrapper (
|
||||
BEAST_MOVE_CAST(Function)(f));
|
||||
|
||||
call (wrapper);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,36 @@ template <typename R, class A>
|
||||
class SharedFunction <R (void), A>
|
||||
{
|
||||
public:
|
||||
class Call : public SharedObject
|
||||
{
|
||||
public:
|
||||
virtual R operator() () = 0;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
class CallType : public Call
|
||||
{
|
||||
public:
|
||||
typedef typename A:: template rebind <CallType <F> >::other Allocator;
|
||||
|
||||
CallType (BEAST_MOVE_ARG(F) f, A a = A ())
|
||||
: m_f (BEAST_MOVE_CAST(F)(f))
|
||||
, m_a (a)
|
||||
{
|
||||
}
|
||||
|
||||
R operator() ()
|
||||
{
|
||||
return m_f ();
|
||||
}
|
||||
|
||||
private:
|
||||
F m_f;
|
||||
Allocator m_a;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template <typename F>
|
||||
SharedFunction (F f, A a = A ())
|
||||
: m_ptr (::new (
|
||||
@@ -62,34 +92,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
class Call : public SharedObject
|
||||
{
|
||||
public:
|
||||
virtual R operator() () = 0;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
class CallType : public Call
|
||||
{
|
||||
public:
|
||||
typedef typename A:: template rebind <CallType <F> >::other Allocator;
|
||||
|
||||
CallType (BEAST_MOVE_ARG(F) f, A const& a)
|
||||
: m_f (BEAST_MOVE_CAST(F)(f))
|
||||
, m_a (a)
|
||||
{
|
||||
}
|
||||
|
||||
R operator() ()
|
||||
{
|
||||
return m_f ();
|
||||
}
|
||||
|
||||
private:
|
||||
F m_f;
|
||||
Allocator m_a;
|
||||
};
|
||||
|
||||
SharedPtr <Call> m_ptr;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user