Skip to content

Commit b029e55

Browse files
committed
Removing unnecessary global io_scheduler from posix file i/o.
1 parent bfb570e commit b029e55

File tree

1 file changed

+4
-95
lines changed

1 file changed

+4
-95
lines changed

Release/src/streams/fileio_posix.cpp

Lines changed: 4 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -35,86 +35,6 @@ using namespace Concurrency::streams::details;
3535

3636
namespace Concurrency { namespace streams { namespace details {
3737

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-
11838
/***
11939
* ==++==
12040
*
@@ -164,7 +84,7 @@ struct _file_info_impl : _file_info
16484
/// <returns>The error code if there was an error in file creation.</returns>
16585
bool _finish_create(int fh, _filestream_callback *callback, std::ios_base::openmode mode, int /* prot */)
16686
{
167-
if ( fh != -1 )
87+
if (fh != -1)
16888
{
16989
// Buffer reads internally if and only if we're just reading (not also writing) and
17090
// 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
180100

181101
auto info = new _file_info_impl(fh, mode, buffer);
182102

183-
if ( mode & std::ios_base::app || mode & std::ios_base::ate )
103+
if (mode & std::ios_base::app || mode & std::ios_base::ate)
184104
{
185105
info->m_wrpos = static_cast<size_t>(-1); // Start at the end of the file.
186106
}
@@ -240,8 +160,7 @@ int get_open_flags(std::ios_base::openmode mode)
240160
/// </remarks>
241161
bool _open_fsb_str(_filestream_callback *callback, const char *filename, std::ios_base::openmode mode, int prot)
242162
{
243-
if ( callback == nullptr ) return false;
244-
if ( filename == nullptr ) return false;
163+
if ( callback == nullptr || filename == nullptr) return false;
245164

246165
std::string name(filename);
247166

@@ -336,12 +255,8 @@ bool _close_fsb(_file_info **info, Concurrency::streams::details::_filestream_ca
336255
/// <returns>0 if the write request is still outstanding, -1 if the request failed, otherwise the size of the data written</returns>
337256
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)
338257
{
339-
// async file writes are emulated using tasks
340-
auto sched = get_scheduler();
341-
342258
++fInfo->m_outstanding_writes;
343-
sched->submit_io();
344-
259+
345260
pplx::create_task([=]() -> void
346261
{
347262
off_t abs_position;
@@ -388,8 +303,6 @@ size_t _write_file_async(Concurrency::streams::details::_file_info_impl *fInfo,
388303
fInfo->m_sync_waiters.clear();
389304
}
390305
}
391-
392-
sched->complete_io();
393306
});
394307

395308
return 0;
@@ -406,9 +319,6 @@ size_t _write_file_async(Concurrency::streams::details::_file_info_impl *fInfo,
406319
/// <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>
407320
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)
408321
{
409-
auto sched = get_scheduler();
410-
sched->submit_io();
411-
412322
pplx::create_task([=]() -> void
413323
{
414324
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
420330
{
421331
callback->on_completed(bytes_read);
422332
}
423-
sched->complete_io();
424333
});
425334

426335
return 0;

0 commit comments

Comments
 (0)