CARingBufferError CARingBuffer::Store(const AudioBufferList *abl, UInt32 framesToWrite, SampleTime startWrite) { if (framesToWrite > mCapacityFrames) return kCARingBufferError_TooMuch; // too big! SampleTime endWrite = startWrite + framesToWrite; if (startWrite < EndTime()) { // going backwards, throw everything out SetTimeBounds(startWrite, startWrite); } else if (endWrite - StartTime() <= mCapacityFrames) { // the buffer has not yet wrapped and will not need to } else { // advance the start time past the region we are about to overwrite SampleTime newStart = endWrite - mCapacityFrames; // one buffer of time behind where we're writing SampleTime newEnd = std::max(newStart, EndTime()); SetTimeBounds(newStart, newEnd); } // write the new frames Byte **buffers = mBuffers; int nchannels = mNumberChannels; int offset0, offset1, nbytes; SampleTime curEnd = EndTime(); if (startWrite > curEnd) { // we are skipping some samples, so zero the range we are skipping offset0 = FrameOffset(curEnd); offset1 = FrameOffset(startWrite); if (offset0 < offset1) ZeroRange(buffers, nchannels, offset0, offset1 - offset0); else { ZeroRange(buffers, nchannels, offset0, mCapacityBytes - offset0); ZeroRange(buffers, nchannels, 0, offset1); } offset0 = offset1; } else { offset0 = FrameOffset(startWrite); } offset1 = FrameOffset(endWrite); if (offset0 < offset1) StoreABL(buffers, offset0, abl, 0, offset1 - offset0); else { nbytes = mCapacityBytes - offset0; StoreABL(buffers, offset0, abl, 0, nbytes); StoreABL(buffers, 0, abl, nbytes, offset1); } // now update the end time SetTimeBounds(StartTime(), endWrite); return kCARingBufferError_OK; // success }
void PrintBoardToFile(int halfsteps, FILE* f) { int x, y; double t; for(y = 0; y < N; y++) { for(x = 0; x < N; x++) { switch(board[y * N + x]) { case BLANK: putc(' ', f); break; case RED: putc('>', f); break; case BLUE: putc('v', f); break; } } fprintf(f, "\n"); } t = EndTime(); fprintf(f, "Arguments: %s| Steps: %d.%d/%d.0 | Max Red: %d%% | Max Blue: %d%% | Time: %lf seconds\n", argsText, halfsteps / 2, halfsteps % 2 * 5, maxFullsteps, maxRedPercent, maxBluePercent, t); fprintf(stdout, "Arguments: %s| Steps: %d.%d/%d.0 | Max Red: %d%% | Max Blue: %d%% | Time: %lf seconds\n", argsText, halfsteps / 2, halfsteps % 2 * 5, maxFullsteps, maxRedPercent, maxBluePercent, t); }
void CBookManageDlg::OnBnClickedDelete() { // TODO: 在此添加控件通知处理程序代码 POSITION pos=m_list.GetFirstSelectedItemPosition(); int row; KeyType key; if(pos!=NULL) { row=(int)m_list.GetNextSelectedItem(pos); if(row>=0&&AfxMessageBox(_T("你确定要删除")+m_list.GetItemText(row,1)+_T("吗?"),MB_ICONEXCLAMATION|MB_OKCANCEL)==IDOK) { key=_ttoi(m_list.GetItemText(row,0)); RunTimer timer; if(tree->DeleteBTree(key)==OK) { EndTime(timer); WriteLog(_T("删除图书")+m_list.GetItemText(row,1)); m_list.DeleteItem(row); AfxMessageBox(_T("删除成功!")); } else { AfxMessageBox(_T("删除失败")); } } } }
void CBookManageDlg::OnBnClickedInsert() { // TODO: 在此添加控件通知处理程序代码 CInputBookDlg dlg; DataType data; if(dlg.DoModal()==IDOK) { data.no=dlg.book_no; data.name=dlg.book_name; data.author=dlg.book_author; data.current_num=data.total_num=dlg.book_num; WriteLog(_T("增加图书")+data.name); //插入到B树 RunTimer timer; if(tree->InsertBTree(data)==OK) { //插入到ListControl EndTime(timer); } else { result res=tree->SearchBTree(data.no); res.pt->key[res.i].current_num+=data.current_num; res.pt->key[res.i].total_num+=data.total_num; AfxMessageBox(_T("已增加数量")); } OnBnClickedReflash(); } }
void CBookManageDlg::OnBnClickedReflash() { // TODO: 在此添加控件通知处理程序代码 m_list.SetRedraw(FALSE); m_list.DeleteAllItems(); RunTimer timer; map.RemoveAll();//也更新哈希表 DisplayList(tree->GetRoot()); EndTime(timer); m_list.SetRedraw(TRUE); }
void *CollectThread(void *args) { struct Handler *handler = (struct Handler *)args; int i = 0; for (i = 0; i < THREAD_NUM; i ++) { pthread_join(t[i], NULL); } EndTime(); PassTime(); LoopStop(handler->loop); }
int JackServer::Close() { jack_log("JackServer::Close"); fChannel.Close(); fAudioDriver->Detach(); fAudioDriver->Close(); fFreewheelDriver->Close(); fEngine->Close(); // TODO: move that in reworked JackServerGlobals::Destroy() JackMessageBuffer::Destroy(); EndTime(); return 0; }
void TestSingleHandler(CuTest *tc) { struct Handler *handler = NewHandler(); CuAssertPtrNotNull(tc, handler); handler->HandleMessage = SingleHandleMessageImpl; struct TestObj obj; obj.context = tc; obj.handler = handler; pthread_t t; pthread_create(&t, NULL, SingleHandlerSub, &obj); LoopStart(handler->loop); EndTime(); PassTime(); }
void TestOldThreadMessage(CuTest *tc) { int id = msgget(IPC_PRIVATE, 0660|IPC_CREAT); static int ret1 = 0; pthread_t t1; pthread_create(&t1, NULL, OldThreadMessageSub, &id); struct msgbuf buf; while (1) { msgrcv(id, &buf, sizeof(int), 0x100, 0); //CuAssertIntEquals(tc, ret1++, buf.mtext); //printf("%d\n", buf.mtext); if (buf.mtext == 0xFFFFE) { break; } } EndTime(); PassTime(); }
bool DataChart::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError) { std::string strType = Std_CheckString(strDataType); if(ActivatedItem::SetData(strDataType, strValue, false)) return true; if(strType == "STARTTIME") { StartTime((float) atof(strValue.c_str())); return true; } if(strType == "ENDTIME") { EndTime((float) atof(strValue.c_str())); return true; } if(strType == "SETSTARTENDTIME") { SetStartEndTime(Std_ToBool(strValue)); return true; } if(strType == "COLLECTTIMEWINDOW") { CollectTimeWindow((float) atof(strValue.c_str())); return true; } if(strType == "COLLECTINTERVAL") { CollectInterval((float) atof(strValue.c_str())); return true; } //If it was not one of those above then we have a problem. if(bThrowError) THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType); return false; }
bool BMAuctionEntry::IsExpired() const { return EndTime() <= std::time(NULL); }
void LogicClient::OnLogin(S2C_Login& msg) { EndTime(C2S_Login::msgid); std::cout << "++Robot[" << _id << "] Login Successed." << std::endl; }
AveragingMSRowProvider::AveragingMSRowProvider(double nWavelengthsAveraging, const string& msPath, const MSSelection& selection, const std::map<size_t, size_t>& selectedDataDescIds, const string& dataColumnName, bool requireModel) : MSRowProvider(msPath, selection, selectedDataDescIds, dataColumnName, requireModel) { casacore::MSAntenna antennaTable(_ms.antenna()); _nAntennae = antennaTable.nrow(); casacore::ROArrayColumn<double> positionColumn(antennaTable, casacore::MSAntenna::columnName(casacore::MSAntennaEnums::POSITION)); std::vector<Pos> positions(_nAntennae); casacore::Array<double> posArr(casacore::IPosition(1, 3)); for(size_t i=0; i!=_nAntennae; ++i) { positionColumn.get(i, posArr); positions[i] = Pos(posArr.data()[0], posArr.data()[1], posArr.data()[2]); } // dataDescId x ant x ant _nElements = selectedDataDescIds.size() * _nAntennae * _nAntennae; _averagingFactors.assign(_nElements, 0.0); _buffers.resize(_nElements); MultiBandData bands(_ms.spectralWindow(), _ms.dataDescription()); double dt = (EndTime() - StartTime()) / (EndTimestep() - StartTimestep()); Logger::Debug << "Assuming integration time of " << dt * (24.0*60.0*60.0) << " seconds.\n"; size_t element = 0; size_t averagingSum = 0, minAvgFactor = std::numeric_limits<size_t>::max(), maxAvgFactor = 0; for(size_t a1=0; a1!=_nAntennae; ++a1) { Pos pos1 = positions[a1]; for(size_t a2=0; a2!=_nAntennae; ++a2) { Pos pos2 = positions[a2]; double dx = std::get<0>(pos1) - std::get<0>(pos2); double dy = std::get<1>(pos1) - std::get<1>(pos2); double dz = std::get<2>(pos1) - std::get<2>(pos2); double dist = sqrt(dx*dx + dy*dy + dz*dz); for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin(); spwIter!=selectedDataDescIds.end(); ++spwIter) { BandData band = bands[spwIter->first]; double lambda = band.SmallestWavelength(); double nWavelengthsPerIntegration = 2.0 * M_PI * dist / lambda * dt; _averagingFactors[element] = std::max<size_t>(size_t(floor(nWavelengthsAveraging / nWavelengthsPerIntegration)), 1); averagingSum += _averagingFactors[element]; if(a1 != a2) { minAvgFactor = std::min<size_t>(minAvgFactor, _averagingFactors[element]); maxAvgFactor = std::max<size_t>(maxAvgFactor, _averagingFactors[element]); } //Logger::Debug << a1 << '\t' << a2 << '\t' << _averagingFactors[element] << '\n'; ++element; } } } Logger::Info << "Averaging factor for longest baseline: " << minAvgFactor << " x . For the shortest: " << maxAvgFactor << " x \n"; _spwIndexToDataDescId.resize(selectedDataDescIds.size()); for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin(); spwIter!=selectedDataDescIds.end(); ++spwIter) { _spwIndexToDataDescId[spwIter->second] = spwIter->first; } _averageFactorSum = 0.0; _rowCount = 0; _averagedRowCount = 0; _currentData = DataArray(DataShape()); _currentModel = DataArray(DataShape()); _currentFlags = FlagArray(DataShape()); _currentWeights = WeightArray(DataShape()); _averagedDataDescId = _currentDataDescId; _flushPosition = 0; if(!MSRowProvider::AtEnd()) { bool timestepAvailable = processCurrentTimestep(); if(!timestepAvailable) NextRow(); } }
// // FUNCTION: DoTimings // // PURPOSE: Calls and times various RPC calls. // (Avoid cluttering up main()) // // PARAMETERS: // Binding - Binding to the server. // iIterations - Number of times to make each call. // // RETURN VALUE: // n/a // // void DoTimings(RPC_BINDING_HANDLE Binding, UINT iIterations) { ULONG mseconds; UINT i; RPC_STATUS status; byte bBuffer[4096]; ULONG lBufferLength; ULONG lBufferSize; // Time Pings() (void calls) StartTime(); for(i = iIterations; i; i--) { status = Ping(Binding); if (status != RPC_S_OK) goto Cleanup; } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - void calls.\n", iIterations, mseconds); // Time [in] buffer's // lBufferLength = BUFFER_SIZE; lBufferSize = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferIn1(Binding, bBuffer, lBufferLength, lBufferSize); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer in (1).\n", iIterations, mseconds); lBufferLength = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferIn3(Binding, bBuffer, lBufferLength); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer in (2).\n", iIterations, mseconds); lBufferLength = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferIn3(Binding, bBuffer, lBufferLength); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer in (3).\n", iIterations, mseconds); // Time [out] buffer's lBufferLength = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferOut1(Binding, bBuffer, &lBufferLength); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer out (1).\n", iIterations, mseconds); lBufferLength = BUFFER_SIZE; lBufferSize = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferOut2(Binding, bBuffer, lBufferSize, &lBufferLength); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer out (2).\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { BUFFER Buffer; Buffer.BufferLength = 0; Buffer.Buffer = 0; status = BufferOut3(Binding, &Buffer); if (status != RPC_S_OK) { goto Cleanup; } MIDL_user_free(Buffer.Buffer); } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer out (3).\n", iIterations, mseconds); lBufferLength = BUFFER_SIZE; StartTime(); for(i = iIterations; i; i--) { status = BufferOut4(Binding, bBuffer, &lBufferLength); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 100 byte buffer out (4).\n", iIterations, mseconds); // Time arrays of structures { struct BAD1 abad1[50]; struct BAD2 abad2[50]; struct GOOD agood[50]; for (i = 0; i < 50; i++) { abad2[i].e = (BAD_ENUM)i % 4 + 1; agood[i].e = (GOOD_ENUM)i % 4 + 5; } StartTime(); for(i = iIterations; i; i--) { status = StructsIn1(Binding, &abad1[0]); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - 2 mod 4 aligned structs.\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { status = StructsIn2(Binding, &abad2[0]); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - structs with an enum.\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { status = StructsIn3(Binding, &agood[0]); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - structs with v1_enum.\n", iIterations, mseconds); } // Linked lists { LIST list; PLIST plist = &list; for (i = 0; i < LIST_SIZE - 1; i++) { plist->pNext = MIDL_user_allocate(sizeof(LIST)); plist->data = i; if (plist->pNext == 0) { status = RPC_S_OUT_OF_MEMORY; goto Cleanup; } plist = plist->pNext; } plist->data = i; plist->pNext = 0; StartTime(); for(i = iIterations; i; i--) { status = ListIn(Binding, &list); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - [in] linked list.\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { status = ListOut1(Binding, &list); if (status != RPC_S_OK) { goto Cleanup; } // Freeing the list here would cause all the elements // to be allocated again on the next call. } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - [out] linked list (1).\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { status = ListOut2(Binding, &list); if (status != RPC_S_OK) { goto Cleanup; } // Freeing the list here would cause all the elements // to be allocated again on the next call. } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - [out] linked list (2).\n", iIterations, mseconds); // Free allocated elements of the list. plist = list.pNext; while(plist) { PLIST tmp = plist; plist = plist->pNext; MIDL_user_free(tmp); } } // Unions { BAD_UNION badunionArray[UNION_ARRAY_LEN]; GOOD_UNION goodunion; ARM_ONE armone; ULONG ulArray[UNION_ARRAY_LEN]; goodunion.Tag = 1; goodunion.u.pOne = &armone; armone.DataLength = UNION_ARRAY_LEN; armone.Data = ulArray; for(i = 0; i < UNION_ARRAY_LEN; i++) { ulArray[i] = i; badunionArray[i].Tag = 1; badunionArray[i].u.ulData = i; } StartTime(); for(i = iIterations; i; i--) { status = UnionCall1(Binding, UNION_ARRAY_LEN, badunionArray); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - [in] array of unions.\n", iIterations, mseconds); StartTime(); for(i = iIterations; i; i--) { status = UnionCall2(Binding, &goodunion); if (status != RPC_S_OK) { goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - [in] union of arrays.\n", iIterations, mseconds); } // Time pings() (null calls) which impersonate the client. StartTime(); for(i = iIterations; i; i--) { status = CheckSecurity(Binding); if (status != RPC_S_OK) { if (status == RPC_S_ACCESS_DENIED) { printf("Access denied, try -s 2 or higher.\n"); return; } goto Cleanup; } } mseconds = EndTime(); printf("%4d calls in %8d milliseconds - void call w/ impersonation\n", iIterations, mseconds); Cleanup: if (status != RPC_S_OK) { printf("Call failed - %d\n", status); } return; }
#include "stdafx.h" #include "TimeCheck.h" #include <windows.h> #ifdef _DEBUG #define new DEBUG_NEW #endif CTimeCheck::CTimeCheck() { } CTimeCheck::~CTimeCheck() { } void CTimeCheck::StartTime() { QueryPerformanceCounter( &__st ); } float CTimeCheck::EndTime() { QueryPerformanceCounter ( &__ed ); QueryPerformanceFrequency ( &__freq ); // 소요 시간 계산 double gap = ( (double) (__ed.QuadPart - __st.QuadPart )) / ( (double) __freq.QuadPart ) ; return (float)(gap * 1000.f); // msec } double CTimeCheck::EndTimeD() { QueryPerformanceCounter ( &__ed ); QueryPerformanceFrequency ( &__freq ); // 소요 시간 계산 double gap = ( (double) (__ed.QuadPart - __st.QuadPart )) / ( (double) __freq.QuadPart ) ; return (gap * 1000.0); // msec } void CTimeCheck::Reset() { QueryPerformanceCounter( &__st ); } float CTimeCheck::Elapsed_ms() { // 생성된 시점에서 현재까지의 시간을 계산해서 보내주기 LARGE_INTEGER ed; QueryPerformanceCounter( &ed ) ; // 소요 시간 계산 double gap = ( (double) (ed.QuadPart - __st.QuadPart )) / ( (double) __freq.QuadPart ) ; return (float)(gap * 1000.f); // msec } //* Pauses for a specified number of milliseconds. */ void CTimeCheck::sleep( float fwaitmsec )//2003.12.12 LHJ { StartTime(); while( EndTime() < fwaitmsec ); }
static void DoLink( char *cmdline ) /**********************************/ // cmdline is only used when we are running under watfor. { #ifndef __OSI__ #ifdef __ZDOS__ signal( SIGBREAK, &TrapBreak ); /* so we can clean up */ #else signal( SIGINT, &TrapBreak ); /* so we can clean up */ #endif #endif StartTime(); DoCmdFile( cmdline ); CheckErr(); MapInit(); SetupFakeModule(); ProcObjFiles(); /* ObjPass1 */ CheckErr(); DoDefaultSystem(); if( LinkState & LIBRARIES_ADDED ) { FindLibPaths(); LinkState |= SEARCHING_LIBRARIES; ResolveUndefined(); LinkState &= ~SEARCHING_LIBRARIES; LinkState |= GENERATE_LIB_LIST; } ProcLocalImports(); DecideFormat(); SetFormat(); ConvertLazyRefs(); SetSegments(); CheckErr(); DefBSSSyms(); LinkFakeModule(); PreAddrCalcFormatSpec(); ReportUndefined(); CheckClassOrder(); CalcSegSizes(); SetStkSize(); AutoGroup(); CalcAddresses(); GetBSSSize(); GetStkAddr(); GetStartAddr(); PostAddrCalcFormatSpec(); #ifdef _RDOS if( FmtData.type & MK_RDOS ) GetRdosSegs(); #endif CheckErr(); InitLoadFile(); ObjPass2(); FiniMap(); CheckErr(); FiniLoadFile(); WritePermData(); BuildImpLib(); EndTime(); #ifndef __OSI__ #ifdef __ZDOS__ signal( SIGBREAK, SIG_IGN ); /* we're going to clean up anyway */ #else signal( SIGINT, SIG_IGN ); /* we're going to clean up anyway */ #endif #endif }
FSTCARingBufferError FSTCARingBuffer::Store(const AudioBufferList *abl, UInt32 framesToWrite, SampleTime startWrite) { if (framesToWrite > mCapacityFrames) return kFSTCARingBufferError_TooMuch; // too big! if(startWrite > mCapacityFrames) return kFSTCARingBufferError_CPUOverload; SampleTime endWrite = startWrite + framesToWrite; if (startWrite < EndTime()) { // going backwards, throw everything out SetTimeBounds(startWrite, startWrite); } else if (endWrite - StartTime() <= mCapacityFrames) { // the buffer has not yet wrapped and will not need to } else { // advance the start time past the region we are about to overwrite SampleTime newStart = endWrite - mCapacityFrames; // one buffer of time behind where we're writing SampleTime newEnd = std::max(newStart, EndTime()); SetTimeBounds(newStart, newEnd); } int idx, offset0, offset1, nbytes; SampleTime curEnd = EndTime(); if(mBufferList) { int numBuffs = abl->mNumberBuffers; if(numBuffs > mBufferList->mNumberBuffers) numBuffs = mBufferList->mNumberBuffers; for(idx=0; idx<numBuffs; idx++) { AudioBuffer * buffer = &mBufferList->mBuffers[idx]; mCapacityBytes = sizeof(float)*buffer->mNumberChannels * mCapacityFrames; if (startWrite > curEnd) { // we are skipping some samples, so zero the range we are skipping offset0 = curEnd * sizeof(float) * buffer->mNumberChannels; offset1 = startWrite * sizeof(float) * buffer->mNumberChannels; if (offset0 < offset1) { ZeroRangeAB(buffer, offset0, offset1 - offset0); } else { ZeroRangeAB(buffer, offset0, mCapacityBytes - offset0); ZeroRangeAB(buffer, 0, offset1); } offset0 = offset1; } else { offset0 = startWrite * sizeof(float) * buffer->mNumberChannels; } offset1 = endWrite * sizeof(float) * buffer->mNumberChannels; if (offset0 < offset1) StoreAB(buffer, offset0, &abl->mBuffers[idx], 0, offset1 - offset0); else { nbytes = mCapacityBytes - offset0; StoreAB(buffer, offset0, &abl->mBuffers[idx], 0, nbytes); StoreAB(buffer, 0, &abl->mBuffers[idx], nbytes, offset1); } } } else { // write the new frames Byte **buffers = mBuffers; int nchannels = mNumberChannels; if (startWrite > curEnd) { // we are skipping some samples, so zero the range we are skipping offset0 = FrameOffset(curEnd); offset1 = FrameOffset(startWrite); if (offset0 < offset1) ZeroRange(buffers, nchannels, offset0, offset1 - offset0); else { ZeroRange(buffers, nchannels, offset0, mCapacityBytes - offset0); ZeroRange(buffers, nchannels, 0, offset1); } offset0 = offset1; } else { offset0 = FrameOffset(startWrite); } offset1 = FrameOffset(endWrite); if (offset0 < offset1) StoreBufs(buffers, offset0, abl, 0, offset1 - offset0); else { nbytes = mCapacityBytes - offset0; StoreBufs(buffers, offset0, abl, 0, nbytes); StoreBufs(buffers, 0, abl, nbytes, offset1); } } // now update the end time SetTimeBounds(StartTime(), endWrite); return kFSTCARingBufferError_OK; // success }
void main() { SPMatrix source ( 2.0f,-1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,-3.0f, 0.0f, 2.0f ); D3DXMATRIX power1; SPMatrix power2; #ifdef USE_P4 ScalarDP power3; DPMatrix power4; #endif power2 = source*source; power1 = *(D3DXMATRIX*)&power2; #ifdef USE_P4 power4 = Expand(power2); power3 = *(ScalarDP*)&power4; #endif int i,j; __int64 total1=0, total2=0, total3=0, total4=0; #ifndef _DEBUG SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL); #endif ////////////////////////////////////////////// // Using Microsoft D3DXMATRIX (scalar code). ////////////////////////////////////////////// for (j=0; j<REPS; j++) { D3DXMATRIX sqrt, rsqrt; D3DXMatrixIdentity(&sqrt); StartTime(1); for (i=1; i<ITER; i++) { D3DXMatrixInverse(&rsqrt, NULL, &sqrt); sqrt += power1*rsqrt; sqrt *= 0.5f; } EndTime(1); if (!j) PrintMatrix(*(SPMatrix *)&sqrt); if (!j) PrintMatrix(*(SPMatrix *)&(sqrt*sqrt)); } ////////////////////////////////////////////// // Using the SPMatrix class. ////////////////////////////////////////////// for (j=0; j<REPS; j++) { SPMatrix sqrt, rsqrt; sqrt.IdentityMatrix(); StartTime(2); for (i=1; i<ITER; i++) { rsqrt = sqrt; rsqrt.Inverse(); sqrt += power2*rsqrt; sqrt *= 0.5f; } EndTime(2); if (!j) PrintMatrix(sqrt); if (!j) PrintMatrix(sqrt*sqrt); } #ifdef USE_P4 ////////////////////////////////////////////// // Using the ScalarDP class (double-precision scalar code). ////////////////////////////////////////////// for (j=0; j<REPS; j++) { ScalarDP sqrt, rsqrt; sqrt.IdentityMatrix(); StartTime(3); for (i=1; i<ITER; i++) { rsqrt = sqrt; rsqrt.Inverse(); sqrt += power3*rsqrt; sqrt *= 0.5; } EndTime(3); if (!j) PrintMatrix(*(DPMatrix *)&sqrt); if (!j) PrintMatrix(*(DPMatrix *)&(sqrt*sqrt)); } ////////////////////////////////////////////// // Using the DPMatrix class. ////////////////////////////////////////////// for (j=0; j<REPS; j++) { DPMatrix sqrt, rsqrt; sqrt.IdentityMatrix(); StartTime(4); for (i=1; i<ITER; i++) { rsqrt = sqrt; rsqrt.Inverse(); sqrt += power4*rsqrt; sqrt *= 0.5; } EndTime(4); if (!j) PrintMatrix(sqrt); if (!j) PrintMatrix(sqrt*sqrt); } #endif #ifndef _DEBUG SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL); #endif printf("Avarage time using the D3DXMATRIX class: %4.2lf\n", double(total1)/double(REPS*ITER)); printf("Avarage time using the SPMatrix class: %4.2lf\n", double(total2)/double(REPS*ITER)); #ifdef USE_P4 printf("Avarage time using the ScalarDP class: %4.2lf\n", double(total3)/double(REPS*ITER)); printf("Avarage time using the DPMatrix class: %4.2lf\n", double(total4)/double(REPS*ITER)); #endif printf("\n"); printf("Speedup of SPMatrix: %1.3lf\n", double(total1)/double(total2)); #ifdef USE_P4 printf("Speedup of DPMatrix: %1.3lf\n", double(total3)/double(total4)); #endif }
ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const { int nPeriod = Period(params); int nThreshold = Threshold(params); int64_t nTimeStart = BeginTime(params); int64_t nTimeTimeout = EndTime(params); // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1. if (pindexPrev != nullptr) { pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod)); } // Walk backwards in steps of nPeriod to find a pindexPrev whose information is known std::vector<const CBlockIndex*> vToCompute; while (cache.count(pindexPrev) == 0) { if (pindexPrev == nullptr) { // The genesis block is by definition defined. cache[pindexPrev] = THRESHOLD_DEFINED; break; } if (pindexPrev->GetMedianTimePast() < nTimeStart) { // Optimization: don't recompute down further, as we know every earlier block will be before the start time cache[pindexPrev] = THRESHOLD_DEFINED; break; } vToCompute.push_back(pindexPrev); pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); } // At this point, cache[pindexPrev] is known assert(cache.count(pindexPrev)); ThresholdState state = cache[pindexPrev]; // Now walk forward and compute the state of descendants of pindexPrev while (!vToCompute.empty()) { ThresholdState stateNext = state; pindexPrev = vToCompute.back(); vToCompute.pop_back(); switch (state) { case THRESHOLD_DEFINED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = THRESHOLD_FAILED; } else if (pindexPrev->GetMedianTimePast() >= nTimeStart) { stateNext = THRESHOLD_STARTED; } break; } case THRESHOLD_STARTED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = THRESHOLD_FAILED; break; } // We need to count const CBlockIndex* pindexCount = pindexPrev; int count = 0; for (int i = 0; i < nPeriod; i++) { if (Condition(pindexCount, params)) { count++; } pindexCount = pindexCount->pprev; } if (count >= nThreshold) { stateNext = THRESHOLD_LOCKED_IN; } break; } case THRESHOLD_LOCKED_IN: { // Always progresses into ACTIVE. stateNext = THRESHOLD_ACTIVE; break; } case THRESHOLD_FAILED: case THRESHOLD_ACTIVE: { // Nothing happens, these are terminal states. break; } } cache[pindexPrev] = state = stateNext; } return state; }
void DataChart::ReInitialize() { if(!m_bInitialized) Initialize(); else { //Re-init the end and start and collect interval slices based on the time and current timestep values. StartTime(m_fltStartTime, false); EndTime(m_fltEndTime, false); CollectInterval(m_fltCollectInterval, false); if(m_fltCollectTimeWindow <= 0) m_lCollectTimeWindow = m_lEndSlice - m_lStartSlice; else m_lCollectTimeWindow = (long) (m_fltCollectTimeWindow / m_lpSim->TimeStep() + 0.5); long lColumnCount = CalculateChartColumnCount(); //We add 10 because we want the buffer to be bigger than the actual amount of data that is collected. long lRowCount = (m_lCollectTimeWindow/m_iCollectInterval) + 10; if(!m_aryDataBuffer || !m_aryTimeBuffer || lColumnCount != m_lColumnCount || lRowCount != m_lRowCount) { m_lColumnCount = lColumnCount; m_lRowCount = lRowCount; long lBuffSize = m_lColumnCount * m_lRowCount; if(lBuffSize > MAX_DATA_CHART_BUFFER) THROW_PARAM_ERROR(Al_Err_lExceededMaxBuffer, Al_Err_strExceededMaxBuffer, "Buffer Size", lBuffSize); if(m_aryDataBuffer) delete[] m_aryDataBuffer; m_aryDataBuffer = NULL; if(m_aryTimeBuffer) delete[] m_aryTimeBuffer; m_aryTimeBuffer = NULL; //Create the buffer and initialize it. m_aryDataBuffer = new float[lBuffSize]; memset(m_aryDataBuffer, 0, (sizeof(float) * lBuffSize)); m_aryTimeBuffer = new float[m_lRowCount]; memset(m_aryTimeBuffer, 0, (sizeof(float) * m_lRowCount)); //Start the current row back over at 0 again. m_lCurrentRow = 0; } //Now sort the data columns based on their ID value. stable_sort(m_aryDataColumns.begin(), m_aryDataColumns.end(), LessThanDataColumnCompare); //Now initialize the data columns. int iCount = m_aryDataColumns.GetSize(); for(int iCol=0; iCol<iCount; iCol++) { //If initialization fails then we need to remove the one that failed. try { m_aryDataColumns[iCol]->ReInitialize(); } catch(CStdErrorInfo oError) { m_aryDataColumns.RemoveAt(iCol); RELAY_ERROR(oError); } catch(...) { m_aryDataColumns.RemoveAt(iCol); THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError); } } } }