comparison data/fileio/FileReadThread.cpp @ 742:c10cb8782576 coreaudio_tests

Merge from branch "default"
author Chris Cannam
date Sun, 01 Jul 2012 11:53:00 +0100
parents 1424aa29ae95
children e802e550a1f2
comparison
equal deleted inserted replaced
666:4efa7429cd85 742:c10cb8782576
18 #include "base/Profiler.h" 18 #include "base/Profiler.h"
19 #include "base/Thread.h" 19 #include "base/Thread.h"
20 20
21 #include <iostream> 21 #include <iostream>
22 #include <unistd.h> 22 #include <unistd.h>
23 #include <cstdio>
23 24
24 //#define DEBUG_FILE_READ_THREAD 1 25 //#define DEBUG_FILE_READ_THREAD 1
25 26
26 FileReadThread::FileReadThread() : 27 FileReadThread::FileReadThread() :
27 m_nextToken(0), 28 m_nextToken(0),
44 } 45 }
45 46
46 notifyCancelled(); 47 notifyCancelled();
47 48
48 #ifdef DEBUG_FILE_READ_THREAD 49 #ifdef DEBUG_FILE_READ_THREAD
49 std::cerr << "FileReadThread::run() exiting" << std::endl; 50 SVDEBUG << "FileReadThread::run() exiting" << endl;
50 #endif 51 #endif
51 } 52 }
52 53
53 void 54 void
54 FileReadThread::finish() 55 FileReadThread::finish()
55 { 56 {
56 #ifdef DEBUG_FILE_READ_THREAD 57 #ifdef DEBUG_FILE_READ_THREAD
57 std::cerr << "FileReadThread::finish()" << std::endl; 58 SVDEBUG << "FileReadThread::finish()" << endl;
58 #endif 59 #endif
59 60
60 { 61 {
61 MutexLocker locker(&m_mutex, "FileReadThread::finish::m_mutex"); 62 MutexLocker locker(&m_mutex, "FileReadThread::finish::m_mutex");
62 63
70 } 71 }
71 72
72 m_condition.wakeAll(); 73 m_condition.wakeAll();
73 74
74 #ifdef DEBUG_FILE_READ_THREAD 75 #ifdef DEBUG_FILE_READ_THREAD
75 std::cerr << "FileReadThread::finish() exiting" << std::endl; 76 SVDEBUG << "FileReadThread::finish() exiting" << endl;
76 #endif 77 #endif
77 } 78 }
78 79
79 int 80 int
80 FileReadThread::request(const Request &request) 81 FileReadThread::request(const Request &request)
110 std::cerr << "WARNING: FileReadThread::cancel: token " << token << " not found" << std::endl; 111 std::cerr << "WARNING: FileReadThread::cancel: token " << token << " not found" << std::endl;
111 } 112 }
112 } 113 }
113 114
114 #ifdef DEBUG_FILE_READ_THREAD 115 #ifdef DEBUG_FILE_READ_THREAD
115 std::cerr << "FileReadThread::cancel(" << token << ") waking condition" << std::endl; 116 SVDEBUG << "FileReadThread::cancel(" << token << ") waking condition" << endl;
116 #endif 117 #endif
117 118
118 m_condition.wakeAll(); 119 m_condition.wakeAll();
119 } 120 }
120 121
213 Request request = m_queue.begin()->second; 214 Request request = m_queue.begin()->second;
214 215
215 m_mutex.unlock(); 216 m_mutex.unlock();
216 217
217 #ifdef DEBUG_FILE_READ_THREAD 218 #ifdef DEBUG_FILE_READ_THREAD
218 std::cerr << "FileReadThread::process: reading " << request.start << ", " << request.size << " on " << request.fd << std::endl; 219 SVDEBUG << "FileReadThread::process: reading " << request.start << ", " << request.size << " on " << request.fd << endl;
219 #endif 220 #endif
220 221
221 bool successful = false; 222 bool successful = false;
222 bool seekFailed = false; 223 bool seekFailed = false;
223 ssize_t r = 0; 224 ssize_t r = 0;
286 287
287 if (m_queue.find(token) != m_queue.end() && !m_exiting) { 288 if (m_queue.find(token) != m_queue.end() && !m_exiting) {
288 m_queue.erase(token); 289 m_queue.erase(token);
289 m_readyRequests[token] = request; 290 m_readyRequests[token] = request;
290 #ifdef DEBUG_FILE_READ_THREAD 291 #ifdef DEBUG_FILE_READ_THREAD
291 std::cerr << "FileReadThread::process: done, marking as ready (success = " << m_readyRequests[token].successful << ")" << std::endl; 292 SVDEBUG << "FileReadThread::process: done, marking as ready (success = " << m_readyRequests[token].successful << ")" << endl;
292 #endif 293 #endif
293 } else { 294 } else {
294 #ifdef DEBUG_FILE_READ_THREAD 295 #ifdef DEBUG_FILE_READ_THREAD
295 if (m_exiting) { 296 if (m_exiting) {
296 std::cerr << "FileReadThread::process: exiting" << std::endl; 297 SVDEBUG << "FileReadThread::process: exiting" << endl;
297 } else { 298 } else {
298 std::cerr << "FileReadThread::process: request disappeared" << std::endl; 299 SVDEBUG << "FileReadThread::process: request disappeared" << endl;
299 } 300 }
300 #endif 301 #endif
301 } 302 }
302 } 303 }
303 304
309 while (!m_newlyCancelled.empty()) { 310 while (!m_newlyCancelled.empty()) {
310 311
311 int token = *m_newlyCancelled.begin(); 312 int token = *m_newlyCancelled.begin();
312 313
313 #ifdef DEBUG_FILE_READ_THREAD 314 #ifdef DEBUG_FILE_READ_THREAD
314 std::cerr << "FileReadThread::notifyCancelled: token " << token << std::endl; 315 SVDEBUG << "FileReadThread::notifyCancelled: token " << token << endl;
315 #endif 316 #endif
316 317
317 m_newlyCancelled.erase(token); 318 m_newlyCancelled.erase(token);
318 } 319 }
319 } 320 }