Updates from BitShares FC #22
4 changed files with 5 additions and 10 deletions
|
|
@ -96,7 +96,7 @@ namespace fc {
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
auto do_parallel( Functor&& f, const char* desc FC_TASK_NAME_DEFAULT_ARG ) -> fc::future<decltype(f())> {
|
auto do_parallel( Functor&& f, const char* desc FC_TASK_NAME_DEFAULT_ARG ) -> fc::future<decltype(f())> {
|
||||||
typedef decltype(f()) Result;
|
typedef decltype(f()) Result;
|
||||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
typedef typename std::remove_const_t< std::remove_reference_t<Functor> > FunctorType;
|
||||||
typename task<Result,sizeof(FunctorType)>::ptr tsk =
|
typename task<Result,sizeof(FunctorType)>::ptr tsk =
|
||||||
task<Result,sizeof(FunctorType)>::create( std::forward<Functor>(f), desc );
|
task<Result,sizeof(FunctorType)>::create( std::forward<Functor>(f), desc );
|
||||||
tsk->retain(); // HERE BE DRAFONS
|
tsk->retain(); // HERE BE DRAFONS
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <fc/thread/future.hpp>
|
#include <fc/thread/future.hpp>
|
||||||
#include <fc/thread/priority.hpp>
|
#include <fc/thread/priority.hpp>
|
||||||
#include <fc/fwd.hpp>
|
#include <fc/fwd.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
struct context;
|
struct context;
|
||||||
|
|
@ -127,7 +128,7 @@ namespace fc {
|
||||||
private:
|
private:
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
task( Functor&& f, const char* desc ):promise_base(desc), task_base(&_functor), promise<R>(desc) {
|
task( Functor&& f, const char* desc ):promise_base(desc), task_base(&_functor), promise<R>(desc) {
|
||||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
typedef typename std::remove_const_t< std::remove_reference_t<Functor> > FunctorType;
|
||||||
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
||||||
new ((char*)&_functor) FunctorType( std::forward<Functor>(f) );
|
new ((char*)&_functor) FunctorType( std::forward<Functor>(f) );
|
||||||
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
||||||
|
|
@ -155,7 +156,7 @@ namespace fc {
|
||||||
private:
|
private:
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
task( Functor&& f, const char* desc ):promise_base(desc), task_base(&_functor), promise<void>(desc) {
|
task( Functor&& f, const char* desc ):promise_base(desc), task_base(&_functor), promise<void>(desc) {
|
||||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
typedef typename std::remove_const_t< std::remove_reference_t<Functor> > FunctorType;
|
||||||
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
||||||
new ((char*)&_functor) FunctorType( std::forward<Functor>(f) );
|
new ((char*)&_functor) FunctorType( std::forward<Functor>(f) );
|
||||||
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ namespace fc {
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
auto async( Functor&& f, const char* desc FC_TASK_NAME_DEFAULT_ARG, priority prio = priority()) -> fc::future<decltype(f())> {
|
auto async( Functor&& f, const char* desc FC_TASK_NAME_DEFAULT_ARG, priority prio = priority()) -> fc::future<decltype(f())> {
|
||||||
typedef decltype(f()) Result;
|
typedef decltype(f()) Result;
|
||||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
typedef typename std::remove_const_t< std::remove_reference_t<Functor> > FunctorType;
|
||||||
typename task<Result,sizeof(FunctorType)>::ptr tsk =
|
typename task<Result,sizeof(FunctorType)>::ptr tsk =
|
||||||
task<Result,sizeof(FunctorType)>::create( std::forward<Functor>(f), desc );
|
task<Result,sizeof(FunctorType)>::create( std::forward<Functor>(f), desc );
|
||||||
tsk->retain(); // HERE BE DRAFONS
|
tsk->retain(); // HERE BE DRAFONS
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,6 @@ namespace fc {
|
||||||
using std::size_t;
|
using std::size_t;
|
||||||
typedef decltype(nullptr) nullptr_t;
|
typedef decltype(nullptr) nullptr_t;
|
||||||
|
|
||||||
template<typename T> struct deduce { typedef T type; };
|
|
||||||
template<typename T> struct deduce<T&> { typedef T type; };
|
|
||||||
template<typename T> struct deduce<const T&> { typedef T type; };
|
|
||||||
template<typename T> struct deduce<T&&> { typedef T type; };
|
|
||||||
template<typename T> struct deduce<const T&&>{ typedef T type; };
|
|
||||||
|
|
||||||
struct true_type { enum _value { value = 1 }; };
|
struct true_type { enum _value { value = 1 }; };
|
||||||
struct false_type { enum _value { value = 0 }; };
|
struct false_type { enum _value { value = 0 }; };
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue