1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIB_ZX_TASK_H_
6 #define LIB_ZX_TASK_H_
7 
8 #include <lib/zx/handle.h>
9 #include <lib/zx/object.h>
10 #include <lib/zx/suspend_token.h>
11 
12 namespace zx {
13 
14 class port;
15 class suspend_token;
16 
17 template <typename T = void> class task : public object<T> {
18 public:
19     constexpr task() = default;
20 
task(zx_handle_t value)21     explicit task(zx_handle_t value) : object<T>(value) {}
22 
task(handle && h)23     explicit task(handle&& h) : object<T>(h.release()) {}
24 
task(task && other)25     task(task&& other) : object<T>(other.release()) {}
26 
bind_exception_port(const object<port> & port,uint64_t key,uint32_t options)27     zx_status_t bind_exception_port(
28             const object<port>& port, uint64_t key, uint32_t options) const {
29         return zx_task_bind_exception_port(object<T>::get(), port.get(), key, options);
30     }
31 
kill()32     zx_status_t kill() const { return zx_task_kill(object<T>::get()); }
33 
34     // Deprecated: Use the variant that takes a suspend_token.
suspend()35     zx_status_t suspend() const { return zx_task_suspend(object<T>::get()); }
36 
suspend(suspend_token * result)37     zx_status_t suspend(suspend_token* result) const {
38         // Assume |result| must refer to a different container than |this|, due
39         // to strict aliasing.
40         return zx_task_suspend_token(
41             object<T>::get(), result->reset_and_get_address());
42     }
43 
resume_from_exception(const object<port> & port,uint32_t options)44     zx_status_t resume_from_exception(const object<port>& port, uint32_t options) const {
45         return zx_task_resume_from_exception(object<T>::get(), port.get(), options);
46     }
47 };
48 
49 } // namespace zx
50 
51 #endif  // LIB_ZX_TASK_H_
52