- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Search for |

# task.hpp

Go to the documentation of this file.

    00001 //  Copyright (c) 2005-2009 Hartmut Kaiser
    00002 //  Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net)
    00003 //  Copyright (c) 2005-2006 Stephan Hirmer (shirmer@cct.lsu.edu)
    00004 //  Copyright (c) 2007 Ole Weidner (oweidner@cct.lsu.edu)
    00005 //
    00006 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
    00007 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    00008
    00009 #ifndef SAGA_TASK_HPP
    00010 #define SAGA_TASK_HPP
    00011
    00012 // include dependent spec sections
    00013 #include <saga/saga/base.hpp>
    00014 #include <saga/saga/util.hpp>
    00015 #include <saga/saga/task_base.hpp>
    00016 #include <saga/saga/object.hpp>
    00017
    00018 #include <saga/saga/uuid.hpp>
    00019 #include <saga/saga/detail/monitorable.hpp>
    00020 #include <saga/saga/detail/hold_any.hpp>
    00021
    00022 // suppress warnings about dependent classes not being exported from the dll
    00023 #if defined(BOOST_MSVC)
    00024 #pragma warning(push)
    00025 #pragma warning(disable: 4251 4231 4275 4660)
    00026 #endif
    00027
    00029 namespace saga
    00030 {
    00033     namespace metrics
    00034     {
    00036         //  metric names for task
    00037
    00038         char const* const task_state = "task.state";
    00039
    00040     }
    00042
    00050     class SAGA_EXPORT task
    00051       : public object,
    00052         public saga::detail::monitorable<task>,
    00053         public task_base
    00054     {
    00055     private:
    00057
    00058         friend struct saga::impl::runtime;
    00059         friend struct saga::detail::monitorable<task>;  // needs to access get_impl()
    00061
    00062     protected:
    00064
    00065         TR1::shared_ptr <saga::impl::task_base> get_impl_sp(void) const;
    00066         saga::impl::task_base* get_impl (void) const;
    00067
    00068         saga::impl::task_interface* get_task_if (void);
    00069         saga::impl::task_interface const* get_task_if (void) const;
    00070         typedef saga::detail::monitorable<task> monitorable_base;
    00071
    00072         explicit task (saga::impl::object* init);
    00073         explicit task (saga::object const& o);
    00074         task &operator= (saga::object const& o);
    00076
    00077     public:
    00082         typedef task_base::state state;
    00083
    00088         explicit task (saga::task_base::state t = saga::task_base::New);
    00089
    00094         ~task ();
    00095
    00100         friend SAGA_EXPORT
    00101         bool operator== (task const & lhs, task const & rhs);
    00102
    00107         void run(void);
    00108
    00114         void cancel(void);
    00115
    00122         bool wait(double timeout = -1.0);
    00123
    00129         state get_state();
    00130
    00135         void rethrow();
    00136
    00142         saga::object get_object() const;
    00143
    00149         template <typename Retval>
    00150         Retval& get_result();
    00151
    00152         template <typename Retval>
    00153         Retval const& get_result() const;
    00154
    00156         void get_result();
    00157         void get_result() const;
    00158     };
    00159
    00160     namespace detail
    00161     {
    00163         // some global functions to simplify the implementation of sync/async/task
    00164         // versions of method calls
    00165
    00167
    00168         SAGA_EXPORT inline saga::task run (saga::task t)
    00169         {
    00170             t.run();
    00171             return t;
    00172         }
    00173
    00174         SAGA_EXPORT inline saga::task wait (saga::task t, double timeout = -1.0)
    00175         {
    00176             t.wait (timeout);
    00177             return t;
    00178         }
    00179
    00180         SAGA_EXPORT inline saga::task run_wait (saga::task t, double timeout = -1.0)
    00181         {
    00182             if (saga::task_base::New == t.get_state())
    00183             {
    00184                 t.run();
    00185                 t.wait(timeout);
    00186             }
    00187             return t;
    00188         }
    00189
    00191         //  Helper function to extract task result from implementation without
    00192         //  exposing any details
    00193         SAGA_EXPORT detail::hold_any& get_task_result(saga::task t);
    00194
    00196         // store the selector state to be used with this task instance
    00197         SAGA_EXPORT void set_selector_state(saga::task t,
    00198             TR1::shared_ptr<impl::adaptor_selector_state> state);
    00199
    00201         // store an exception in a task instance
    00202         SAGA_EXPORT saga::task set_task_exception(saga::task t,
    00203             saga::impl::object const *obj, saga::impl::exception_list const& e);
    00205     }
    00206
    00208 } // namespace saga
    00209
    00210 // re-enable warnings about dependent classes not being exported from the dll
    00211 #if defined(BOOST_MSVC)
    00212 #pragma warning(pop)
    00213 #endif
    00214
    00215 #endif // SAGA_TASK_HPP
    00216