在if语句外定义了ed,赋值为m_eventInputManager->getById(ticket)的返回值,如果未找到对应的Event Descriptor,则返回EventInputManager::EIM_MAYCOME或者EventInputManager::EIM_NEVERTOCOME。 在if语句内也定义了ed, 赋值为m_eventInputManager->getEventDescriptor(mem_page)返回值,这是根据造的空数据的内存内存地址得到对应的event descriptor,并修改该ED的值为ticket,然后根据ticket将该ed放进对应的List。 但是if语句里有对丢失数据的状态判断,这应该是用到的if外的ed值。在if语句重新定义ed后,覆盖了该if外的ed值,???此处是不是有bug? 178 /**************************************************************/ 179 ROS::EventFragment* PCMemoryDataChannel::getFragment(int ticket) 180 /**************************************************************/ 181 { 182 evDesc_t *ed; 183 MemoryPage *mem_page; 184 EventFragment *fragment=0; 185 186 DEBUG_TEXT(DFDB_ROSFM, 10, "PCMemoryDataChannel::getFragment: fragment with L1ID " << ticket << " requested"); 187 // protect EIM and fast allocate with same mutex 188 m_mutex->lock(); 189 190 //Find the requested event 191 ed = m_eventInputManager->getById(ticket); 192 193 if (m_fragType == 0) 194 { 195 DEBUG_TEXT(DFDB_ROSFM, 10, "PCMemoryDataChannel::getFragment: processing ROB fragment"); 196 if((intptr_t)ed == EventInputManager::EIM_MAYCOME || (intptr_t)ed == EventInputManager::EIM_NEVERTOCOME) 197 { 198 DEBUG_TEXT(DFDB_ROSFM, 8, "EIM_MAYCOME || EIM_NEVERTOCOME " << ticket << "ed:" << ed <<std::endl); 199 try 200 { 201 fragment = new ROBFragment(m_memoryPool, ticket, m_sourceIdentifier, 0); //create an empty ROB fragment 202 Buffer *mem_buffer = fragment->buffer(); //get the Buffer of the ROB fragment 203 Buffer::page_iterator mem_page_i = mem_buffer->begin(); 204 MemoryPage *mem_page = const_cast<MemoryPage *>(*mem_page_i); //get the memory page of the buffer 205 mem_page->lock(); 206 207 evDesc_t *ed = m_eventInputManager->getEventDescriptor(mem_page); //get a pointer to the event descriptor 208 ed->L1id = ticket; //set the L1ID 209 m_eventInputManager->createEvent(ed); //Insert the event into the Event Input Manager 210 211 if ((intptr_t)ed == EventInputManager::EIM_MAYCOME) 212 { 213 m_statistics->fragmentsMissed++; 214 fragment->setStatus(EventFragment::STATUS_MAYCOME); 215 DEBUG_TEXT(DFDB_ROSFM, 8, "PCMemoryDataChannel::getFragment: Fragment for L1ID " << ticket << " has not yet arrived"); 216 } 217 218 if ((intptr_t)ed == EventInputManager::EIM_NEVERTOCOME) 219 { 220 m_statistics->fragmentsLost++; 221 fragment->setStatus(EventFragment::STATUS_LOST); 222 DEBUG_TEXT(DFDB_ROSFM, 8, "PCMemoryDataChannel::getFragment: Fragment for L1ID " << ticket << " does not exist"); 223 CREATE_ROS_EXCEPTION(ex1, CoreException, PCMEMCHAN_LOST, "\n L1ID = " << ticket << ", ROL physical addr = " << physicalAddr ess()); 224 ers::warning(ex1); 225 } 226 } 227 catch (EventFragmentException& e) 228 { 229 DEBUG_TEXT(DFDB_ROSFM, 8, "PCMemoryDataChannel::getFragment:EventFragmentException"); 230 DEBUG_TEXT(DFDB_ROSFM, 5, e); 231 m_mutex->unlock(); 232 throw e; 233 } 234 m_mutex->unlock(); 235 return(fragment); 236 } 237 } 238 239 if (m_fragType == 1) 240 { 241 DEBUG_TEXT(DFDB_ROSFM, 10, "PCMemoryDataChannel::getFragment: processing full fragment"); 242 if ((intptr_t)ed == EventInputManager::EIM_MAYCOME || (intptr_t)ed == EventInputManager::EIM_NEVERTOCOME) 243 { 244 DEBUG_TEXT(DFDB_ROSFM, 5, "PCMemoryDataChannel::getFragment: Fragment for L1ID " << ticket << " is not available"); 245 CREATE_ROS_EXCEPTION(ex1, CoreException, NODATA, "L1ID = " << ticket << ", ROL physical addr = " << physicalAddress()); 246 throw(ex1); 247 } 248 } 249 250 m_statistics->fragmentsServed++; 251 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: getById returns " << HEX(ed)); 252 mem_page = ed->myPage; 253 254 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: Dumping fields of this event descriptor:"); 255 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: Address of memory page = " << std::hex << mem_page << std::dec); 256 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: Fragment size (bytes) = " << ed->RODFragmentSize); 257 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: Fragment status = " << ed->RODFragmentStatus); 258 259 if (m_fragType == 0) 260 { 261 //<+gumh: add time 262 //u_long base = (u_long)(mem_page->address()) ; 263 //u_int *ptr = (u_int *)(base + sizeof(ROBFragment::ROBHeader) + sizeof(RODFragment::RODHeader) + 4 + sizeof(timeval)); // 4 -> status element 264 //struct timeval tv ; 265 //gettimeofday(&tv, NULL) ; 266 //memcpy(ptr, &tv, sizeof(timeval)) ; 267 268 //u_int *ptr = (u_int *)(base + sizeof(ROBFragment::ROBHeader) + sizeof(RODFragment::RODHeader) + 4 + sizeof(timeval)); // 4 -> status element 269 //+> 270 271 //Create a ROB Fragment in the Buffer and initialize it 272 fragment = new ROBFragment(mem_page, ed->RODFragmentSize, 0, m_sourceIdentifier); 273 } 274 275 if (m_fragType == 1) 276 { 277 //Create a Full Fragment in the Buffer 278 fragment = new FullFragment(mem_page); 279 DEBUG_TEXT(DFDB_ROSFM, 20, "PCMemoryDataChannel::getFragment: Full fragment is at " << HEX(fragment)); 280 } 281 282 m_mutex->unlock(); 283 284 DEBUG_TEXT(DFDB_ROSFM, 10, "PCMemoryDataChannel::getFragment: PCMemoryDataChannel:: got fragment with L1ID " << ticket); 285 DEBUG_TEXT(DFDB_ROSFM, 15, "PCMemoryDataChannel::getFragment: done"); 286 287 return(fragment); 288 }
时间: 2024-10-10 14:35:19