fix doc example typo
[boost.git] / boost / asio / detail / call_stack.hpp
blob0096741c1056ae44ed1a6f9fefa92bd6da91cf67
1 //
2 // call_stack.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
11 #ifndef BOOST_ASIO_DETAIL_CALL_STACK_HPP
12 #define BOOST_ASIO_DETAIL_CALL_STACK_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/noncopyable.hpp>
21 #include <boost/asio/detail/tss_ptr.hpp>
23 namespace boost {
24 namespace asio {
25 namespace detail {
27 // Helper class to determine whether or not the current thread is inside an
28 // invocation of io_service::run() for a specified io_service object.
29 template <typename Owner>
30 class call_stack
32 public:
33 // Context class automatically pushes an owner on to the stack.
34 class context
35 : private noncopyable
37 public:
38 // Push the owner on to the stack.
39 explicit context(Owner* d)
40 : owner_(d),
41 next_(call_stack<Owner>::top_)
43 call_stack<Owner>::top_ = this;
46 // Pop the owner from the stack.
47 ~context()
49 call_stack<Owner>::top_ = next_;
52 private:
53 friend class call_stack<Owner>;
55 // The owner associated with the context.
56 Owner* owner_;
58 // The next element in the stack.
59 context* next_;
62 friend class context;
64 // Determine whether the specified owner is on the stack.
65 static bool contains(Owner* d)
67 context* elem = top_;
68 while (elem)
70 if (elem->owner_ == d)
71 return true;
72 elem = elem->next_;
74 return false;
77 private:
78 // The top of the stack of calls for the current thread.
79 static tss_ptr<context> top_;
82 template <typename Owner>
83 tss_ptr<typename call_stack<Owner>::context>
84 call_stack<Owner>::top_;
86 } // namespace detail
87 } // namespace asio
88 } // namespace boost
90 #include <boost/asio/detail/pop_options.hpp>
92 #endif // BOOST_ASIO_DETAIL_CALL_STACK_HPP