File: sync_streams.qbk

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (193 lines) | stat: -rw-r--r-- 6,115 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[/
 / Copyright (c) 2013 Vicente J. Botet Escriba
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]


[section:ext_locked_streams Externally Locked Streams - EXPERIMENTAL]

[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(] 

[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3535.html [*N3535 - C++ Streams Mutex]] C++1y proposal, even if the library proposes al alternative interface.]

[section:tutorial Tutorial]

[endsect] [/tutorial]

[/////////////////////]
[section:ref Reference]

  #include <boost/thread/externally_locked_stream.hpp>
  namespace boost
  {
    template <typename Stream, typename RecursiveMutex=recursive_mutex>
    class externally_locked_stream;
    template <class Stream, typename RecursiveMutex=recursive_mutex>
    class stream_guard;
    template <typename Stream, typename RecursiveMutex>
    struct is_strict_lock_sur_parole<stream_guard<Stream, RecursiveMutex> > : true_type  {};

    // Stream-like operators
    template <typename Stream, typename RecursiveMutex, typename T>
    const stream_guard<Stream, RecursiveMutex>& operator<<(const stream_guard<Stream, RecursiveMutex>& lck, T arg);
    template <typename Stream, typename RecursiveMutex>
    const stream_guard<Stream, RecursiveMutex>& 
    operator<<(const stream_guard<Stream, RecursiveMutex>& lck, Stream& (*arg)(Stream&));
    template <typename Stream, typename RecursiveMutex, typename T>
    const stream_guard<Stream, RecursiveMutex>& 
    operator>>(const stream_guard<Stream, RecursiveMutex>& lck, T& arg);
    template <typename Stream, typename RecursiveMutex, typename T>
    stream_guard<Stream, RecursiveMutex> 
    operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, T arg);
    template <typename Stream, typename RecursiveMutex>
    stream_guard<Stream, RecursiveMutex> 
    operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, Stream& (*arg)(Stream&));
    template <typename Stream, typename RecursiveMutex, typename T>
    stream_guard<Stream, RecursiveMutex> 
    operator>>(externally_locked_stream<Stream, RecursiveMutex>& mtx, T& arg);
  }

[/////////////////////////////////////////]
[section:stream_guard Class `stream_guard`]
  
  #include <boost/thread/externally_locked_stream.hpp>
  namespace boost
  { 
    template <class Stream, typename RecursiveMutex=recursive_mutex>
    class stream_guard
    {
    public:
      typedef typename externally_locked_stream<Stream, RecursiveMutex>::mutex_type mutex_type;
  
      // Constructors, Assignment and Destructors
      stream_guard(stream_guard const&) = delete;
      stream_guard& operator=(stream_guard const&) = delete;
      stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx);
      stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx, adopt_lock_t);
      stream_guard(stream_guard&& rhs);
      ~stream_guard();

      // Observers  
      bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT;
      Stream& get() const;
      Stream& bypass() const;

    };
  }

`stream_guard` is a model of __StrictLock.

[//////////////////////////////////////////////////]
[section:constructor `stream_guard(mutex_type & m)`]

[variablelist

[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]

[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]

]

[endsect]
[////////////////////////////////////////////////////////////////////////////]
[section:constructor_adopt `stream_guard(mutex_type & m,boost::adopt_lock_t)`]

[variablelist

[[Precondition:] [The current thread owns a lock on `m` equivalent to one
obtained by a call to [lock_ref_link `m.lock()`].]]

[[Effects:] [Stores a reference to `m`. Takes ownership of the lock state of
`m`.]]

[[Throws:] [Nothing.]]

]

[endsect]
[//////////////////////////////////////////////////////////]
[section:move_constructor `stream_guard(stream_guard && m)`]


[variablelist

[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]

[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]

]

[endsect]
[////////////////////////////////////]
[section:destructor `~stream_guard()`]

[variablelist

[[Effects:] [Invokes [unlock_ref_link `m.unlock()`] on the __lockable_concept_type__
object passed to the constructor.]]

[[Throws:] [Nothing.]]

]

[endsect]

[endsect]
[//////////////////////////////////////////////////////////////////]
[section:externally_locked_stream Class `externally_locked_stream `]

  #include <boost/thread/externally_locked_stream.hpp>
  namespace boost
  {
    template <typename Stream, typename RecursiveMutex>
    class externally_locked_stream: public externally_locked<Stream&, RecursiveMutex>
    {
    public:
      // Constructors, Assignment and Destructors
      externally_locked_stream(externally_locked_stream const&) = delete;
      externally_locked_stream& operator=(externally_locked_stream const&) = delete;
      externally_locked_stream(Stream& stream, RecursiveMutex& mtx);
  
      // Modifiers  
      stream_guard<Stream, RecursiveMutex> hold();

    };
  }

`externally_locked_stream` cloaks a reference to a stream of type `Stream`, and actually
provides full access to that object through the `get` member functions, provided you
pass a reference to a strict lock object.


[////////////////////////////////////////////////////////////////////////]
[section:constructor `externally_locked_stream(Stream&, RecursiveMutex&)`]

[variablelist

[[Effects:] [Constructs an externally locked object storing the cloaked reference object and its locking mutex.]]

]

[endsect]

[/////////////////////]
[section:hold `hold()`]

[variablelist

[[Returns:] [A stream_guard which will hold the mutex during it lifetime .]]

]

[endsect]



[endsect]


[endsect] [/ref]

[endsect] [/Externally Locked Streams]