1 //  Copyright (c)      2011 Bryce Lelbach
2 //  Copyright (c) 2007-2017 Hartmut Kaiser
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
5 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #if !defined(HPX_1FB4A979_B6B6_4845_BD95_3CEC605011A2)
8 #define HPX_1FB4A979_B6B6_4845_BD95_3CEC605011A2
9 
10 #include <hpx/config.hpp>
11 #include <hpx/exception_fwd.hpp>
12 #include <hpx/lcos/server/object_semaphore.hpp>
13 #include <hpx/runtime/components/client_base.hpp>
14 #include <hpx/util/assert.hpp>
15 
16 #include <cstdint>
17 
18 namespace hpx { namespace lcos
19 {
20     template <typename ValueType>
21     struct object_semaphore
22       : components::client_base<
23             object_semaphore<ValueType>,
24             lcos::server::object_semaphore<ValueType>
25         >
26     {
27         typedef lcos::server::object_semaphore<ValueType> server_type;
28 
29         typedef components::client_base<
30             object_semaphore,
31             lcos::server::object_semaphore<ValueType>
32         > base_type;
33 
object_semaphorehpx::lcos::object_semaphore34         object_semaphore() {}
35 
object_semaphorehpx::lcos::object_semaphore36         object_semaphore(naming::id_type gid) : base_type(gid) {}
37 
38         ///////////////////////////////////////////////////////////////////////
signalhpx::lcos::object_semaphore39         lcos::future<void> signal(launch::async_policy,
40             ValueType const& val, std::uint64_t count = 1)
41         {
42             HPX_ASSERT(this->get_id());
43             typedef typename server_type::signal_action action_type;
44             return hpx::async<action_type>(this->get_id(), val, count);
45         }
signalhpx::lcos::object_semaphore46         void signal(launch::sync_policy,
47             ValueType const& val, std::uint64_t count = 1)
48         {
49             signal(hpx::async, val, count).get();
50         }
51 
52         ///////////////////////////////////////////////////////////////////////
gethpx::lcos::object_semaphore53         lcos::future<ValueType> get(launch::async_policy)
54         {
55             HPX_ASSERT(this->get_id());
56             typedef typename server_type::get_action action_type;
57             return hpx::async<action_type>(this->get_id());
58         }
gethpx::lcos::object_semaphore59         ValueType get(launch::sync_policy)
60         {
61             return get(launch::async).get();
62         }
63 
64         ///////////////////////////////////////////////////////////////////////
abort_pendinghpx::lcos::object_semaphore65         future<void> abort_pending(launch::async_policy, error ec = no_success)
66         {
67             HPX_ASSERT(this->get_id());
68             typedef typename server_type::abort_pending_action action_type;
69             return hpx::async<action_type>(this->get_id(), ec);
70         }
abort_pendinghpx::lcos::object_semaphore71         void abort_pending(launch::sync_policy, error ec = no_success)
72         {
73             abort_pending(launch::async).get();
74         }
75 
76         ///////////////////////////////////////////////////////////////////////
waithpx::lcos::object_semaphore77         void wait(launch::async_policy)
78         {
79             HPX_ASSERT(this->get_id());
80             typedef typename server_type::wait_action action_type;
81             return hpx::async<action_type>(this->get_id());
82         }
waithpx::lcos::object_semaphore83         void wait(launch::sync_policy)
84         {
85             wait(launch::async).get();
86         }
87     };
88 }}
89 
90 #endif // HPX_1FB4A979_B6B6_4845_BD95_3CEC605011A2
91 
92