Changeset 7507
- Timestamp:
- 01/25/08 07:19:32
- Files:
-
- gnuradio/branches/releases/3.1/usrp/host/lib/legacy/circular_buffer.h (modified) (9 diffs)
- gnuradio/branches/releases/3.1/usrp/host/lib/legacy/circular_linked_list.h (modified) (4 diffs)
- gnuradio/branches/releases/3.1/usrp/host/lib/legacy/fusb_darwin.cc (modified) (15 diffs)
- gnuradio/branches/releases/3.1/usrp/host/lib/legacy/mld_threads.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/releases/3.1/usrp/host/lib/legacy/circular_buffer.h
r6152 r7507 27 27 #include <stdexcept> 28 28 29 #ifndef DO_DEBUG 29 30 #define DO_DEBUG 0 31 #endif 30 32 31 33 #if DO_DEBUG … … 83 85 "doWriteBlock = %s, doFullRead = %s\n", d_bufLen_I, 84 86 (d_doWriteBlock ? "true" : "false"), 85 (d_doFullRead ? "true" : "false")) );87 (d_doFullRead ? "true" : "false"));); 86 88 }; 87 89 … … 151 153 DEBUG (fprintf (stderr, "enqueue: buf = %X, bufLen = %ld, #av_wr = %ld, " 152 154 "#av_rd = %ld.\n", (unsigned int)buf, bufLen_I, 153 d_n_avail_write_I, d_n_avail_read_I) );155 d_n_avail_write_I, d_n_avail_read_I);); 154 156 if (bufLen_I > d_bufLen_I) { 155 157 fprintf (stderr, "cannot add buffer longer (%ld" … … 174 176 if (d_doWriteBlock) { 175 177 while (bufLen_I > d_n_avail_write_I) { 176 DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n") );178 DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n");); 177 179 // wait will automatically unlock() the internal mutex 178 180 d_writeBlock->wait (); … … 180 182 if (d_doAbort) { 181 183 d_internal->unlock (); 182 DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n") );184 DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n");); 183 185 return (2); 184 186 } 185 DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n") );187 DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n");); 186 188 } 187 189 } else { 188 190 d_n_avail_read_I = d_bufLen_I - bufLen_I; 189 191 d_n_avail_write_I = bufLen_I; 190 DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n") );192 DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n");); 191 193 retval = -1; 192 194 } … … 234 236 DEBUG (fprintf (stderr, "dequeue: buf = %X, *bufLen = %ld, #av_wr = %ld, " 235 237 "#av_rd = %ld.\n", (unsigned int)buf, *bufLen_I, 236 d_n_avail_write_I, d_n_avail_read_I) );238 d_n_avail_write_I, d_n_avail_read_I);); 237 239 if (!bufLen_I) 238 240 throw std::runtime_error ("circular_buffer::dequeue(): " … … 258 260 if (d_doFullRead) { 259 261 while (d_n_avail_read_I < l_bufLen_I) { 260 DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n") );262 DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n");); 261 263 // wait will automatically unlock() the internal mutex 262 264 d_readBlock->wait (); … … 264 266 if (d_doAbort) { 265 267 d_internal->unlock (); 266 DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n") );268 DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n");); 267 269 return (2); 268 270 } 269 DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n") );271 DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n");); 270 272 } 271 273 } else { 272 274 while (d_n_avail_read_I == 0) { 273 DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n") );275 DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n");); 274 276 // wait will automatically unlock() the internal mutex 275 277 d_readBlock->wait (); … … 277 279 if (d_doAbort) { 278 280 d_internal->unlock (); 279 DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n") );281 DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n");); 280 282 return (2); 281 283 } 282 DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n") );284 DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n");); 283 285 } 284 286 } gnuradio/branches/releases/3.1/usrp/host/lib/legacy/circular_linked_list.h
r6152 r7507 28 28 29 29 #define __INLINE__ inline 30 31 #ifndef DO_DEBUG 30 32 #define DO_DEBUG 0 33 #endif 31 34 32 35 #if DO_DEBUG … … 169 172 // find an available node 170 173 s_node_ptr l_node = d_available; 171 DEBUG (fprintf (stderr, "w ") );174 DEBUG (fprintf (stderr, "w ");); 172 175 while (! l_node) { 173 DEBUG (fprintf (stderr, "x\n") );176 DEBUG (fprintf (stderr, "x\n");); 174 177 // the ioBlock condition will automatically unlock() d_internal 175 178 d_ioBlock->wait (); 176 179 // and lock() is here 177 DEBUG (fprintf (stderr, "y\n") );180 DEBUG (fprintf (stderr, "y\n");); 178 181 l_node = d_available; 179 182 } 180 183 DEBUG (fprintf (stderr, "::f_n_a_n: #u = %ld, node = %p\n", 181 num_used(), l_node) );184 num_used(), l_node);); 182 185 // remove this one from the current available list 183 186 if (num_available () == 1) { … … 202 205 d_internal->lock (); 203 206 DEBUG (fprintf (stderr, "::m_n_a: #u = %ld, node = %p\n", 204 num_used(), l_node) );207 num_used(), l_node);); 205 208 // remove this node from the inUse list 206 209 if (num_used () == 1) { … … 217 220 d_n_used--; 218 221 219 DEBUG (fprintf (stderr, "s%ld ", d_n_used) );222 DEBUG (fprintf (stderr, "s%ld ", d_n_used);); 220 223 // signal the condition when new data arrives 221 224 d_ioBlock->signal (); 222 DEBUG (fprintf (stderr, "t ") );225 DEBUG (fprintf (stderr, "t ");); 223 226 224 227 // unlock the mutex for thread safety gnuradio/branches/releases/3.1/usrp/host/lib/legacy/fusb_darwin.cc
r6152 r7507 28 28 // but rather Darwin's pthreads 29 29 #define _USE_OMNI_THREADS_ 30 #define DO_DEBUG 0 30 31 31 32 #include <usb.h> … … 191 192 number, interval, maxPacketSize); 192 193 193 // set global start boolean194 // set global start boolean 194 195 d_started = true; 195 196 196 // create the run thread, which allows OSX to process I/O separately 197 // lock the runBlock mutex, before creating the run thread. 198 // this guarantees that we can control execution between these 2 threads 199 d_runBlock->mutex ()->lock (); 200 201 // create the run thread, which allows OSX to process I/O separately 197 202 d_runThread = new mld_thread (run_thread, this); 198 203 199 // wait until the threads are -really- going 204 // wait until the run thread (and possibky read thread) are -really- 205 // going; this will unlock the mutex before waiting for a signal () 200 206 d_runBlock->wait (); 201 207 … … 211 217 { 212 218 fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(arg); 219 220 // lock the run thread running mutex; if ::stop() is called, it will 221 // first abort() the pipe then wait for the run thread to finish, 222 // via a lock() on this mutex 213 223 mld_mutex_ptr l_runThreadRunning = This->d_runThreadRunning; 214 224 l_runThreadRunning->lock (); … … 216 226 mld_mutex_ptr l_readRunning = This->d_readRunning; 217 227 mld_condition_ptr l_readBlock = This->d_readBlock; 228 mld_mutex_ptr l_readBlock_mutex = l_readBlock->mutex (); 218 229 219 230 bool l_input_p = This->d_input_p; … … 238 249 239 250 if (l_input_p) { 251 // lock the readBlock mutex, before creating the read thread. 252 // this guarantees that we can control execution between these 2 threads 253 l_readBlock_mutex->lock (); 254 // create the read thread, which just issues all of the starting 255 // async read commands, then returns 240 256 l_rwThread = new mld_thread (read_thread, arg); 241 // wait until the the rwThread is -really- going 257 // wait until the the read thread is -really- going; this will 258 // unlock the read block mutex before waiting for a signal () 242 259 l_readBlock->wait (); 243 260 } 244 261 245 // now signal the run condition to release and finish ::start() 262 // now signal the run condition to release and finish ::start(). 263 264 // lock the runBlock mutex first; this will force waiting until the 265 // ->wait() command is issued in ::start() 266 mld_mutex_ptr l_run_block_mutex = This->d_runBlock->mutex (); 267 l_run_block_mutex->lock (); 268 269 // now that the lock is in place, signal the parent thread that 270 // things are running 246 271 This->d_runBlock->signal (); 247 272 248 // run the loop 273 // release the run_block mutex, just in case 274 l_run_block_mutex->unlock (); 275 276 // run the loop 249 277 CFRunLoopRun (); 250 278 251 279 if (l_input_p) { 252 // wait for read_thread () to finish 280 // wait for read_thread () to finish, if needed 253 281 l_readRunning->lock (); 254 282 l_readRunning->unlock (); 255 283 } 256 284 257 // remove run loop stuff285 // remove run loop stuff 258 286 CFRunLoopRemoveSource (CFRunLoopGetCurrent (), 259 287 l_cfSource, kCFRunLoopDefaultMode); … … 263 291 l_input_p ? "read" : "write"); 264 292 293 // release the run thread running mutex 265 294 l_runThreadRunning->unlock (); 266 295 } … … 274 303 fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(arg); 275 304 305 // before doing anything else, lock the read running mutex. this 306 // mutex does flow control between this thread and the run_thread 276 307 mld_mutex_ptr l_readRunning = This->d_readRunning; 277 308 l_readRunning->lock (); 278 309 279 // signal the read condition from run_thread() to continue 310 // signal the read condition from run_thread() to continue 311 312 // lock the readBlock mutex first; this will force waiting until the 313 // ->wait() command is issued in ::run_thread() 280 314 mld_condition_ptr l_readBlock = This->d_readBlock; 315 mld_mutex_ptr l_read_block_mutex = l_readBlock->mutex (); 316 l_read_block_mutex->lock (); 317 318 // now that the lock is in place, signal the parent thread that 319 // things are running here 281 320 l_readBlock->signal (); 282 321 322 // release the run_block mutex, just in case 323 l_read_block_mutex->unlock (); 324 325 // queue up all of the available read requests 283 326 s_queue_ptr l_queue = This->d_queue; 284 327 l_queue->iterate_start (); … … 292 335 fprintf (stderr, "fusb_ephandle_darwin::read_thread: finished.\n"); 293 336 337 // release the read running mutex, to let the parent thread knows 338 // that this thread is finished 294 339 l_readRunning->unlock (); 295 340 } … … 298 343 fusb_ephandle_darwin::read_issue (s_both_ptr l_both) 299 344 { 300 if ((! l_both) || (! d_started)) 345 if ((! l_both) || (! d_started)) { 346 if (usb_debug > 4) 347 fprintf (stderr, "fusb_ephandle_darwin::read_issue: Doing nothing; " 348 "l_both is %X; started is %s\n", (unsigned int) l_both, 349 d_started ? "TRUE" : "FALSE"); 301 350 return; 351 } 302 352 303 353 // set the node and buffer from the input "both" … … 329 379 d_transferType == kUSBInterrupt ? "" : "TO", 330 380 darwin_error_str (result)); 381 else if (usb_debug > 4) 382 fprintf (stderr, "fusb_ephandle_darwin::read_issue: " 383 "Queued %X (%ld Bytes)\n", (unsigned int) l_both, bufLen); 331 384 } 332 385 … … 348 401 "Expected %ld bytes; read %ld.\n", 349 402 l_i_size, l_size); 403 else if (usb_debug > 4) 404 fprintf (stderr, "fusb_ephandle_darwin::read_completed: " 405 "Read %X (%ld bytes)\n", 406 (unsigned int) l_both, l_size); 350 407 351 408 // add this read to the transfer buffer … … 379 436 UInt32 l_nbytes = (UInt32) nbytes; 380 437 381 if (! d_started) return (0); 438 if (! d_started) { 439 if (usb_debug) 440 fprintf (stderr, "fusb_ephandle_darwin::write: Not yet started.\n"); 441 442 return (0); 443 } 382 444 383 445 while (l_nbytes != 0) { … … 401 463 /* This is an interrupt pipe ... can't specify a timeout. */ 402 464 result = d_interface->WritePipeAsync 403 (d_interfaceRef, d_pipeRef, v_buffer, l_nbytes,465 (d_interfaceRef, d_pipeRef, v_buffer, t_nbytes, 404 466 (IOAsyncCallback1) write_completed, (void*) l_both); 405 467 else 406 468 result = d_interface->WritePipeAsyncTO 407 (d_interfaceRef, d_pipeRef, v_buffer, l_nbytes, 0, USB_TIMEOUT,469 (d_interfaceRef, d_pipeRef, v_buffer, t_nbytes, 0, USB_TIMEOUT, 408 470 (IOAsyncCallback1) write_completed, (void*) l_both); 409 471 … … 414 476 d_transferType == kUSBInterrupt ? "" : "TO", 415 477 darwin_error_str (result)); 478 else if (usb_debug > 4) { 479 fprintf (stderr, "fusb_ephandle_darwin::write_thread: " 480 "Queued %X (%ld Bytes)\n", (unsigned int) l_both, t_nbytes); 481 } 416 482 l_nbytes -= t_nbytes; 417 483 } … … 437 503 "Expected %ld bytes written; wrote %ld.\n", 438 504 l_i_size, l_size); 505 else if (usb_debug > 4) 506 fprintf (stderr, "fusb_ephandle_darwin::write_completed: " 507 "Wrote %X (%ld Bytes)\n", (unsigned int) l_both, l_size); 439 508 440 509 // set buffer's # data to 0 gnuradio/branches/releases/3.1/usrp/host/lib/legacy/mld_threads.h
r6152 r7507 38 38 39 39 #define __INLINE__ inline 40 41 #ifndef DO_DEBUG 40 42 #define DO_DEBUG 0 43 #endif 41 44 42 45 #if DO_DEBUG … … 183 186 184 187 __INLINE__ void signal () { 185 DEBUG (fprintf (stderr, "a ") );188 DEBUG (fprintf (stderr, "a ");); 186 189 187 190 #ifdef _USE_OMNI_THREADS_ … … 194 197 } 195 198 #endif 196 DEBUG (fprintf (stderr, "b ") );199 DEBUG (fprintf (stderr, "b ");); 197 200 }; 198 201 199 202 __INLINE__ void wait () { 200 DEBUG (fprintf (stderr, "c ") );203 DEBUG (fprintf (stderr, "c ");); 201 204 #ifdef _USE_OMNI_THREADS_ 202 205 d_condition->wait (); … … 208 211 } 209 212 #endif 210 DEBUG ( printf (stderr, "d "));213 DEBUG (fprintf (stderr, "d ");); 211 214 }; 212 215 };
