BitMap Storage::BuildBitmap(UINT maxLength) const { LIVE_ASSERT(maxLength > 0); if (IsEmpty()) return BitMap(); UINT minIndex = GetMinIndex(); UINT maxIndex = GetMaxIndex(); if ((minIndex == 0) && (maxIndex == 0)) return BitMap(); LIVE_ASSERT(minIndex > 0); LIVE_ASSERT(minIndex <= maxIndex); UINT length = maxIndex - minIndex + 1; LIMIT_MAX(length, maxLength); maxIndex = minIndex + length - 1; const PieceInfoCollection& pieceColl = m_dataPieces; PieceInfoCollection::const_iterator BeginItr = pieceColl.find(minIndex); PieceInfoCollection::const_iterator EndItr = pieceColl.upper_bound(maxIndex); BitMap bitmap(minIndex, length); //2.生成Bitmap for (PieceInfoCollection::const_iterator itr = BeginItr; itr != EndItr; itr++ ) { LIVE_ASSERT(bitmap.IsInRange(itr->first)); bitmap.SetBit(itr->first); } return bitmap; }
BitMap Storage::BuildBitmap() const { if (m_dataPieces.empty()) return BitMap(); UINT minIndex = GetMinIndex(); UINT maxIndex = GetMaxIndex(); if ((minIndex == 0) && (maxIndex == 0)) return BitMap(); LIVE_ASSERT(minIndex > 0); LIVE_ASSERT(minIndex <= maxIndex); UINT length = maxIndex - minIndex + 1; const PieceInfoCollection& pieceColl = m_dataPieces; PieceInfoCollection::const_iterator BeginItr = pieceColl.find(minIndex); PieceInfoCollection::const_iterator EndItr = pieceColl.find(maxIndex); BitMap bitmap(minIndex, length); // for(int i = 0; i < length; i ++ ) // { // bitmap.SetBit(minIndex + i); // } //2.生成Bitmap for (PieceInfoCollection::const_iterator itr = BeginItr; itr != EndItr; itr++ ) { LIVE_ASSERT(bitmap.IsInRange(itr->first)); bitmap.SetBit(itr->first); } return bitmap; }
size_t Storage::RemoveExpired(const StreamIndicator& baseIndicator, UINT minBufferTime) { UINT64 elapsedTime = baseIndicator.GetElapsedTime(); LIVE_ASSERT(elapsedTime <= INT_MAX); if (elapsedTime <= minBufferTime) { return 0; } elapsedTime -= minBufferTime; size_t deletedCount = 0; PieceInfoCollection::iterator iter = m_dataPieces.begin(); while (iter != m_dataPieces.end()) { if (m_dataPieces.size() <= 1) break; MediaDataPiecePtr piece = iter->second.GetPiece(); CheckDataPiece(piece); UINT pieceIndex = iter->first; // 可能删掉upperBound对应的piece //LIVE_ASSERT(pieceIndex < upperBound); // 如果upperBound以后一直没有数据,或者距离很远才遇到下一片,则可能会发生upperBound对应的片也过时的情况 if (pieceIndex >= baseIndicator.GetPieceIndex()) { // peer端的BaseIndex不一定是最小的,需要加以检查 LIVE_ASSERT( piece->GetTimeStamp() >= baseIndicator.GetTimeStamp() ); UINT64 elapsedTimeStamp = piece->GetTimeStamp() - baseIndicator.GetTimeStamp(); if (elapsedTimeStamp >= elapsedTime) { SOURCENEW_DEBUG("推进 MinIndex="<<GetMinIndex()<<" MaxIndex="<<GetMaxIndex()<<" 推进时间戳="<<elapsedTime); break; } } // piece过期,删除之 STREAMBUFFER_WARN("Storage::RemoveExpired: " << make_tuple(pieceIndex, baseIndicator.GetPieceIndex())); DoDelete(iter++); ++deletedCount; } while (m_dataPieces.size() > STORAGE_PIECE_LIMIT) { DoDelete(m_dataPieces.begin()); } //m_unfinishedDataPieces.RemoveOld(GetMinIndex()); return deletedCount; }
void Storage::ViewStreamBuffer() const { VIEW_INFO("Storage::ViewStreamBuffer - LocalBitmap " << GetMinIndex() << " " << GetMaxIndex() << " " << BuildBitmap().GetResourceString() << " End"); }
UINT Storage::GetBufferSize() const { if (m_dataPieces.empty()) return 0; return GetMaxIndex() - GetMinIndex() + 1; }
int Schedule(const ReadCircuit &readCircuit, int64_t no_core, int64_t **core) { const vector<ReadGate>& G = readCircuit.gate_list; int64_t no_task; int64_t input_size = readCircuit.g_init_size + readCircuit.e_init_size + readCircuit.g_input_size + readCircuit.e_input_size; int64_t no_of_input_dff = input_size + readCircuit.dff_size; no_task = readCircuit.gate_size; int64_t *index; index = new int64_t[no_task]; TopSort(G, no_task, index); // start of scheduling int64_t *p0, *p1, *core_busy, *core_index; p0 = new int64_t[no_task]; memset(p0, -1, no_task * sizeof(int64_t)); p1 = new int64_t[no_task]; memset(p1, -1, no_task * sizeof(int64_t)); core_index = new int64_t[no_core]; memset(core_index, 0, no_core * sizeof(int64_t)); core_busy = new int64_t[no_core]; memset(core_busy, 0, no_core * sizeof(int64_t)); int64_t scheduled = 0; while (scheduled < no_task) { for (int64_t i = 0; i < no_task; i++) { if (p0[index[i]] == ((int64_t)-1)) // not assigned yet { if (((G[index[i]].input[0] - no_of_input_dff < 0) || (p0[G[index[i]].input[0] - no_of_input_dff] != int64_t(-1)))) { if ((G[index[i]].input[1] - no_of_input_dff < 0) || (p0[G[index[i]].input[1] - no_of_input_dff] != int64_t(-1))) //ready { p1[index[i]] = GetMinIndex(core_busy, no_core); core[p1[index[i]]][core_index[p1[index[i]]]] = index[i]; core_index[p1[index[i]]]++; core_busy[p1[index[i]]] = core_busy[p1[index[i]]] + 1; scheduled++; } } } } for (int64_t i = 0; i < no_task; i++) { p0[i] = p1[i]; } } delete[] index; delete[] p0; delete[] p1; delete[] core_index; delete[] core_busy; return SUCCESS; }