~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/call_stack.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
//
10
 
 
11
 
#ifndef ASIO_DETAIL_CALL_STACK_HPP
12
 
#define ASIO_DETAIL_CALL_STACK_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/noncopyable.hpp"
21
 
#include "asio/detail/tss_ptr.hpp"
22
 
 
23
 
namespace asio {
24
 
namespace detail {
25
 
 
26
 
// Helper class to determine whether or not the current thread is inside an
27
 
// invocation of io_service::run() for a specified io_service object.
28
 
template <typename Owner>
29
 
class call_stack
30
 
{
31
 
public:
32
 
  // Context class automatically pushes an owner on to the stack.
33
 
  class context
34
 
    : private noncopyable
35
 
  {
36
 
  public:
37
 
    // Push the owner on to the stack.
38
 
    explicit context(Owner* d)
39
 
      : owner_(d),
40
 
        next_(call_stack<Owner>::top_)
41
 
    {
42
 
      call_stack<Owner>::top_ = this;
43
 
    }
44
 
 
45
 
    // Pop the owner from the stack.
46
 
    ~context()
47
 
    {
48
 
      call_stack<Owner>::top_ = next_;
49
 
    }
50
 
 
51
 
  private:
52
 
    friend class call_stack<Owner>;
53
 
 
54
 
    // The owner associated with the context.
55
 
    Owner* owner_;
56
 
 
57
 
    // The next element in the stack.
58
 
    context* next_;
59
 
  };
60
 
 
61
 
  friend class context;
62
 
 
63
 
  // Determine whether the specified owner is on the stack.
64
 
  static bool contains(Owner* d)
65
 
  {
66
 
    context* elem = top_;
67
 
    while (elem)
68
 
    {
69
 
      if (elem->owner_ == d)
70
 
        return true;
71
 
      elem = elem->next_;
72
 
    }
73
 
    return false;
74
 
  }
75
 
 
76
 
private:
77
 
  // The top of the stack of calls for the current thread.
78
 
  static tss_ptr<context> top_;
79
 
};
80
 
 
81
 
template <typename Owner>
82
 
tss_ptr<typename call_stack<Owner>::context>
83
 
call_stack<Owner>::top_;
84
 
 
85
 
} // namespace detail
86
 
} // namespace asio
87
 
 
88
 
#include "asio/detail/pop_options.hpp"
89
 
 
90
 
#endif // ASIO_DETAIL_CALL_STACK_HPP