@@ -35,86 +35,6 @@ using namespace Concurrency::streams::details;
35
35
36
36
namespace Concurrency { namespace streams { namespace details {
37
37
38
- /* **
39
- * ==++==
40
- *
41
- * Scheduler details.
42
- *
43
- * =-=-=-
44
- ****/
45
-
46
- class io_scheduler ;
47
-
48
- // / <summary>
49
- // / Scheduler of I/O completions as well as any asynchronous operations that
50
- // / are created internally as opposed to operations created by the application.
51
- // / </summary>
52
- class io_scheduler
53
- {
54
- public:
55
- // / <summary>
56
- // / Constructor
57
- // / </summary>
58
- io_scheduler ()
59
- : m_outstanding_work(0 )
60
- {
61
- m_no_outstanding_work.set ();
62
- }
63
-
64
- // / <summary>
65
- // / Destructor
66
- // / </summary>
67
- ~io_scheduler ()
68
- {
69
- m_no_outstanding_work.wait ();
70
- }
71
-
72
- void submit_io ()
73
- {
74
- m_no_outstanding_work.reset ();
75
- ++m_outstanding_work;
76
- }
77
-
78
- void complete_io ()
79
- {
80
- if (--m_outstanding_work == 0 )
81
- {
82
- m_no_outstanding_work.set ();
83
- }
84
- }
85
-
86
- io_service& service ()
87
- {
88
- return crossplat::threadpool::shared_instance ().service ();
89
- }
90
-
91
- private:
92
- pplx::extensibility::event_t m_no_outstanding_work;
93
-
94
- volatile std::atomic<long > m_outstanding_work;
95
- };
96
-
97
- // / <summary>
98
- // / We keep a single instance of the I/O scheduler. In order to create it on first
99
- // / demand, it's referenced through a shared_ptr<T> and retrieved through function call.
100
- // / </summary>
101
- boost::mutex _g_lock;
102
- std::unique_ptr<io_scheduler> _g_scheduler;
103
-
104
- // / <summary>
105
- // / Get the I/O scheduler instance.
106
- // / </summary>
107
- io_scheduler * get_scheduler ()
108
- {
109
- boost::lock_guard<boost::mutex> lck (_g_lock);
110
- if ( !_g_scheduler )
111
- {
112
- _g_scheduler = std::unique_ptr<io_scheduler>(new io_scheduler ());
113
- }
114
-
115
- return _g_scheduler.get ();
116
- }
117
-
118
38
/* **
119
39
* ==++==
120
40
*
@@ -164,7 +84,7 @@ struct _file_info_impl : _file_info
164
84
// / <returns>The error code if there was an error in file creation.</returns>
165
85
bool _finish_create (int fh, _filestream_callback *callback, std::ios_base::openmode mode, int /* prot */ )
166
86
{
167
- if ( fh != -1 )
87
+ if (fh != -1 )
168
88
{
169
89
// Buffer reads internally if and only if we're just reading (not also writing) and
170
90
// if the file is opened exclusively. If either is false, we're better off just
@@ -180,7 +100,7 @@ bool _finish_create(int fh, _filestream_callback *callback, std::ios_base::openm
180
100
181
101
auto info = new _file_info_impl (fh, mode, buffer);
182
102
183
- if ( mode & std::ios_base::app || mode & std::ios_base::ate )
103
+ if (mode & std::ios_base::app || mode & std::ios_base::ate)
184
104
{
185
105
info->m_wrpos = static_cast <size_t >(-1 ); // Start at the end of the file.
186
106
}
@@ -240,8 +160,7 @@ int get_open_flags(std::ios_base::openmode mode)
240
160
// / </remarks>
241
161
bool _open_fsb_str (_filestream_callback *callback, const char *filename, std::ios_base::openmode mode, int prot)
242
162
{
243
- if ( callback == nullptr ) return false ;
244
- if ( filename == nullptr ) return false ;
163
+ if ( callback == nullptr || filename == nullptr ) return false ;
245
164
246
165
std::string name (filename);
247
166
@@ -336,12 +255,8 @@ bool _close_fsb(_file_info **info, Concurrency::streams::details::_filestream_ca
336
255
// / <returns>0 if the write request is still outstanding, -1 if the request failed, otherwise the size of the data written</returns>
337
256
size_t _write_file_async (Concurrency::streams::details::_file_info_impl *fInfo , Concurrency::streams::details::_filestream_callback *callback, const void *ptr, size_t count, size_t position)
338
257
{
339
- // async file writes are emulated using tasks
340
- auto sched = get_scheduler ();
341
-
342
258
++fInfo ->m_outstanding_writes ;
343
- sched->submit_io ();
344
-
259
+
345
260
pplx::create_task ([=]() -> void
346
261
{
347
262
off_t abs_position;
@@ -388,8 +303,6 @@ size_t _write_file_async(Concurrency::streams::details::_file_info_impl *fInfo,
388
303
fInfo ->m_sync_waiters .clear ();
389
304
}
390
305
}
391
-
392
- sched->complete_io ();
393
306
});
394
307
395
308
return 0 ;
@@ -406,9 +319,6 @@ size_t _write_file_async(Concurrency::streams::details::_file_info_impl *fInfo,
406
319
// / <returns>0 if the read request is still outstanding, -1 if the request failed, otherwise the size of the data read into the buffer</returns>
407
320
size_t _read_file_async (Concurrency::streams::details::_file_info_impl *fInfo , Concurrency::streams::details::_filestream_callback *callback, void *ptr, size_t count, size_t offset)
408
321
{
409
- auto sched = get_scheduler ();
410
- sched->submit_io ();
411
-
412
322
pplx::create_task ([=]() -> void
413
323
{
414
324
auto bytes_read = pread (fInfo ->m_handle , ptr, count, offset);
@@ -420,7 +330,6 @@ size_t _read_file_async(Concurrency::streams::details::_file_info_impl *fInfo, C
420
330
{
421
331
callback->on_completed (bytes_read);
422
332
}
423
- sched->complete_io ();
424
333
});
425
334
426
335
return 0 ;
0 commit comments