1 //  Copyright (c) 2007-2014 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef HPX_RUNTIME_NAMING_ID_TYPE_HPP
7 #define HPX_RUNTIME_NAMING_ID_TYPE_HPP
8 
9 #include <hpx/config.hpp>
10 #include <hpx/runtime/naming_fwd.hpp>
11 #include <hpx/runtime/serialization/serialization_fwd.hpp>
12 
13 #include <boost/intrusive_ptr.hpp>
14 
15 #include <cstdint>
16 #include <iosfwd>
17 #include <utility>
18 
19 #include <hpx/config/warnings_prefix.hpp>
20 
21 ///////////////////////////////////////////////////////////////////////////////
22 namespace hpx { namespace naming
23 {
24     namespace detail
25     {
26         struct HPX_EXPORT id_type_impl;
27         HPX_EXPORT void intrusive_ptr_add_ref(id_type_impl* p);
28         HPX_EXPORT void intrusive_ptr_release(id_type_impl* p);
29     }
30 
31     ///////////////////////////////////////////////////////////////////////////
32     // the local gid is actually just a wrapper around the real thing
33     struct HPX_EXPORT id_type
34     {
35     private:
36         friend struct detail::id_type_impl;
37 
id_typehpx::naming::id_type38         id_type(detail::id_type_impl* p)
39           : gid_(p)
40         {}
41 
42     public:
43         enum management_type
44         {
45             unknown_deleter = -1,
46             unmanaged = 0,          ///< unmanaged GID
47             managed = 1,            ///< managed GID
48             managed_move_credit = 2 ///< managed GID which will give up all
49                                     ///< credits when sent
50         };
51 
id_typehpx::naming::id_type52         id_type() {}
53 
54         id_type(std::uint64_t lsb_id, management_type t);
55         id_type(gid_type const& gid, management_type t);
56         id_type(std::uint64_t msb_id, std::uint64_t lsb_id, management_type t);
57 
id_typehpx::naming::id_type58         id_type(id_type const & o) : gid_(o.gid_) {}
id_typehpx::naming::id_type59         id_type(id_type && o)
60           : gid_(std::move(o.gid_))
61         {
62             o.gid_.reset();
63         }
64 
operator =hpx::naming::id_type65         id_type & operator=(id_type const & o)
66         {
67             if (this != &o)
68                 gid_ = o.gid_;
69             return *this;
70         }
operator =hpx::naming::id_type71         id_type & operator=(id_type && o)
72         {
73             if (this != &o)
74             {
75                 gid_ = o.gid_;
76                 o.gid_.reset();
77             }
78             return *this;
79         }
80 
81         gid_type& get_gid();
82         gid_type const& get_gid() const;
83 
84         // This function is used in AGAS unit tests and application code, do not
85         // remove.
86         management_type get_management_type() const;
87 
88         id_type& operator++();
89         id_type operator++(int);
90 
91         explicit operator bool() const noexcept;
92 
93         // comparison is required as well
94         friend bool operator== (id_type const& lhs, id_type const& rhs);
95         friend bool operator!= (id_type const& lhs, id_type const& rhs);
96 
97         friend bool operator< (id_type const& lhs, id_type const& rhs);
98         friend bool operator<= (id_type const& lhs, id_type const& rhs);
99         friend bool operator> (id_type const& lhs, id_type const& rhs);
100         friend bool operator>= (id_type const& lhs, id_type const& rhs);
101 
102         // access the internal parts of the gid
103         std::uint64_t get_msb() const;
104         void set_msb(std::uint64_t msb);
105 
106         std::uint64_t get_lsb() const;
107         void set_lsb(std::uint64_t lsb);
108         void set_lsb(void* lsb);
109 
110         // Convert this id into an unmanaged one (in-place) - Use with maximum
111         // care, or better, don't use this at all.
112         void make_unmanaged() const;
113 
114     private:
115         friend HPX_API_EXPORT gid_type get_parcel_dest_gid(id_type const& id);
116 
117         friend HPX_EXPORT std::ostream& operator<<(std::ostream& os,
118             id_type const& id);
119 
120         friend class hpx::serialization::access;
121 
122         void save(serialization::output_archive& ar, unsigned int version) const;
123 
124         void load(serialization::input_archive& ar, unsigned int version);
125 
126         HPX_SERIALIZATION_SPLIT_MEMBER()
127 
128         boost::intrusive_ptr<detail::id_type_impl> gid_;
129     };
130 
131     ///////////////////////////////////////////////////////////////////////////
132     id_type const invalid_id = id_type();
133 }}
134 
135 #include <hpx/config/warnings_suffix.hpp>
136 
137 #endif /*HPX_RUNTIME_NAMING_ID_TYPE_HPP*/
138