[go: up one dir, main page]

Menu

[8bf46b]: / io / syscall_file.cpp  Maximize  Restore  History

Download this file

193 lines (150 with data), 4.7 kB

  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
#include "syscall_file.h"
__STXXL_BEGIN_NAMESPACE
syscall_file::syscall_file(
const std::string & filename,
int mode,
int disk): ufs_file_base (filename, mode, disk)
{
}
syscall_request::syscall_request(
syscall_file * f,
void *buf,
stxxl::int64 off,
size_t b,
request_type t,
completion_handler on_cmpl):
ufs_request_base(f,buf,off,b,t,on_cmpl)
{
}
const char *syscall_request::io_type ()
{
return "syscall";
}
void syscall_request::serve ()
{
stats * iostats = stats::get_instance();
if(nref() < 2)
{
STXXL_ERRMSG("WARNING: serious error, reference to the request is lost before serve (nref="
<<nref()<<") "<<
" this="<<long(this)<<
" File descriptor="<<
static_cast<syscall_file*>(file_)->get_file_des()<< " offset="<<offset<<" buffer="<<buffer<<" bytes="<<bytes
<< " type=" <<((type == READ)?"READ":"WRITE") )
}
STXXL_VERBOSE2("syscall_request::serve(): Buffer at "<<((void*)buffer)
<<" offset: "<<offset<<" bytes: "<<bytes<<((type== READ)?" READ":" WRITE")
<<" file: "<<static_cast<syscall_file*>(file_)->get_file_des());
try
{
stxxl_ifcheck_i(::lseek (static_cast<syscall_file*>(file_)->get_file_des (), offset, SEEK_SET),
" this="<<long(this)<<" File descriptor="<<
static_cast<syscall_file*>(file_)->get_file_des()<< " offset="<<offset<<" buffer="<<
buffer<<" bytes="<<bytes
<< " type=" <<((type == READ)?"READ":"WRITE"),io_error )
else
{
if (type == READ)
{
#ifdef STXXL_IO_STATS
iostats->read_started (size());
#endif
debugmon::get_instance()->io_started((char*)buffer);
stxxl_ifcheck_i(::read (static_cast<syscall_file*>(file_)->get_file_des(), buffer, bytes),
" this="<<long(this)<<" File descriptor="<<
static_cast<syscall_file*>(file_)->get_file_des()<< " offset="<<offset<<
" buffer="<<buffer<<" bytes="<<bytes<< " type=" <<
((type == READ)?"READ":"WRITE")<<" nref= "<<nref(),io_error)
debugmon::get_instance()->io_finished((char*)buffer);
#ifdef STXXL_IO_STATS
iostats->read_finished ();
#endif
}
else
{
#ifdef STXXL_IO_STATS
iostats->write_started (size());
#endif
debugmon::get_instance()->io_started((char*)buffer);
stxxl_ifcheck_i(::write (static_cast<syscall_file*>(file_)->get_file_des (), buffer, bytes),
" this="<<long(this)<<" File descriptor="<<
static_cast<syscall_file*>(file_)->get_file_des()<< " offset="<<offset<<" buffer="<<
buffer<<" bytes="<<bytes<< " type=" <<
((type == READ)?"READ":"WRITE")<<" nref= "<<nref(),io_error);
debugmon::get_instance()->io_finished((char*)buffer);
#ifdef STXXL_IO_STATS
iostats->write_finished ();
#endif
}
}
}
catch(const io_error & ex)
{
error_occured(ex.what());
}
if(nref() < 2)
{
STXXL_ERRMSG("WARNING: reference to the request is lost after serve (nref="<<nref()<<") "<<
" this="<<long(this)<<" File descriptor="<<static_cast<syscall_file*>(file_)->get_file_des()<<
" offset="<<offset<<" buffer="<<buffer<<" bytes="<<bytes <<
" type=" <<((type == READ)?"READ":"WRITE"))
}
_state.set_to(DONE);
#ifdef STXXL_BOOST_THREADS
boost::mutex::scoped_lock Lock(waiters_mutex);
#else
waiters_mutex.lock ();
#endif
// << notification >>
#ifdef __MCSTL__
std::for_each(
waiters.begin(),
waiters.end(),
std::mem_fun(&onoff_switch::on),
mcstl::sequential_tag());
#else
std::for_each(
waiters.begin(),
waiters.end(),
std::mem_fun(&onoff_switch::on) );
#endif
#ifdef STXXL_BOOST_THREADS
Lock.unlock();
#else
waiters_mutex.unlock ();
#endif
completed ();
_state.set_to (READY2DIE);
}
request_ptr syscall_file::aread (
void *buffer,
stxxl::int64 pos,
size_t bytes,
completion_handler on_cmpl)
{
request_ptr req = new syscall_request(this,
buffer, pos, bytes,
request::READ, on_cmpl);
if(!req.get())
stxxl_function_error(io_error);
#ifndef NO_OVERLAPPING
disk_queues::get_instance ()->add_readreq(req,get_id());
#endif
return req;
};
request_ptr syscall_file::awrite (
void *buffer,
stxxl::int64 pos,
size_t bytes,
completion_handler on_cmpl)
{
request_ptr req = new syscall_request(this, buffer, pos, bytes,
request::WRITE, on_cmpl);
if(!req.get())
stxxl_function_error(io_error);
#ifndef NO_OVERLAPPING
disk_queues::get_instance ()->add_writereq(req,get_id());
#endif
return req;
}
__STXXL_END_NAMESPACE