00001 /* -*- Mode: c++ -*- */ 00002 /* 00003 * Copyright 2001 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 * Boston, MA 02111-1307, USA. 00021 */ 00022 /* 00023 * Copyright 1997 Massachusetts Institute of Technology 00024 * 00025 * Permission to use, copy, modify, distribute, and sell this software and its 00026 * documentation for any purpose is hereby granted without fee, provided that 00027 * the above copyright notice appear in all copies and that both that 00028 * copyright notice and this permission notice appear in supporting 00029 * documentation, and that the name of M.I.T. not be used in advertising or 00030 * publicity pertaining to distribution of the software without specific, 00031 * written prior permission. M.I.T. makes no representations about the 00032 * suitability of this software for any purpose. It is provided "as is" 00033 * without express or implied warranty. 00034 * 00035 */ 00036 00037 #ifndef _VRCONNECT_H_ 00038 #define _VRCONNECT_H_ 00039 00040 00041 class VrSigProc; 00042 class VrBuffer; 00043 #include<VrBuffer.h> 00044 00045 class VrConnect { 00046 friend class VrBuffer; 00047 00048 private: 00049 VrBuffer *buffer; 00050 VrSigProc *ds_sigproc; 00051 volatile readerLL *first, *last; 00052 volatile VrSampleIndex lastRP; 00053 MUTEX_DECLARE (mutex); 00054 00055 public: 00056 void attach_reader(readerLL *r,VrSampleIndex nextBlock) { 00057 MUTEX_LOCK(&mutex); 00058 00059 //jca printf("attach_reader[%s] r %x first %x block %lld\n", 00060 // getUpstreamModule()->name(), r, first, nextBlock); 00061 00062 if(first==NULL) { 00063 first=r; 00064 00065 // -eb if work doesn't complete all work, this test isn't valid. 00066 if(0 && PARANOID && lastRP > r->index) { 00067 fprintf(stderr, "Out of order read threads (predicted read VrSampleIndex incorrect).\n"); 00068 abort (); 00069 } 00070 } 00071 else { 00072 last->next=r; 00073 00074 if(PARANOID && last->index > r->index) { 00075 fprintf(stderr, "Out of order read threads.\n"); 00076 abort (); 00077 } 00078 } 00079 00080 last=r; 00081 lastRP=nextBlock; //what's coming up next 00082 MUTEX_UNLOCK(&mutex); 00083 } 00084 00085 void detach_reader(readerLL *r) { 00086 MUTEX_LOCK(&mutex); 00087 if(first==r) { 00088 first=r->next; 00089 if(last==r) { 00090 last=NULL; 00091 // lastRP=r->index; 00092 } 00093 } 00094 else { 00095 readerLL *t= (readerLL *) first; 00096 while(t->next != r) { 00097 t=t->next; 00098 } 00099 t->next=r->next; 00100 if(last==r) { 00101 last = t; 00102 // lastRP=r->index; 00103 //What will the next block from downstream ask for? 00104 } 00105 } 00106 MUTEX_UNLOCK(&mutex); 00107 //jca printf("detach_reader[%s] r %x first %x last %x\n", 00108 // getUpstreamModule()->name(), r, first, last); 00109 } 00110 00111 VrSampleIndex minRP() { 00112 MUTEX_LOCK(&mutex); 00113 VrSampleIndex m=lastRP; 00114 00115 //jca printf("[%s:%d] minRP[%s] m %lld\n", 00116 // __FILE__, __LINE__, getUpstreamModule()->name(), m); 00117 00118 readerLL *t= (readerLL *) first; 00119 00120 while (t) { 00121 00122 //jca printf("[%s:%d] t %x next %x minRP[%s] index %lld\n", 00123 // __FILE__, __LINE__, (int)t, (int)t->next, getUpstreamModule()->name(), t->index); 00124 00125 if (t->index < m) 00126 m = t->index; 00127 t = t->next; 00128 } 00129 00130 MUTEX_UNLOCK(&mutex); 00131 return m; 00132 } 00133 00134 char *getReadPointer(VrSampleRange r) { return buffer->getReadPointer(r); } 00135 00136 VrSigProc *getUpstreamModule() { return buffer->getUpstreamModule(); } 00137 00138 //Make input connector for s reading from buffer b // 00139 VrConnect(VrSigProc*s, VrBuffer* b) : buffer(b), ds_sigproc(s), 00140 first(NULL), last(NULL), lastRP(0) { 00141 MUTEX_INIT(&mutex); 00142 buffer->connect_buffer(this); 00143 } 00144 00145 double connect_getSamplingFrequency() {return buffer->buffer_getSamplingFrequency();} 00146 00147 virtual ~VrConnect() {} 00148 }; 00149 #endif