3 // Copyright (C) 2007 Douglas Gregor <doug.gregor@gmail.com>
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_GRAPH_DISTRIBUTED_TAG_ALLOCATOR_HPP
9 #define BOOST_GRAPH_DISTRIBUTED_TAG_ALLOCATOR_HPP
11 #ifndef BOOST_GRAPH_USE_MPI
12 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
17 namespace boost { namespace graph { namespace distributed { namespace detail {
20 * \brief The tag allocator allows clients to request unique tags that
21 * can be used for one-time communications.
23 * The tag allocator hands out tag values from a predefined maximum
24 * (given in the constructor) moving downward. Tags are provided one
25 * at a time via a @c token. When the @c token goes out of scope, the
26 * tag is returned and may be reallocated. These tags should be used,
27 * for example, for one-time communication of values.
35 * Construct a new tag allocator that provides unique tags starting
36 * with the value @p top_tag and moving lower, as necessary.
38 explicit tag_allocator(int top_tag) : bottom(top_tag) { }
41 * Retrieve a new tag. The token itself holds onto the tag, which
42 * will be released when the token is destroyed.
48 std::vector<int> freed;
52 * A token used to represent an allocated tag.
54 class tag_allocator::token {
56 /// Transfer ownership of the tag from @p other.
57 token(const token& other);
59 /// De-allocate the tag, if this token still owns it.
62 /// Retrieve the tag allocated for this task.
63 operator int() const { return tag_; }
66 /// Create a token with a specific tag from the given tag_allocator
67 token(tag_allocator* allocator, int tag)
68 : allocator(allocator), tag_(tag) { }
70 /// Undefined: tokens are not copy-assignable
71 token& operator=(const token&);
73 /// The allocator from which this tag was allocated.
74 tag_allocator* allocator;
76 /// The stored tag flag. If -1, this token does not own the tag.
79 friend class tag_allocator;
82 } } } } // end namespace boost::graph::distributed::detail
84 #endif // BOOST_GRAPH_DISTRIBUTED_TAG_ALLOCATOR_HPP