#ifndef __X10_UTIL_CONCURRENT_FUTURE_H
#define __X10_UTIL_CONCURRENT_FUTURE_H

#include <x10rt.h>


#define X10_LANG_OBJECT_H_NODEPS
#include <x10/lang/Object.h>
#undef X10_LANG_OBJECT_H_NODEPS
#define X10_LANG_FUN_0_0_H_NODEPS
#include <x10/lang/Fun_0_0.h>
#undef X10_LANG_FUN_0_0_H_NODEPS
#define X10_LANG_GLOBALREF_H_NODEPS
#include <x10/lang/GlobalRef.h>
#undef X10_LANG_GLOBALREF_H_NODEPS
namespace x10 { namespace lang { 
template<class TPMGL(T)> class GlobalRef;
} } 
namespace x10 { namespace util { namespace concurrent { 
class Latch;
} } } 
namespace x10 { namespace compiler { 
class SuppressTransientError;
} } 
namespace x10 { namespace util { 
template<class TPMGL(T)> class GrowableIndexedMemoryChunk;
} } 
namespace x10 { namespace lang { 
class Throwable;
} } 
namespace x10 { namespace lang { 
class Runtime;
} } 
namespace x10 { namespace lang { 
class VoidFun_0_0;
} } 
namespace x10 { namespace compiler { 
class AsyncClosure;
} } 
namespace x10 { namespace lang { 
class Boolean;
} } 
namespace x10 { namespace lang { 
class Place;
} } 
namespace x10 { namespace compiler { 
class Global;
} } 
namespace x10 { namespace lang { 
class Int;
} } 
namespace x10 { namespace compiler { 
class Pinned;
} } 
namespace x10 { namespace lang { 
class FinishState;
} } 
namespace x10 { namespace lang { 
class RuntimeException;
} } 
namespace x10 { namespace compiler { 
class Finalization;
} } 
namespace x10 { namespace compiler { 
class Abort;
} } 
namespace x10 { namespace compiler { 
class CompilerFlags;
} } 
namespace x10 { namespace util { namespace concurrent { 

template<class TPMGL(T)> class Future;
template <> class Future<void>;
template<class TPMGL(T)> class Future : public x10::lang::Object   {
    public:
    RTT_H_DECLS_CLASS
    
    static x10aux::itable_entry _itables[3];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    static typename x10::lang::Fun_0_0<TPMGL(T)>::template itable<x10::util::concurrent::Future<TPMGL(T)> > _itable_0;
    
    static x10::lang::Any::itable<x10::util::concurrent::Future<TPMGL(T)> > _itable_1;
    
    x10::lang::GlobalRef<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > >
      FMGL(root);
    
    x10aux::ref<x10::util::concurrent::Latch> FMGL(latch);
    
    x10aux::ref<x10::util::GrowableIndexedMemoryChunk<x10aux::ref<x10::lang::Throwable> > >
      FMGL(exception);
    
    x10aux::ref<x10::util::GrowableIndexedMemoryChunk<TPMGL(T)> >
      FMGL(result);
    
    x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > FMGL(eval);
    
    void _constructor(x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval);
    
    static x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > _make(
             x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval);
    
    virtual x10_boolean forced();
    virtual TPMGL(T) __apply();
    virtual TPMGL(T) force();
    TPMGL(T) forceLocal();
    virtual void run();
    virtual x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >
      x10__util__concurrent__Future____x10__util__concurrent__Future__this(
      );
    void __fieldInitializers50808();
    
    // Serialization
    public: static const x10aux::serialization_id_t _serialization_id;
    
    public: virtual x10aux::serialization_id_t _get_serialization_id() {
         return _serialization_id;
    }
    
    public: virtual void _serialize_body(x10aux::serialization_buffer& buf);
    
    public: static x10aux::ref<x10::lang::Reference> _deserializer(x10aux::deserialization_buffer& buf);
    
    public: void _deserialize_body(x10aux::deserialization_buffer& buf);
    
};
template <> class Future<void> : public x10::lang::Object {
    public:
    static x10aux::RuntimeType rtt;
    static const x10aux::RuntimeType* getRTT() { return & rtt; }
    template<class TPMGL(T)> static x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >
      make(x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval);
    
    
};

} } } 
#endif // X10_UTIL_CONCURRENT_FUTURE_H

namespace x10 { namespace util { namespace concurrent { 
template<class TPMGL(T)> class Future;
} } } 

#ifndef X10_UTIL_CONCURRENT_FUTURE_H_NODEPS
#define X10_UTIL_CONCURRENT_FUTURE_H_NODEPS
#include <x10/lang/Object.h>
#include <x10/lang/Fun_0_0.h>
#include <x10/lang/GlobalRef.h>
#include <x10/util/concurrent/Latch.h>
#include <x10/compiler/SuppressTransientError.h>
#include <x10/util/GrowableIndexedMemoryChunk.h>
#include <x10/lang/Throwable.h>
#include <x10/lang/Runtime.h>
#include <x10/lang/VoidFun_0_0.h>
#include <x10/compiler/AsyncClosure.h>
#include <x10/lang/Boolean.h>
#include <x10/lang/Place.h>
#include <x10/compiler/Global.h>
#include <x10/lang/Int.h>
#include <x10/compiler/Pinned.h>
#include <x10/lang/FinishState.h>
#include <x10/lang/RuntimeException.h>
#include <x10/compiler/Finalization.h>
#include <x10/compiler/Abort.h>
#include <x10/compiler/CompilerFlags.h>
#ifndef X10_UTIL_CONCURRENT_FUTURE_H_GENERICS
#define X10_UTIL_CONCURRENT_FUTURE_H_GENERICS
#endif // X10_UTIL_CONCURRENT_FUTURE_H_GENERICS
#ifndef X10_UTIL_CONCURRENT_FUTURE_H_IMPLEMENTATION
#define X10_UTIL_CONCURRENT_FUTURE_H_IMPLEMENTATION
#include <x10/util/concurrent/Future.h>

#ifndef X10_UTIL_CONCURRENT_FUTURE__CLOSURE__1_CLOSURE
#define X10_UTIL_CONCURRENT_FUTURE__CLOSURE__1_CLOSURE
#include <x10/lang/Closure.h>
#include <x10/lang/Fun_0_0.h>
template<class TPMGL(T)> class x10_util_concurrent_Future__closure__1 : public x10::lang::Closure {
    public:
    
    static typename x10::lang::Fun_0_0<x10_boolean>::template itable <x10_util_concurrent_Future__closure__1<TPMGL(T) > > _itable;
    static x10aux::itable_entry _itables[2];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    // closure body
    x10_boolean __apply() {
        
        //#line 62 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
        return x10aux::nullCheck((saved_this->FMGL(root))->__apply())->FMGL(latch)->__apply();
        
    }
    
    // captured environment
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > saved_this;
    
    x10aux::serialization_id_t _get_serialization_id() {
        return _serialization_id;
    }
    
    void _serialize_body(x10aux::serialization_buffer &buf) {
        buf.write(this->saved_this);
    }
    
    template<class __T> static x10aux::ref<__T> _deserialize(x10aux::deserialization_buffer &buf) {
        x10_util_concurrent_Future__closure__1<TPMGL(T) >* storage = x10aux::alloc<x10_util_concurrent_Future__closure__1<TPMGL(T) > >();
        buf.record_reference(x10aux::ref<x10_util_concurrent_Future__closure__1<TPMGL(T) > >(storage));
        x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > that_saved_this = buf.read<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > >();
        x10aux::ref<x10_util_concurrent_Future__closure__1<TPMGL(T) > > this_ = new (storage) x10_util_concurrent_Future__closure__1<TPMGL(T) >(that_saved_this);
        return this_;
    }
    
    x10_util_concurrent_Future__closure__1(x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > saved_this) : saved_this(saved_this) { }
    
    static const x10aux::serialization_id_t _serialization_id;
    
    static const x10aux::RuntimeType* getRTT() { return x10aux::getRTT<x10::lang::Fun_0_0<x10_boolean> >(); }
    virtual const x10aux::RuntimeType *_type() const { return x10aux::getRTT<x10::lang::Fun_0_0<x10_boolean> >(); }
    
    x10aux::ref<x10::lang::String> toString() {
        return x10aux::string_utils::lit(this->toNativeString());
    }
    
    const char* toNativeString() {
        return "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10:62";
    }

};

template<class TPMGL(T)> typename x10::lang::Fun_0_0<x10_boolean>::template itable <x10_util_concurrent_Future__closure__1<TPMGL(T) > >x10_util_concurrent_Future__closure__1<TPMGL(T) >::_itable(&x10::lang::Reference::equals, &x10::lang::Closure::hashCode, &x10_util_concurrent_Future__closure__1<TPMGL(T) >::__apply, &x10_util_concurrent_Future__closure__1<TPMGL(T) >::toString, &x10::lang::Closure::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10_util_concurrent_Future__closure__1<TPMGL(T) >::_itables[2] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Fun_0_0<x10_boolean> >, &x10_util_concurrent_Future__closure__1<TPMGL(T) >::_itable),x10aux::itable_entry(NULL, NULL)};

template<class TPMGL(T)> const x10aux::serialization_id_t x10_util_concurrent_Future__closure__1<TPMGL(T) >::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10_util_concurrent_Future__closure__1<TPMGL(T) >::template _deserialize<x10::lang::Reference>,x10aux::CLOSURE_KIND_NOT_ASYNC);

#endif // X10_UTIL_CONCURRENT_FUTURE__CLOSURE__1_CLOSURE
#ifndef X10_UTIL_CONCURRENT_FUTURE__CLOSURE__2_CLOSURE
#define X10_UTIL_CONCURRENT_FUTURE__CLOSURE__2_CLOSURE
#include <x10/lang/Closure.h>
#include <x10/lang/Fun_0_0.h>
template<class TPMGL(T)> class x10_util_concurrent_Future__closure__2 : public x10::lang::Closure {
    public:
    
    static typename x10::lang::Fun_0_0<TPMGL(T)>::template itable <x10_util_concurrent_Future__closure__2<TPMGL(T) > > _itable;
    static x10aux::itable_entry _itables[2];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    // closure body
    TPMGL(T) __apply() {
        
        //#line 70 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
        return x10aux::nullCheck((saved_this->FMGL(root))->__apply())->forceLocal();
        
    }
    
    // captured environment
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > saved_this;
    
    x10aux::serialization_id_t _get_serialization_id() {
        return _serialization_id;
    }
    
    void _serialize_body(x10aux::serialization_buffer &buf) {
        buf.write(this->saved_this);
    }
    
    template<class __T> static x10aux::ref<__T> _deserialize(x10aux::deserialization_buffer &buf) {
        x10_util_concurrent_Future__closure__2<TPMGL(T) >* storage = x10aux::alloc<x10_util_concurrent_Future__closure__2<TPMGL(T) > >();
        buf.record_reference(x10aux::ref<x10_util_concurrent_Future__closure__2<TPMGL(T) > >(storage));
        x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > that_saved_this = buf.read<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > >();
        x10aux::ref<x10_util_concurrent_Future__closure__2<TPMGL(T) > > this_ = new (storage) x10_util_concurrent_Future__closure__2<TPMGL(T) >(that_saved_this);
        return this_;
    }
    
    x10_util_concurrent_Future__closure__2(x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > saved_this) : saved_this(saved_this) { }
    
    static const x10aux::serialization_id_t _serialization_id;
    
    static const x10aux::RuntimeType* getRTT() { return x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >(); }
    virtual const x10aux::RuntimeType *_type() const { return x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >(); }
    
    x10aux::ref<x10::lang::String> toString() {
        return x10aux::string_utils::lit(this->toNativeString());
    }
    
    const char* toNativeString() {
        return "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10:70";
    }

};

template<class TPMGL(T)> typename x10::lang::Fun_0_0<TPMGL(T)>::template itable <x10_util_concurrent_Future__closure__2<TPMGL(T) > >x10_util_concurrent_Future__closure__2<TPMGL(T) >::_itable(&x10::lang::Reference::equals, &x10::lang::Closure::hashCode, &x10_util_concurrent_Future__closure__2<TPMGL(T) >::__apply, &x10_util_concurrent_Future__closure__2<TPMGL(T) >::toString, &x10::lang::Closure::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10_util_concurrent_Future__closure__2<TPMGL(T) >::_itables[2] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >, &x10_util_concurrent_Future__closure__2<TPMGL(T) >::_itable),x10aux::itable_entry(NULL, NULL)};

template<class TPMGL(T)> const x10aux::serialization_id_t x10_util_concurrent_Future__closure__2<TPMGL(T) >::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10_util_concurrent_Future__closure__2<TPMGL(T) >::template _deserialize<x10::lang::Reference>,x10aux::CLOSURE_KIND_NOT_ASYNC);

#endif // X10_UTIL_CONCURRENT_FUTURE__CLOSURE__2_CLOSURE
#ifndef X10_UTIL_CONCURRENT_FUTURE__CLOSURE__3_CLOSURE
#define X10_UTIL_CONCURRENT_FUTURE__CLOSURE__3_CLOSURE
#include <x10/lang/Closure.h>
#include <x10/lang/VoidFun_0_0.h>
template<class TPMGL(T)> class x10_util_concurrent_Future__closure__3 : public x10::lang::Closure {
    public:
    
    static typename x10::lang::VoidFun_0_0::template itable <x10_util_concurrent_Future__closure__3<TPMGL(T) > > _itable;
    static x10aux::itable_entry _itables[2];
    
    virtual x10aux::itable_entry* _getITables() { return _itables; }
    
    // closure body
    void __apply() {
        
        //#line 50 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
        f->run();
    }
    
    // captured environment
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > f;
    
    x10aux::serialization_id_t _get_serialization_id() {
        return _serialization_id;
    }
    
    void _serialize_body(x10aux::serialization_buffer &buf) {
        buf.write(this->f);
    }
    
    template<class __T> static x10aux::ref<__T> _deserialize(x10aux::deserialization_buffer &buf) {
        x10_util_concurrent_Future__closure__3<TPMGL(T) >* storage = x10aux::alloc<x10_util_concurrent_Future__closure__3<TPMGL(T) > >();
        buf.record_reference(x10aux::ref<x10_util_concurrent_Future__closure__3<TPMGL(T) > >(storage));
        x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > that_f = buf.read<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > >();
        x10aux::ref<x10_util_concurrent_Future__closure__3<TPMGL(T) > > this_ = new (storage) x10_util_concurrent_Future__closure__3<TPMGL(T) >(that_f);
        return this_;
    }
    
    x10_util_concurrent_Future__closure__3(x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > f) : f(f) { }
    
    static const x10aux::serialization_id_t _serialization_id;
    
    static const x10aux::RuntimeType* getRTT() { return x10aux::getRTT<x10::lang::VoidFun_0_0>(); }
    virtual const x10aux::RuntimeType *_type() const { return x10aux::getRTT<x10::lang::VoidFun_0_0>(); }
    
    x10aux::ref<x10::lang::String> toString() {
        return x10aux::string_utils::lit(this->toNativeString());
    }
    
    const char* toNativeString() {
        return "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10:50";
    }

};

template<class TPMGL(T)> typename x10::lang::VoidFun_0_0::template itable <x10_util_concurrent_Future__closure__3<TPMGL(T) > >x10_util_concurrent_Future__closure__3<TPMGL(T) >::_itable(&x10::lang::Reference::equals, &x10::lang::Closure::hashCode, &x10_util_concurrent_Future__closure__3<TPMGL(T) >::__apply, &x10_util_concurrent_Future__closure__3<TPMGL(T) >::toString, &x10::lang::Closure::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10_util_concurrent_Future__closure__3<TPMGL(T) >::_itables[2] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::VoidFun_0_0>, &x10_util_concurrent_Future__closure__3<TPMGL(T) >::_itable),x10aux::itable_entry(NULL, NULL)};

template<class TPMGL(T)> const x10aux::serialization_id_t x10_util_concurrent_Future__closure__3<TPMGL(T) >::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10_util_concurrent_Future__closure__3<TPMGL(T) >::template _deserialize<x10::lang::Reference>,x10aux::CLOSURE_KIND_SIMPLE_ASYNC);

#endif // X10_UTIL_CONCURRENT_FUTURE__CLOSURE__3_CLOSURE
template<class TPMGL(T)> typename x10::lang::Fun_0_0<TPMGL(T)>::template itable<x10::util::concurrent::Future<TPMGL(T)> >  x10::util::concurrent::Future<TPMGL(T)>::_itable_0(&x10::util::concurrent::Future<TPMGL(T)>::equals, &x10::util::concurrent::Future<TPMGL(T)>::hashCode, &x10::util::concurrent::Future<TPMGL(T)>::__apply, &x10::util::concurrent::Future<TPMGL(T)>::toString, &x10::util::concurrent::Future<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10::lang::Any::itable<x10::util::concurrent::Future<TPMGL(T)> >  x10::util::concurrent::Future<TPMGL(T)>::_itable_1(&x10::util::concurrent::Future<TPMGL(T)>::equals, &x10::util::concurrent::Future<TPMGL(T)>::hashCode, &x10::util::concurrent::Future<TPMGL(T)>::toString, &x10::util::concurrent::Future<TPMGL(T)>::typeName);
template<class TPMGL(T)> x10aux::itable_entry x10::util::concurrent::Future<TPMGL(T)>::_itables[3] = {x10aux::itable_entry(&x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >, &_itable_0), x10aux::itable_entry(&x10aux::getRTT<x10::lang::Any>, &_itable_1), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<x10::util::concurrent::Future<TPMGL(T)> >())};

//#line 29 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10FieldDecl_c

//#line 34 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10FieldDecl_c
/**
     * Latch for signaling and wait
     */

//#line 43 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10FieldDecl_c
/**
     * Set if the activity terminated with an exception.
     * Can only be of type Error or RuntimeException
     *
     */

//#line 44 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10FieldDecl_c

//#line 45 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10FieldDecl_c

//#line 47 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c

//#line 53 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10ConstructorDecl_c
template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::_constructor(
                           x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval) {
    
    //#line 53 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10ConstructorCall_c
    (this)->::x10::lang::Object::_constructor();
    
    //#line 53 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.AssignPropertyCall_c
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->x10::util::concurrent::Future<TPMGL(T)>::__fieldInitializers50808();
    
    //#line 54 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(eval) = eval;
}
template<class TPMGL(T)> x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > x10::util::concurrent::Future<TPMGL(T)>::_make(
                           x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval)
{
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::concurrent::Future<TPMGL(T)> >(), 0, sizeof(x10::util::concurrent::Future<TPMGL(T)>))) x10::util::concurrent::Future<TPMGL(T)>();
    this_->_constructor(eval);
    return this_;
}



//#line 62 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10_boolean x10::util::concurrent::Future<TPMGL(T)>::forced(
  ) {
    
    //#line 62 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return x10::lang::Runtime::template evalAt<x10_boolean >(
             x10::lang::Place::place((((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                                        FMGL(root))->location),
             x10aux::ref<x10::lang::Fun_0_0<x10_boolean> >(x10aux::ref<x10_util_concurrent_Future__closure__1<TPMGL(T) > >(new (x10aux::alloc<x10::lang::Fun_0_0<x10_boolean> >(sizeof(x10_util_concurrent_Future__closure__1<TPMGL(T)>)))x10_util_concurrent_Future__closure__1<TPMGL(T)>(this))));
    
}

//#line 63 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::concurrent::Future<TPMGL(T)>::__apply(
  ) {
    
    //#line 63 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->force();
    
}

//#line 68 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::concurrent::Future<TPMGL(T)>::force(
  ) {
    
    //#line 69 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
    x10::lang::Runtime::ensureNotInAtomic();
    
    //#line 70 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return x10::lang::Runtime::template evalAt<TPMGL(T) >(
             x10::lang::Place::place((((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                                        FMGL(root))->location),
             x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> >(x10aux::ref<x10_util_concurrent_Future__closure__2<TPMGL(T) > >(new (x10aux::alloc<x10::lang::Fun_0_0<TPMGL(T)> >(sizeof(x10_util_concurrent_Future__closure__2<TPMGL(T)>)))x10_util_concurrent_Future__closure__2<TPMGL(T)>(this))));
    
}

//#line 72 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> TPMGL(T) x10::util::concurrent::Future<TPMGL(T)>::forceLocal(
  ) {
    
    //#line 73 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(latch)->await();
    
    //#line 74 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
    if (((((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
            FMGL(exception)->x10::util::GrowableIndexedMemoryChunk<x10aux::ref<x10::lang::Throwable> >::length()) > (((x10_int)0))))
    {
        
        //#line 75 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Throw_c
        x10aux::throwException(x10aux::nullCheck(((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                                                   FMGL(exception)->x10::util::GrowableIndexedMemoryChunk<x10aux::ref<x10::lang::Throwable> >::__apply(
                                                   ((x10_int)0))));
    }
    
    //#line 77 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
             FMGL(result)->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::__apply(
             ((x10_int)0));
    
}

//#line 79 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::run(
  ) {
    
    //#line 80 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Try_c
    try {
        {
            
            //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
            x10::lang::Runtime::ensureNotInAtomic();
            
            //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10LocalDecl_c
            x10aux::ref<x10::lang::FinishState> x10____var22 =
              x10::lang::Runtime::startFinish();
            {
                
                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10LocalDecl_c
                x10aux::ref<x10::lang::Throwable> throwable50822 =
                  X10_NULL;
                
                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Try_c
                try {
                    
                    //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Try_c
                    try {
                        {
                            
                            //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                            ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                              FMGL(result)->x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::add(
                              x10::lang::Fun_0_0<TPMGL(T)>::__apply(x10aux::nullCheck(((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                                                                                        FMGL(eval))));
                        }
                    }
                    catch (x10aux::__ref& __ref__1996) {
                        x10aux::ref<x10::lang::Throwable>& __exc__ref__1996 = (x10aux::ref<x10::lang::Throwable>&)__ref__1996;
                        if (true) {
                            x10aux::ref<x10::lang::Throwable> __lowerer__var__22__ =
                              static_cast<x10aux::ref<x10::lang::Throwable> >(__exc__ref__1996);
                            {
                                
                                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                                x10::lang::Runtime::pushException(
                                  __lowerer__var__22__);
                                
                                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Throw_c
                                x10aux::throwException(x10aux::nullCheck(x10::lang::RuntimeException::_make()));
                            }
                        } else
                        throw;
                    }
                    
                    //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                    x10::compiler::Finalization::plausibleThrow();
                }
                catch (x10aux::__ref& __ref__1997) {
                    x10aux::ref<x10::lang::Throwable>& __exc__ref__1997 = (x10aux::ref<x10::lang::Throwable>&)__ref__1997;
                    if (true) {
                        x10aux::ref<x10::lang::Throwable> formal50823 =
                          static_cast<x10aux::ref<x10::lang::Throwable> >(__exc__ref__1997);
                        {
                            
                            //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10LocalAssign_c
                            throwable50822 = formal50823;
                        }
                    } else
                    throw;
                }
                
                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
                if ((!x10aux::struct_equals(X10_NULL, throwable50822)))
                {
                    
                    //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
                    if (x10aux::instanceof<x10aux::ref<x10::compiler::Abort> >(throwable50822))
                    {
                        
                        //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Throw_c
                        x10aux::throwException(x10aux::nullCheck(throwable50822));
                    }
                    
                }
                
                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
                if (true) {
                    
                    //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                    x10::lang::Runtime::stopFinish(x10____var22);
                }
                
                //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
                if ((!x10aux::struct_equals(X10_NULL, throwable50822)))
                {
                    
                    //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10If_c
                    if (!(x10aux::instanceof<x10aux::ref<x10::compiler::Finalization> >(throwable50822)))
                    {
                        
                        //#line 81 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": polyglot.ast.Throw_c
                        x10aux::throwException(x10aux::nullCheck(throwable50822));
                    }
                    
                }
                
            }
        }
        
        //#line 82 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
        ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
          FMGL(latch)->release();
    }
    catch (x10aux::__ref& __ref__1998) {
        x10aux::ref<x10::lang::Throwable>& __exc__ref__1998 = (x10aux::ref<x10::lang::Throwable>&)__ref__1998;
        if (true) {
            x10aux::ref<x10::lang::Throwable> t = static_cast<x10aux::ref<x10::lang::Throwable> >(__exc__ref__1998);
            {
                
                //#line 84 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                  FMGL(exception)->x10::util::GrowableIndexedMemoryChunk<x10aux::ref<x10::lang::Throwable> >::add(
                  t);
                
                //#line 85 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
                ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
                  FMGL(latch)->release();
            }
        } else
        throw;
    }
}

//#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >
  x10::util::concurrent::Future<TPMGL(T)>::x10__util__concurrent__Future____x10__util__concurrent__Future__this(
  ) {
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this);
    
}

//#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10MethodDecl_c
template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::__fieldInitializers50808(
  ) {
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(root) = x10::lang::GlobalRef<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > >::_make(((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this));
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(latch) = x10::util::concurrent::Latch::_make();
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(exception) = x10::util::GrowableIndexedMemoryChunk<x10aux::ref<x10::lang::Throwable> >::_make();
    
    //#line 28 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10FieldAssign_c
    ((x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >)this)->
      FMGL(result) = x10::util::GrowableIndexedMemoryChunk<TPMGL(T)>::_make();
}
template<class TPMGL(T)> const x10aux::serialization_id_t x10::util::concurrent::Future<TPMGL(T)>::_serialization_id = 
    x10aux::DeserializationDispatcher::addDeserializer(x10::util::concurrent::Future<TPMGL(T)>::_deserializer, x10aux::CLOSURE_KIND_NOT_ASYNC);

template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::_serialize_body(x10aux::serialization_buffer& buf) {
    x10::lang::Object::_serialize_body(buf);
    buf.write(this->FMGL(root));
    
}

template<class TPMGL(T)> x10aux::ref<x10::lang::Reference> x10::util::concurrent::Future<TPMGL(T)>::_deserializer(x10aux::deserialization_buffer& buf) {
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > this_ = new (memset(x10aux::alloc<x10::util::concurrent::Future<TPMGL(T)> >(), 0, sizeof(x10::util::concurrent::Future<TPMGL(T)>))) x10::util::concurrent::Future<TPMGL(T)>();
    buf.record_reference(this_);
    this_->_deserialize_body(buf);
    return this_;
}

template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::_deserialize_body(x10aux::deserialization_buffer& buf) {
    x10::lang::Object::_deserialize_body(buf);
    FMGL(root) = buf.read<x10::lang::GlobalRef<x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > > >();
    
}

template<class TPMGL(T)> x10aux::RuntimeType x10::util::concurrent::Future<TPMGL(T)>::rtt;
template<class TPMGL(T)> void x10::util::concurrent::Future<TPMGL(T)>::_initRTT() {
    const x10aux::RuntimeType *canonical = x10aux::getRTT<x10::util::concurrent::Future<void> >();
    if (rtt.initStageOne(canonical)) return;
    const x10aux::RuntimeType* parents[2] = { x10aux::getRTT<x10::lang::Object>(), x10aux::getRTT<x10::lang::Fun_0_0<TPMGL(T)> >()};
    const x10aux::RuntimeType* params[1] = { x10aux::getRTT<TPMGL(T)>()};
    x10aux::RuntimeType::Variance variances[1] = { x10aux::RuntimeType::invariant};
    const char *baseName = "x10.util.concurrent.Future";
    rtt.initStageTwo(baseName, x10aux::RuntimeType::class_kind, 2, parents, 1, params, variances);
}
template<class TPMGL(T)> x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> >
  x10::util::concurrent::Future<void>::make(x10aux::ref<x10::lang::Fun_0_0<TPMGL(T)> > eval)
{
    
    //#line 48 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
    x10::lang::Runtime::ensureNotInAtomic();
    
    //#line 49 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10LocalDecl_c
    x10aux::ref<x10::util::concurrent::Future<TPMGL(T)> > f =
      x10::util::concurrent::Future<TPMGL(T)>::_make(eval);
    
    //#line 50 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": Eval of x10.ast.X10Call_c
    x10::lang::Runtime::runAsync(x10aux::ref<x10::lang::VoidFun_0_0>(x10aux::ref<x10_util_concurrent_Future__closure__3<TPMGL(T) > >(new (x10aux::alloc<x10::lang::VoidFun_0_0>(sizeof(x10_util_concurrent_Future__closure__3<TPMGL(T)>)))x10_util_concurrent_Future__closure__3<TPMGL(T)>(f))));
    
    //#line 51 "/wrkdirs/usr/ports/lang/x10/work/x10.runtime/src-x10/x10/util/concurrent/Future.x10": x10.ast.X10Return_c
    return f;
    
}
#endif // X10_UTIL_CONCURRENT_FUTURE_H_IMPLEMENTATION
#endif // __X10_UTIL_CONCURRENT_FUTURE_H_NODEPS
