1 // Copyright (C) 2007  Douglas Gregor  <doug.gregor@gmail.com>
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/graph/use_mpi.hpp>
7 #include <boost/graph/distributed/detail/tag_allocator.hpp>
8 
9 namespace boost { namespace graph { namespace distributed { namespace detail {
10 
get_tag()11 tag_allocator::token tag_allocator::get_tag()
12 {
13   int tag;
14 
15   if (!freed.empty()) {
16     // Grab the tag at the top of the stack.
17     tag = freed.back();
18     freed.pop_back();
19   } else
20     // Grab the bottom tag and move the bottom down
21     tag = bottom--;
22 
23   return token(this, tag);
24 }
25 
token(const token & other)26 tag_allocator::token::token(const token& other)
27   : allocator(other.allocator), tag_(other.tag_)
28 {
29   // other no longer owns this tag
30   other.tag_ = -1;
31 }
32 
~token()33 tag_allocator::token::~token()
34 {
35   if (tag_ != -1) {
36     if (tag_ == allocator->bottom + 1)
37       // This is the bottommost tag: just bump up the bottom
38       ++allocator->bottom;
39     else
40       // This tag isn't the bottom, so push it only the freed stack
41       allocator->freed.push_back(tag_);
42   }
43 }
44 
45 } } } } // end namespace boost::graph::distributed::detail
46