~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to libtorrent/include/asio/strand.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// strand.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_STRAND_HPP
12
 
#define ASIO_STRAND_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/io_service.hpp"
21
 
#include "asio/detail/strand_service.hpp"
22
 
#include "asio/detail/wrapped_handler.hpp"
23
 
 
24
 
namespace asio {
25
 
 
26
 
/// Provides serialised handler execution.
27
 
/**
28
 
 * The io_service::strand class provides the ability to post and dispatch
29
 
 * handlers with the guarantee that none of those handlers will execute
30
 
 * concurrently.
31
 
 *
32
 
 * @par Thread Safety
33
 
 * @e Distinct @e objects: Safe.@n
34
 
 * @e Shared @e objects: Safe.
35
 
 *
36
 
 * @par Concepts:
37
 
 * Dispatcher.
38
 
 */
39
 
class io_service::strand
40
 
{
41
 
public:
42
 
  /// Constructor.
43
 
  /**
44
 
   * Constructs the strand.
45
 
   *
46
 
   * @param io_service The io_service object that the strand will use to
47
 
   * dispatch handlers that are ready to be run.
48
 
   */
49
 
  explicit strand(asio::io_service& io_service)
50
 
    : service_(asio::use_service<
51
 
        asio::detail::strand_service>(io_service))
52
 
  {
53
 
    service_.construct(impl_);
54
 
  }
55
 
 
56
 
  /// Destructor.
57
 
  /**
58
 
   * Destroys a strand.
59
 
   *
60
 
   * Handlers posted through the strand that have not yet been invoked will
61
 
   * still be dispatched in a way that meets the guarantee of non-concurrency.
62
 
   */
63
 
  ~strand()
64
 
  {
65
 
    service_.destroy(impl_);
66
 
  }
67
 
 
68
 
  /// (Deprecated: use get_io_service().) Get the io_service associated with
69
 
  /// the strand.
70
 
  /**
71
 
   * This function may be used to obtain the io_service object that the strand
72
 
   * uses to dispatch handlers for asynchronous operations.
73
 
   *
74
 
   * @return A reference to the io_service object that the strand will use to
75
 
   * dispatch handlers. Ownership is not transferred to the caller.
76
 
   */
77
 
  asio::io_service& io_service()
78
 
  {
79
 
    return service_.get_io_service();
80
 
  }
81
 
 
82
 
  /// Get the io_service associated with the strand.
83
 
  /**
84
 
   * This function may be used to obtain the io_service object that the strand
85
 
   * uses to dispatch handlers for asynchronous operations.
86
 
   *
87
 
   * @return A reference to the io_service object that the strand will use to
88
 
   * dispatch handlers. Ownership is not transferred to the caller.
89
 
   */
90
 
  asio::io_service& get_io_service()
91
 
  {
92
 
    return service_.get_io_service();
93
 
  }
94
 
 
95
 
  /// Request the strand to invoke the given handler.
96
 
  /**
97
 
   * This function is used to ask the strand to execute the given handler.
98
 
   *
99
 
   * The strand object guarantees that handlers posted or dispatched through
100
 
   * the strand will not be executed concurrently. The handler may be executed
101
 
   * inside this function if the guarantee can be met. If this function is
102
 
   * called from within a handler that was posted or dispatched through the same
103
 
   * strand, then the new handler will be executed immediately.
104
 
   *
105
 
   * The strand's guarantee is in addition to the guarantee provided by the
106
 
   * underlying io_service. The io_service guarantees that the handler will only
107
 
   * be called in a thread in which the io_service's run member function is
108
 
   * currently being invoked.
109
 
   *
110
 
   * @param handler The handler to be called. The strand will make a copy of the
111
 
   * handler object as required. The function signature of the handler must be:
112
 
   * @code void handler(); @endcode
113
 
   */
114
 
  template <typename Handler>
115
 
  void dispatch(Handler handler)
116
 
  {
117
 
    service_.dispatch(impl_, handler);
118
 
  }
119
 
 
120
 
  /// Request the strand to invoke the given handler and return
121
 
  /// immediately.
122
 
  /**
123
 
   * This function is used to ask the strand to execute the given handler, but
124
 
   * without allowing the strand to call the handler from inside this function.
125
 
   *
126
 
   * The strand object guarantees that handlers posted or dispatched through
127
 
   * the strand will not be executed concurrently. The strand's guarantee is in
128
 
   * addition to the guarantee provided by the underlying io_service. The
129
 
   * io_service guarantees that the handler will only be called in a thread in
130
 
   * which the io_service's run member function is currently being invoked.
131
 
   *
132
 
   * @param handler The handler to be called. The strand will make a copy of the
133
 
   * handler object as required. The function signature of the handler must be:
134
 
   * @code void handler(); @endcode
135
 
   */
136
 
  template <typename Handler>
137
 
  void post(Handler handler)
138
 
  {
139
 
    service_.post(impl_, handler);
140
 
  }
141
 
 
142
 
  /// Create a new handler that automatically dispatches the wrapped handler
143
 
  /// on the strand.
144
 
  /**
145
 
   * This function is used to create a new handler function object that, when
146
 
   * invoked, will automatically pass the wrapped handler to the strand's
147
 
   * dispatch function.
148
 
   *
149
 
   * @param handler The handler to be wrapped. The strand will make a copy of
150
 
   * the handler object as required. The function signature of the handler must
151
 
   * be: @code void handler(A1 a1, ... An an); @endcode
152
 
   *
153
 
   * @return A function object that, when invoked, passes the wrapped handler to
154
 
   * the strand's dispatch function. Given a function object with the signature:
155
 
   * @code R f(A1 a1, ... An an); @endcode
156
 
   * If this function object is passed to the wrap function like so:
157
 
   * @code strand.wrap(f); @endcode
158
 
   * then the return value is a function object with the signature
159
 
   * @code void g(A1 a1, ... An an); @endcode
160
 
   * that, when invoked, executes code equivalent to:
161
 
   * @code strand.dispatch(boost::bind(f, a1, ... an)); @endcode
162
 
   */
163
 
  template <typename Handler>
164
 
#if defined(GENERATING_DOCUMENTATION)
165
 
  unspecified
166
 
#else
167
 
  detail::wrapped_handler<strand, Handler>
168
 
#endif
169
 
  wrap(Handler handler)
170
 
  {
171
 
    return detail::wrapped_handler<io_service::strand, Handler>(*this, handler);
172
 
  }
173
 
 
174
 
private:
175
 
  asio::detail::strand_service& service_;
176
 
  asio::detail::strand_service::implementation_type impl_;
177
 
};
178
 
 
179
 
/// Typedef for backwards compatibility.
180
 
typedef asio::io_service::strand strand;
181
 
 
182
 
} // namespace asio
183
 
 
184
 
#include "asio/detail/pop_options.hpp"
185
 
 
186
 
#endif // ASIO_STRAND_HPP