25 #if FOXXLL_MSVC >= 1700 && FOXXLL_MSVC <= 1800 29 #ifndef FOXXLL_CHECK_FOR_PENDING_REQUESTS_ON_SUBMISSION 30 #define FOXXLL_CHECK_FOR_PENDING_REQUESTS_ON_SUBMISSION 1 35 struct file_offset_match
36 :
public std::binary_function<request_ptr, request_ptr, bool>
43 return (a->offset() == b->offset()) &&
44 (a->get_file() == b->get_file());
49 : thread_state_(NOT_RUNNING), sem_(0)
67 if (!dynamic_cast<serving_request*>(req.
get()))
68 TLX_LOG1 <<
"Incompatible request submitted to running queue.";
72 #if FOXXLL_CHECK_FOR_PENDING_REQUESTS_ON_SUBMISSION 77 bind2nd(file_offset_match(), req)
81 TLX_LOG1 <<
"READ request submitted for a BID with a pending WRITE request";
90 #if FOXXLL_CHECK_FOR_PENDING_REQUESTS_ON_SUBMISSION 95 bind2nd(file_offset_match(), req)
99 TLX_LOG1 <<
"WRITE request submitted for a BID with a pending READ request";
116 if (!dynamic_cast<serving_request*>(req.
get()))
117 TLX_LOG1 <<
"Incompatible request submitted to running queue.";
119 bool was_still_in_queue =
false;
123 queue_type::iterator pos
128 was_still_in_queue =
true;
136 queue_type::iterator pos
141 was_still_in_queue =
true;
147 return was_still_in_queue;
157 self* pthis =
static_cast<self*
>(arg);
159 bool write_phase =
true;
166 std::unique_lock<std::mutex> write_lock(pthis->write_mutex_);
167 if (!pthis->write_queue_.empty())
170 pthis->write_queue_.pop_front();
181 pthis->sem_.signal();
183 if (pthis->priority_op_ ==
WRITE)
187 if (pthis->priority_op_ ==
NONE || pthis->priority_op_ ==
READ)
192 std::unique_lock<std::mutex> read_lock(pthis->read_mutex_);
194 if (!pthis->read_queue_.empty())
197 pthis->read_queue_.pop_front();
201 TLX_LOG <<
"queue: before serve request has " 202 << req->reference_count() <<
" references ";
205 TLX_LOG <<
"queue: after serve request has " 206 << req->reference_count() <<
" references ";
212 pthis->sem_.signal();
214 if (pthis->priority_op_ ==
READ)
218 if (pthis->priority_op_ ==
NONE || pthis->priority_op_ ==
WRITE)
224 if (pthis->sem_.wait() == 0)
227 pthis->sem_.signal();
233 #if FOXXLL_MSVC >= 1700 && FOXXLL_MSVC <= 1800
#define FOXXLL_THROW_INVALID_ARGUMENT(error_message)
Throws std::invalid_argument with "Error in [function] : [error_message]".
tlx::counting_ptr< request > request_ptr
A reference counting pointer for request.
static void * worker(void *arg)
void add_request(request_ptr &req) final
Type * get() const noexcept
return the enclosed pointer.
void set_priority_op(const priority_op &op) final
size_t wait(size_t delta=1, size_t slack=0)
void stop_thread(std::thread &t, shared_state< thread_state > &s, tlx::semaphore &sem)
High-performance smart pointer used as a wrapping reference counting pointer.
bool cancel_request(request_ptr &req) final
~request_queue_impl_qwqr()
Request which serves an I/O by calling the synchronous routine of the file.
bool empty() const noexcept
test for a nullptr pointer
shared_state< thread_state > thread_state_
void start_thread(void *(*worker)(void *), void *arg, std::thread &t, shared_state< thread_state > &s)
request_queue_impl_qwqr(int n=1)
#define TLX_LOG
Default logging method: output if the local debug variable is true.