void inPlaceSort(void (*funct)(int *, int), int which){ printf("Performing %s with MIN = %d, MAX = %d and STEP = %d\n\n",inPlaceSortingFunctionNames[which],MIN,MAX,STEP); FILE *fpBest,*fpWorst,*fpAverage; int currentCount; //! Bubble Sort fpBest = fopen(formFileName(inPlaceSortingFunctionNames[which],"Best"),"w"); fpAverage = fopen(formFileName(inPlaceSortingFunctionNames[which],"Average"),"w"); fpWorst = fopen(formFileName(inPlaceSortingFunctionNames[which],"Worst"),"w"); for(currentCount=MIN; currentCount<=MAX; currentCount+=STEP) { int *a; generateBest(&a,currentCount); (*funct)(a,currentCount); fprintf(fpBest,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); generateAverage(&a,currentCount); (*funct)(a,currentCount); fprintf(fpAverage,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); generateWorst(&a,currentCount); (*funct)(a,currentCount); fprintf(fpWorst,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); printf("N: %d\n",currentCount); } fclose(fpBest); fclose(fpAverage); fclose(fpWorst); printf("Finished %s with MIN = %d, MAX = %d and STEP = %d\n\n",inPlaceSortingFunctionNames[which],MIN,MAX,STEP); }
bool TextureCache::syncCache() { static int32_t count = 0; if (count > 10) { // ?!? resetCounters(); count = 0; } count++; bool needs_sync = false; for (uint64_t i = 0; i < max_images_; i++) if (image_[i]->needs_sync) { needs_sync = true; break; } if (needs_sync) { for (uint64_t i = 0; i < max_images_; i++) { if (image_[i]->needs_sync) { syncTexture(i); } } return true; } return false; }
WidgetStub::WidgetStub(QObject *, bool enableVisualizationPriority) : m_lastKeyEvent(QKeyEvent::KeyPress, 0, 0), visualizationPriority(enableVisualizationPriority) { setAttribute(Qt::WA_InputMethodEnabled); resetCounters(); }
/** * @param file File pointer for a file to be parsed. The file must be open for * reading (e.g. with ArUtil::fopen()) and this pointer must not be NULL. * @param buffer a non-NULL char array in which to read the file * @param bufferLength the number of chars in the buffer; must be greater than 0 * @param continueOnErrors a bool set to true if parsing should continue * even after an error is detected * @param errorBuffer buffer to put errors into if not NULL. Only the * first error is saved, and as soon as this function is called it * immediately empties the errorBuffer * @param errorBufferLen the length of @a errorBuffer */ AREXPORT bool ArFileParser::parseFile(FILE *file, char *buffer, int bufferLength, bool continueOnErrors, char *errorBuffer, size_t errorBufferLen) { if (errorBuffer) errorBuffer[0] = '\0'; if ((file == NULL) || (buffer == NULL) || (bufferLength <= 0)) { if (errorBuffer != NULL) snprintf(errorBuffer, errorBufferLen, "parseFile: bad setup"); return false; } bool ret = true; resetCounters(); // read until the end of the file while (fgets(buffer, bufferLength, file) != NULL) { if (!parseLine(buffer, errorBuffer, errorBufferLen)) { ret = false; if (!continueOnErrors) break; } } return ret; }
void IncompressibleCloud::evolve() { smoment_.setSize(U_.size()); resetCounters(); label particles=size(); UInterpolator_ = interpolation<vector>::New ( interpolationSchemes_, volPointInterpolation_, U_ ); move(); inject(); UInterpolator_.clear(); reduce(particles, sumOp<label>()); reduce(wallCollisions_, sumOp<label>()); reduce(leavingModel_, sumOp<label>()); reduce(injectedInModel_, sumOp<label>()); reduce(changedProzessor_, sumOp<label>()); Info << particles << " Particles moved. " << wallCollisions_ << " walls hit. " << leavingModel_ << " particles left the model. " ; if(injectedInModel_) { Info << injectedInModel_ << " particles injected. "; } if(changedProzessor_) { Info << changedProzessor_ << " particles changed the processor. "; } Info << endl; }
bool Transporter::connect_server(NDB_SOCKET_TYPE sockfd, BaseString& msg) { // all initial negotiation is done in TransporterRegistry::connect_server DBUG_ENTER("Transporter::connect_server"); if (m_connected) { msg.assfmt("line: %u : already connected ??", __LINE__); DBUG_RETURN(false); } // Cache the connect address my_socket_connect_address(sockfd, &m_connect_address); if (!connect_server_impl(sockfd)) { msg.assfmt("line: %u : connect_server_impl failed", __LINE__); DBUG_RETURN(false); } m_connect_count++; resetCounters(); m_connected = true; DBUG_RETURN(true); }
void run_function_spec() { ASSERT(!filter_node_count, NULL); REMARK("Testing < void, void > (single filter in pipeline)"); #if __TBB_LAMBDAS_PRESENT REMARK( " ( + lambdas)"); #endif REMARK("\n"); input_filter<void> i_filter; // Test pipeline that contains only one filter for( unsigned i = 0; i<number_of_filter_types; i++) { tbb::filter_t<void, void> one_filter( filter_table[i], i_filter ); ASSERT(filter_node_count==1, "some filter nodes left after previous iteration?"); resetCounters(); tbb::parallel_pipeline( n_tokens, one_filter ); // no need to check counters #if __TBB_LAMBDAS_PRESENT tbb::atomic<int> counter; counter = max_counter; // Construct filter using lambda-syntax when parallel_pipeline() is being run; tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, void>(filter_table[i], [&counter]( tbb::flow_control& control ) { if( counter-- == 0 ) control.stop(); } ) ); #endif } ASSERT(!filter_node_count, "filter_node objects leaked"); }
void UniformRegistry::clear(){ for(auto & entry : uniforms) { delete entry.second; } uniforms.clear(); orderedList.clear(); resetCounters(); }
PortScanner::PortScanner() { if (debug > 2) printf("PortScanner: Constructing\n"); src_port = getFirstPID();; show_closed_ports = 0; resolve_service_names = 1; custom_source_port_flag = 0; resetCounters(); }
/** * Test the content of an MiscellaneousNotification * Strategy: Set up a subscription and send a notification. * Check it. */ void miscellaneousNotificationTest(void) { /* TODO: Implement test once the API exist */ subscriptionId = 6; resetCounters(); test_validate(SA_AIS_ERR_NOT_SUPPORTED, SA_AIS_OK); }
void Interpret::reset() { info("reset()"); resetCounters(); resetEventVariables(); _lastMetaIndexNotSet = 0; _lastWordIndexSet = 0; _metaEventIndexLength = 0; _metaEventIndex = 0; _startWordIndex = 0; }
void Move::autoTune( void ) { // only do something if tuning is turned on if ( autoTuning ) { // delegate to derived class tune(); // reset counters resetCounters(); } }
static void debugPrint() { int i = 0; for (i = 0; i < nrOfQueues; i++) { Data* queueData = &data[i]; if (filter(queueData)) { debugPrintQueue(queueData); } } if (RESET_COUNTERS_AFTER_DISPLAY) { resetCounters(); } }
/** * Test the content of an SecurityAlarmNotification * Strategy: Set up a subscription and send a notification. * Check it. */ void securityAlarmNotificationTest(void) { SaNtfSecurityAlarmNotificationFilterT myFilter; subscriptionId = 5; resetCounters(); safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK); safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK); if(!safassertNice((rc = saNtfSecurityAlarmNotificationFilterAllocate( ntfHandle, &myFilter, 0, 0, 0, 0, 0,0,0,0,0)), SA_AIS_OK)) { /* Initialize filter handles */ myNotificationFilterHandles.alarmFilterHandle = 0; myNotificationFilterHandles.attributeChangeFilterHandle = 0; myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0; myNotificationFilterHandles.securityAlarmFilterHandle = myFilter.notificationFilterHandle; myNotificationFilterHandles.stateChangeFilterHandle = 0; /* subscribe */ safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles, subscriptionId), SA_AIS_OK); createSecurityAlarmNotification(ntfHandle, &mySecAlarmNotification); safassert(saNtfNotificationSend(mySecAlarmNotification.notificationHandle), SA_AIS_OK); /* Delay to let the notification slip through */ poll_until_received(ntfHandle, *mySecAlarmNotification.notificationHeader.notificationId); if(ntfRecieved.alarmFilterHandle != 0 || ntfRecieved.attributeChangeFilterHandle != 0 || ntfRecieved.objectCreateDeleteFilterHandle !=0 || ntfRecieved.securityAlarmFilterHandle != 1 || ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK); safassert(saNtfNotificationFree(mySecAlarmNotification.notificationHandle), SA_AIS_OK); safassert(saNtfNotificationFilterFree(myFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK); safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK); if(errors && rc == SA_AIS_OK) rc = SA_AIS_ERR_FAILED_OPERATION; test_validate(rc, SA_AIS_OK); }
TimeStateInfo() { entityProcessed = NULL; resetCounters(); startPos = 0; endPos = 0; nextPos = 0; lastEndPos = 0; numWords = 0; isTimeUnit = false; hasTimeUnit = false; currentType = OTHER; currentState = NOTHING_S; nextState = NOTHING_S; punctuationInfo.reset(); }
void Interpret::reset() { info("reset()"); resetCounters(); resetEventVariables(); _lastMetaIndexNotSet = 0; _lastWordIndexSet = 0; _metaEventIndexLength = 0; _metaEventIndex = 0; _startWordIndex = 0; // initialize SRAM variables to 0 tTriggerNumber = 0; tActualLVL1ID = 0; tActualBCID = 0; tActualSRcode= 0; tActualSRcounter = 0; }
AREXPORT ArFileParser::ArFileParser(const char *baseDirectory) : myCommentDelimiterList(), myPreParseFunctor(NULL), myMap(), myRemainderHandler(NULL), myIsQuiet(false) { setBaseDirectory(baseDirectory); std::list<std::string> defaultDelimiters; defaultDelimiters.push_back(";"); defaultDelimiters.push_back("#"); setCommentDelimiters(defaultDelimiters); resetCounters(); setMaxNumArguments(); }
/** * Configure this Transport for communication. * If this Transport is already configured, it will be closed and reconfigured. * The RX buffer and Message queue will be flushed. * Counters will be reset. * @param device The device to communicate over. (Currently, must be serial) * @param retries Number of times to resend an unacknowledged message. * @throws TransportException if configuration fails * @post Transport becomes configured. */ void Transport::configure(const char* device, int retries) { if( configured ) { // Close serial close(); } // Forget old counters resetCounters(); this->retries = retries; if( !openComm(device) ) { configured = true; } else { throw new TransportException("Failed to open serial port", TransportException::CONFIGURE_FAIL); } }
BOOL CCharInfoDialog::OnInitDialog() { CDialog::OnInitDialog(); DoSetButtonSkin(); configToControls(config); resetCounters(); m_hasteRemaining.EnableWindow(config->enableTimers); m_stronghasteRemaining.EnableWindow(config->enableTimers); m_invisRemaining.EnableWindow(config->enableTimers); m_magicshieldRemaining.EnableWindow(config->enableTimers); m_magicShieldText.EnableWindow(config->enableTimers); m_strongHasteText.EnableWindow(config->enableTimers); m_invisText.EnableWindow(config->enableTimers); m_hasteText.EnableWindow(config->enableTimers); SetTimer(1001, 500, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
unsigned long Memory::saveState(SaveState &state, unsigned long cc) { cc = resetCounters(cc); nontrivial_ff_read(0x05, cc); nontrivial_ff_read(0x0F, cc); nontrivial_ff_read(0x26, cc); state.mem.divLastUpdate = divLastUpdate_; state.mem.nextSerialtime = intreq_.eventTime(intevent_serial); state.mem.unhaltTime = intreq_.eventTime(intevent_unhalt); state.mem.lastOamDmaUpdate = lastOamDmaUpdate_; state.mem.dmaSource = dmaSource_; state.mem.dmaDestination = dmaDestination_; state.mem.oamDmaPos = oamDmaPos_; intreq_.saveState(state); cart_.saveState(state); tima_.saveState(state); lcd_.saveState(state); psg_.saveState(state); return cc; }
unsigned long Memory::saveState(SaveState &state, unsigned long cycleCounter) { cycleCounter = resetCounters(cycleCounter); nontrivial_ff_read(0xFF05, cycleCounter); nontrivial_ff_read(0xFF0F, cycleCounter); nontrivial_ff_read(0xFF26, cycleCounter); state.mem.divLastUpdate = divLastUpdate; state.mem.nextSerialtime = intreq.eventTime(SERIAL); state.mem.unhaltTime = intreq.eventTime(UNHALT); state.mem.lastOamDmaUpdate = lastOamDmaUpdate; state.mem.dmaSource = dmaSource; state.mem.dmaDestination = dmaDestination; state.mem.oamDmaPos = oamDmaPos; intreq.saveState(state); cart.saveState(state); tima.saveState(state); display.saveState(state); sound.saveState(state); return cycleCounter; }
InfAdmixture::InfAdmixture(Data *d,State *s,double alpha,bool v,double initialq,bool test) { atest=test; data=d; state=s; verbose=v; resetCounters(); double numvars=100; P_QS=100.0/numvars; //P_PS =1-sum(these) for(int c1=0;c1<data->getDim();c1++) { Q.push_back(vector<double>(state->getP(),0.0)); } QcolSums=vector<double>(state->getP(),0.0); for(int c1=0;c1<state->getP();c1++) { P.push_back(vector<double>(state->getP(),0.0)); } samplePs(true); initialQs(initialq); setAlpha(alpha); logstateprob=state->admixtureLogLikelihood(&Q,&P,&QcolSums); }
void CIntel::update(int frame) { resetCounters(); if (enemyvector == ZeroVector) updateEnemyVector(); int numUnits = ai->cbc->GetEnemyUnits(&ai->unitIDs[0], MAX_UNITS); for (int i = 0; i < numUnits; i++) { const int uid = ai->unitIDs[i]; const UnitDef* ud = ai->cbc->GetUnitDef(uid); if (ud == NULL) continue; unitCategory c = UT(ud->id)->cats; if ((c&ATTACKER).any() && (c&MOBILE).any()) updateCounters(c); } updateRoulette(); }
/** * Test the content of several notifications at once * Strategy: Set up a subscription and send a notification. * Check it. */ void allNotificationTest(void) { rc = SA_AIS_OK; saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams; SaNtfAlarmNotificationFilterT myAlarmFilter; SaNtfObjectCreateDeleteNotificationFilterT myObjCrDeFilter; SaNtfAttributeChangeNotificationFilterT myAttrChangeFilter; SaNtfStateChangeNotificationFilterT myStateChangeFilter; SaNtfSecurityAlarmNotificationFilterT mySecAlarmFilter; subscriptionId = 7; resetCounters(); fillInDefaultValues(&myNotificationAllocationParams, &myNotificationFilterAllocationParams, &myNotificationParams); safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK); if(!safassertNice(saNtfAlarmNotificationFilterAllocate( ntfHandle, &myAlarmFilter, myNotificationFilterAllocationParams.numEventTypes, myNotificationFilterAllocationParams.numNotificationObjects, myNotificationFilterAllocationParams.numNotifyingObjects, myNotificationFilterAllocationParams.numNotificationClassIds, myNotificationFilterAllocationParams.numProbableCauses, myNotificationFilterAllocationParams.numPerceivedSeverities, myNotificationFilterAllocationParams.numTrends), SA_AIS_OK)) { /* Set perceived severities */ myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING; myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED; if(!safassertNice((rc = saNtfObjectCreateDeleteNotificationFilterAllocate( ntfHandle, &myObjCrDeFilter, myNotificationFilterAllocationParams.numEventTypes, myNotificationFilterAllocationParams.numNotificationObjects, myNotificationFilterAllocationParams.numNotifyingObjects, myNotificationFilterAllocationParams.numNotificationClassIds, myNotificationFilterAllocationParams.numSourceIndicators)), SA_AIS_OK)) { if(!safassertNice((rc = saNtfAttributeChangeNotificationFilterAllocate( ntfHandle, &myAttrChangeFilter, myNotificationFilterAllocationParams.numEventTypes, myNotificationFilterAllocationParams.numNotificationObjects, myNotificationFilterAllocationParams.numNotifyingObjects, myNotificationFilterAllocationParams.numNotificationClassIds, myNotificationFilterAllocationParams.numSourceIndicators)), SA_AIS_OK)) { if(!safassertNice((rc = saNtfSecurityAlarmNotificationFilterAllocate( ntfHandle, &mySecAlarmFilter, myNotificationFilterAllocationParams.numEventTypes, myNotificationFilterAllocationParams.numNotificationObjects, myNotificationFilterAllocationParams.numNotifyingObjects, myNotificationFilterAllocationParams.numNotificationClassIds, myNotificationFilterAllocationParams.numProbableCauses, myNotificationFilterAllocationParams.numSeverities, myNotificationFilterAllocationParams.numSecurityAlarmDetectos, myNotificationFilterAllocationParams.numServiceUsers, myNotificationFilterAllocationParams.numServiceProviders)), SA_AIS_OK)) { if(!safassertNice((rc = saNtfStateChangeNotificationFilterAllocate( ntfHandle, &myStateChangeFilter, myNotificationFilterAllocationParams.numEventTypes, myNotificationFilterAllocationParams.numNotificationObjects, myNotificationFilterAllocationParams.numNotifyingObjects, myNotificationFilterAllocationParams.numNotificationClassIds, myNotificationFilterAllocationParams.numSourceIndicators, myNotificationFilterAllocationParams.numChangedStates)), SA_AIS_OK)) { /* Initialize filter handles */ myNotificationFilterHandles.alarmFilterHandle = myAlarmFilter.notificationFilterHandle; myNotificationFilterHandles.attributeChangeFilterHandle = myAttrChangeFilter.notificationFilterHandle; myNotificationFilterHandles.objectCreateDeleteFilterHandle = myObjCrDeFilter.notificationFilterHandle; myNotificationFilterHandles.securityAlarmFilterHandle = mySecAlarmFilter.notificationFilterHandle; myNotificationFilterHandles.stateChangeFilterHandle = myStateChangeFilter.notificationFilterHandle; /* subscribe */ safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles, subscriptionId), SA_AIS_OK); /* Create a couple of notifications and send them */ createAlarmNotification(ntfHandle, &myAlarmNotification); safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK); createObjectCreateDeleteNotification(ntfHandle, &myObjCrDelNotfification); safassert(saNtfNotificationSend(myObjCrDelNotfification.notificationHandle), SA_AIS_OK); createAttributeChangeNotification(ntfHandle, &myAttrChangeNotification); safassert(saNtfNotificationSend(myAttrChangeNotification.notificationHandle), SA_AIS_OK); createStateChangeNotification(ntfHandle, &myStateChangeNotification); safassert(saNtfNotificationSend(myStateChangeNotification.notificationHandle), SA_AIS_OK); createSecurityAlarmNotification(ntfHandle, &mySecAlarmNotification); safassert(saNtfNotificationSend(mySecAlarmNotification.notificationHandle), SA_AIS_OK); /* TODO: add MiscellaneousNotification */ poll_until_received(ntfHandle, *mySecAlarmNotification.notificationHeader.notificationId); if(ntfRecieved.alarmFilterHandle != 1 || ntfRecieved.attributeChangeFilterHandle != 1 || ntfRecieved.objectCreateDeleteFilterHandle !=1 || ntfRecieved.securityAlarmFilterHandle != 1 || ntfRecieved.stateChangeFilterHandle != 1){ fprintf(stderr, "ntfreceived fh: a: %llu, att: %llu, o: %llu, se: %llu, st: %llu \n", ntfRecieved.alarmFilterHandle, ntfRecieved.attributeChangeFilterHandle, ntfRecieved.objectCreateDeleteFilterHandle, ntfRecieved.securityAlarmFilterHandle, ntfRecieved.stateChangeFilterHandle); safassertNice(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK); } safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK); safassert(saNtfNotificationFree(myObjCrDelNotfification.notificationHandle), SA_AIS_OK); safassert(saNtfNotificationFree(myAttrChangeNotification.notificationHandle), SA_AIS_OK); safassert(saNtfNotificationFree(myStateChangeNotification.notificationHandle), SA_AIS_OK); safassert(saNtfNotificationFree(mySecAlarmNotification.notificationHandle), SA_AIS_OK); /* TODO: add MiscellaneousNotification free */ safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK); safassert(saNtfNotificationFilterFree(myStateChangeFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfNotificationFilterFree(mySecAlarmFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfNotificationFilterFree(myAttrChangeFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfNotificationFilterFree(myObjCrDeFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK); } safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK); /* Allocated in fillInDefaultValues() */ free(myNotificationParams.additionalText); if(errors && rc == SA_AIS_OK) rc = SA_AIS_ERR_FAILED_OPERATION; test_validate(rc, SA_AIS_OK); }
void run_lambdas_test( mode_array *filter_type ) { tbb::atomic<int> counter; counter = max_counter; // Construct filters using lambda-syntax and create the sequence when parallel_pipeline() is being run; resetCounters(); // only need the output_counter reset. tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, t1>(filter_type[0], [&counter]( tbb::flow_control& control ) -> t1 { if( --counter < 0 ) control.stop(); return t1(); } ) & tbb::make_filter<t1, t2>(filter_type[1], []( t1 /*my_storage*/ ) -> t2 { return t2(); } ) & tbb::make_filter<t2, void>(filter_type[2], [] ( t2 ) -> void { output_counter++; } ) ); checkCounters(no_pointer_counts); // don't have to worry about specializations counter = max_counter; // pointer filters resetCounters(); tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, t1*>(filter_type[0], [&counter]( tbb::flow_control& control ) -> t1* { if( --counter < 0 ) { control.stop(); return NULL; } return new(fetchNextBuffer()) t1(); } ) & tbb::make_filter<t1*, t2*>(filter_type[1], []( t1* my_storage ) -> t2* { tbb::tbb_allocator<t1>().destroy(my_storage); // my_storage->~t1(); return new(my_storage) t2(); } ) & tbb::make_filter<t2*, void>(filter_type[2], [] ( t2* my_storage ) -> void { tbb::tbb_allocator<t2>().destroy(my_storage); // my_storage->~t2(); freeBuffer(my_storage); output_counter++; } ) ); checkCounters(no_pointer_counts); // first filter outputs pointer counter = max_counter; resetCounters(); tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, t1*>(filter_type[0], [&counter]( tbb::flow_control& control ) -> t1* { if( --counter < 0 ) { control.stop(); return NULL; } return new(fetchNextBuffer()) t1(); } ) & tbb::make_filter<t1*, t2>(filter_type[1], []( t1* my_storage ) -> t2 { tbb::tbb_allocator<t1>().destroy(my_storage); // my_storage->~t1(); freeBuffer(my_storage); return t2(); } ) & tbb::make_filter<t2, void>(filter_type[2], [] ( t2 /*my_storage*/) -> void { output_counter++; } ) ); checkCounters(no_pointer_counts); // second filter outputs pointer counter = max_counter; resetCounters(); tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, t1>(filter_type[0], [&counter]( tbb::flow_control& control ) -> t1 { if( --counter < 0 ) { control.stop(); } return t1(); } ) & tbb::make_filter<t1, t2*>(filter_type[1], []( t1 /*my_storage*/ ) -> t2* { return new(fetchNextBuffer()) t2(); } ) & tbb::make_filter<t2*, void>(filter_type[2], [] ( t2* my_storage) -> void { tbb::tbb_allocator<t2>().destroy(my_storage); // my_storage->~t2(); freeBuffer(my_storage); output_counter++; } ) ); checkCounters(no_pointer_counts); }
/** * Test the content of an alarm notification * Strategy: Set up a subscription and send a notification. * Check it. */ void alarmNotificationTest2(void) { SaNtfAlarmNotificationFilterT myAlarmFilter; subscriptionId = 1; int i; rc = SA_AIS_OK; resetCounters(); safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK); safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK); /* Set up the filters and subscription */ safassert(saNtfAlarmNotificationFilterAllocate( ntfHandle, &myAlarmFilter, 0, 0, 0, 0, 0, 2, 0), SA_AIS_OK); /* Set perceived severities */ myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING; myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED; /* Initialize filter handles */ myNotificationFilterHandles.alarmFilterHandle = myAlarmFilter.notificationFilterHandle; myNotificationFilterHandles.attributeChangeFilterHandle = 0; myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0; myNotificationFilterHandles.securityAlarmFilterHandle = 0; myNotificationFilterHandles.stateChangeFilterHandle = 0; safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles, subscriptionId), SA_AIS_OK); /* Create a notification and send it */ myAlarmNotification.notificationHeader.numCorrelatedNotifications = 2; myAlarmNotification.notificationHeader.numAdditionalInfo = 5; safassert(saNtfAlarmNotificationAllocate( ntfHandle, &myAlarmNotification, myAlarmNotification.notificationHeader.numCorrelatedNotifications, (SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1), myAlarmNotification.notificationHeader.numAdditionalInfo, 3, /* SaUint16T numSpecificProblems, */ 2, /* SaUint16T numMonitoredAttributes, */ 2, /* SaUint16T numProposedRepairActions, */ SA_NTF_ALLOC_SYSTEM_LIMIT), /* SaInt16T variableDataSize */ SA_AIS_OK); fillHeader(&myAlarmNotification.notificationHeader); /* determine perceived severity */ *(myAlarmNotification.perceivedSeverity) = SA_NTF_SEVERITY_WARNING; /* set probable cause*/ *(myAlarmNotification.probableCause) = SA_NTF_BANDWIDTH_REDUCED; myAlarmNotification.specificProblems[0].problemClassId.vendorId = 23; myAlarmNotification.specificProblems[0].problemClassId.majorId = 22; myAlarmNotification.specificProblems[0].problemClassId.minorId = 21; myAlarmNotification.specificProblems[1].problemClassId.vendorId = 5; myAlarmNotification.specificProblems[1].problemClassId.majorId = 4; myAlarmNotification.specificProblems[1].problemClassId.minorId = 2; myAlarmNotification.specificProblems[2].problemClassId.vendorId = 2; myAlarmNotification.specificProblems[2].problemClassId.majorId = 3; myAlarmNotification.specificProblems[2].problemClassId.minorId = 4; myAlarmNotification.monitoredAttributes[0].attributeId = 1; myAlarmNotification.monitoredAttributes[0].attributeType = SA_NTF_VALUE_INT64; myAlarmNotification.monitoredAttributes[0].attributeValue.int64Val = 987654321; myAlarmNotification.monitoredAttributes[1].attributeId = 2; myAlarmNotification.monitoredAttributes[1].attributeType = SA_NTF_VALUE_INT8; myAlarmNotification.monitoredAttributes[1].attributeValue.int8Val = 88; myAlarmNotification.proposedRepairActions[0].actionId = 3; myAlarmNotification.proposedRepairActions[0].actionValueType = SA_NTF_VALUE_INT16; myAlarmNotification.proposedRepairActions[0].actionValue.int16Val = 456; myAlarmNotification.proposedRepairActions[1].actionId = 4; myAlarmNotification.proposedRepairActions[1].actionValueType = SA_NTF_VALUE_INT32; myAlarmNotification.proposedRepairActions[1].actionValue.int32Val = 456; for (i = 0; i < myAlarmNotification.numSpecificProblems; i++) { myAlarmNotification.specificProblems[i].problemId = i; myAlarmNotification.specificProblems[i].problemClassId.majorId = 1; myAlarmNotification.specificProblems[i].problemClassId.minorId = 2; myAlarmNotification.specificProblems[i].problemClassId.vendorId = 33; myAlarmNotification.specificProblems[i].problemType = SA_NTF_VALUE_UINT32; myAlarmNotification.specificProblems[i].problemValue.uint32Val = (SaUint32T)(600+i); } for (i = 0; i < myAlarmNotification.numProposedRepairActions; i++) { myAlarmNotification.proposedRepairActions[i].actionId = i; myAlarmNotification.proposedRepairActions[i].actionValueType = SA_NTF_VALUE_UINT32; myAlarmNotification.proposedRepairActions[i].actionValue.uint32Val = (SaUint32T)(700+i); } *myAlarmNotification.trend = SA_NTF_TREND_MORE_SEVERE; myAlarmNotification.thresholdInformation->thresholdValueType = SA_NTF_VALUE_UINT32; myAlarmNotification.thresholdInformation->thresholdValue.uint32Val = 600; myAlarmNotification.thresholdInformation->thresholdHysteresis.uint32Val = 100; myAlarmNotification.thresholdInformation->observedValue.uint32Val = 567; myAlarmNotification.thresholdInformation->armTime = SA_TIME_UNKNOWN; myAlarmNotification.notificationHeader.correlatedNotifications[0] = 1999; myAlarmNotification.notificationHeader.correlatedNotifications[1] = 1984; safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK); poll_until_received(ntfHandle, *myAlarmNotification.notificationHeader.notificationId); if(ntfRecieved.alarmFilterHandle != 1 || ntfRecieved.attributeChangeFilterHandle != 0 || ntfRecieved.objectCreateDeleteFilterHandle !=0 || ntfRecieved.securityAlarmFilterHandle != 0 || ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK); safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK); safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK); safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK); safassert(saNtfFinalize(ntfHandle), SA_AIS_OK); /* Allocated in fillInDefaultValues() */ free(myNotificationParams.additionalText); if(errors) rc = SA_AIS_ERR_FAILED_OPERATION; test_validate(rc, SA_AIS_OK); }
/** * Test the content of an alarm notification * Strategy: Set up a subscription and send a notification. * Check it. */ void alarmNotificationTest(void) { SaNtfAlarmNotificationFilterT myAlarmFilter; subscriptionId = 1; rc = SA_AIS_OK; resetCounters(); safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK); safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK); /* Set up the filters and subscription */ safassert(saNtfAlarmNotificationFilterAllocate( ntfHandle, &myAlarmFilter, 0, 0, 0, 0, 0, 2, 0), SA_AIS_OK); /* Set perceived severities */ myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING; myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED; /* Initialize filter handles */ myNotificationFilterHandles.alarmFilterHandle = myAlarmFilter.notificationFilterHandle; myNotificationFilterHandles.attributeChangeFilterHandle = 0; myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0; myNotificationFilterHandles.securityAlarmFilterHandle = 0; myNotificationFilterHandles.stateChangeFilterHandle = 0; safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles, subscriptionId), SA_AIS_OK); /* Create a notification and send it */ safassert(saNtfAlarmNotificationAllocate( ntfHandle, &myAlarmNotification, 0, (SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1), 0, 0, 0, 0, SA_NTF_ALLOC_SYSTEM_LIMIT), SA_AIS_OK); fillHeader(&myAlarmNotification.notificationHeader); /* determine perceived severity */ *(myAlarmNotification.perceivedSeverity) = SA_NTF_SEVERITY_WARNING; /* set probable cause*/ *(myAlarmNotification.probableCause) = SA_NTF_BANDWIDTH_REDUCED; *myAlarmNotification.trend = SA_NTF_TREND_MORE_SEVERE; myAlarmNotification.thresholdInformation->thresholdValueType = SA_NTF_VALUE_UINT32; myAlarmNotification.thresholdInformation->thresholdValue.uint32Val = 600; myAlarmNotification.thresholdInformation->thresholdHysteresis.uint32Val = 100; myAlarmNotification.thresholdInformation->observedValue.uint32Val = 567; myAlarmNotification.thresholdInformation->armTime = SA_TIME_UNKNOWN; safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK); poll_until_received(ntfHandle, *myAlarmNotification.notificationHeader.notificationId); if(ntfRecieved.alarmFilterHandle != 1 || ntfRecieved.attributeChangeFilterHandle != 0 || ntfRecieved.objectCreateDeleteFilterHandle !=0 || ntfRecieved.securityAlarmFilterHandle != 0 || ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK); safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK); safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK); safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK); safassert(saNtfFinalize(ntfHandle), SA_AIS_OK); /* Allocated in fillInDefaultValues() */ free(myNotificationParams.additionalText); if(errors) rc = SA_AIS_ERR_FAILED_OPERATION; test_validate(rc, SA_AIS_OK); }
bool Transporter::connect_client(NDB_SOCKET_TYPE sockfd) { DBUG_ENTER("Transporter::connect_client(sockfd)"); if(m_connected) { DBUG_PRINT("error", ("Already connected")); DBUG_RETURN(true); } if (!my_socket_valid(sockfd)) { DBUG_PRINT("error", ("Socket " MY_SOCKET_FORMAT " is not valid", MY_SOCKET_FORMAT_VALUE(sockfd))); DBUG_RETURN(false); } DBUG_PRINT("info",("server port: %d, isMgmConnection: %d", m_s_port, isMgmConnection)); // Send "hello" DBUG_PRINT("info", ("Sending own nodeid: %d and transporter type: %d", localNodeId, m_type)); SocketOutputStream s_output(sockfd); if (s_output.println("%d %d", localNodeId, m_type) < 0) { DBUG_PRINT("error", ("Send of 'hello' failed")); NDB_CLOSE_SOCKET(sockfd); DBUG_RETURN(false); } // Read reply DBUG_PRINT("info", ("Reading reply")); char buf[256]; SocketInputStream s_input(sockfd); if (s_input.gets(buf, 256) == 0) { DBUG_PRINT("error", ("Failed to read reply")); NDB_CLOSE_SOCKET(sockfd); DBUG_RETURN(false); } // Parse reply int nodeId, remote_transporter_type= -1; int r= sscanf(buf, "%d %d", &nodeId, &remote_transporter_type); switch (r) { case 2: break; case 1: // we're running version prior to 4.1.9 // ok, but with no checks on transporter configuration compatability break; default: DBUG_PRINT("error", ("Failed to parse reply")); NDB_CLOSE_SOCKET(sockfd); DBUG_RETURN(false); } DBUG_PRINT("info", ("nodeId=%d remote_transporter_type=%d", nodeId, remote_transporter_type)); // Check nodeid if (nodeId != remoteNodeId) { g_eventLogger->error("Connected to wrong nodeid: %d, expected: %d", nodeId, remoteNodeId); NDB_CLOSE_SOCKET(sockfd); DBUG_RETURN(false); } // Check transporter type if (remote_transporter_type != -1 && remote_transporter_type != m_type) { g_eventLogger->error("Connection to node: %d uses different transporter " "type: %d, expected type: %d", nodeId, remote_transporter_type, m_type); NDB_CLOSE_SOCKET(sockfd); DBUG_RETURN(false); } // Cache the connect address my_socket_connect_address(sockfd, &m_connect_address); if (!connect_client_impl(sockfd)) DBUG_RETURN(false); m_connect_count++; resetCounters(); m_connected = true; DBUG_RETURN(true); }
void run_function(const char *l1, const char *l2) { ASSERT(!filter_node_count, NULL); REMARK("Testing < %s, %s >", l1, l2 ); #if __TBB_LAMBDAS_PRESENT REMARK( " ( + lambdas)"); #endif REMARK("\n"); const size_t number_of_filters = 3; input_filter<type1> i_filter; middle_filter<type1, type2> m_filter; output_filter<type2> o_filter; unsigned limit = 1; // Test pipeline that contains number_of_filters filters for( unsigned i=0; i<number_of_filters; ++i) limit *= number_of_filter_types; // Iterate over possible filter sequences for( unsigned numeral=0; numeral<limit; ++numeral ) { unsigned temp = numeral; tbb::filter::mode filter_type[number_of_filter_types]; for( unsigned i=0; i<number_of_filters; ++i, temp/=number_of_filter_types ) filter_type[i] = filter_table[temp%number_of_filter_types]; tbb::filter_t<void, type1> filter1( filter_type[0], i_filter ); tbb::filter_t<type1, type2> filter2( filter_type[1], m_filter ); tbb::filter_t<type2, void> filter3( filter_type[2], o_filter ); ASSERT(filter_node_count==3, "some filter nodes left after previous iteration?"); resetCounters(); // Create filters sequence when parallel_pipeline() is being run tbb::parallel_pipeline( n_tokens, filter1 & filter2 & filter3 ); checkCounters(); // Create filters sequence partially outside parallel_pipeline() and also when parallel_pipeline() is being run tbb::filter_t<void, type2> filter12; filter12 = filter1 & filter2; resetCounters(); tbb::parallel_pipeline( n_tokens, filter12 & filter3 ); checkCounters(); tbb::filter_t<void, void> filter123 = filter12 & filter3; // Run pipeline twice with the same filter sequence for( unsigned i = 0; i<2; i++ ) { resetCounters(); tbb::parallel_pipeline( n_tokens, filter123 ); checkCounters(); } // Now copy-construct another filter_t instance, and use it to run pipeline { tbb::filter_t<void, void> copy123( filter123 ); resetCounters(); tbb::parallel_pipeline( n_tokens, copy123 ); checkCounters(); } // Construct filters and create the sequence when parallel_pipeline() is being run resetCounters(); tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, type1>(filter_type[0], i_filter) & tbb::make_filter<type1, type2>(filter_type[1], m_filter) & tbb::make_filter<type2, void>(filter_type[2], o_filter) ); checkCounters(); // Construct filters, make a copy, destroy the original filters, and run with the copy int cnt = filter_node_count; { tbb::filter_t<void, void>* p123 = new tbb::filter_t<void,void> ( tbb::make_filter<void, type1>(filter_type[0], i_filter) & tbb::make_filter<type1, type2>(filter_type[1], m_filter) & tbb::make_filter<type2, void>(filter_type[2], o_filter) ); ASSERT(filter_node_count==cnt+5, "filter node accounting error?"); tbb::filter_t<void, void> copy123( *p123 ); delete p123; ASSERT(filter_node_count==cnt+5, "filter nodes deleted prematurely?"); resetCounters(); tbb::parallel_pipeline( n_tokens, copy123 ); checkCounters(); } // construct a filter with temporaries { tbb::filter_t<void, void> my_filter; fill_chain<type1,type2>( my_filter, filter_type, i_filter, m_filter, o_filter ); resetCounters(); tbb::parallel_pipeline( n_tokens, my_filter ); checkCounters(); } ASSERT(filter_node_count==cnt, "scope ended but filter nodes not deleted?"); #if __TBB_LAMBDAS_PRESENT tbb::atomic<int> counter; counter = max_counter; // Construct filters using lambda-syntax and create the sequence when parallel_pipeline() is being run; resetCounters(); // only need the output_counter reset. tbb::parallel_pipeline( n_tokens, tbb::make_filter<void, type1>(filter_type[0], [&counter]( tbb::flow_control& control ) -> type1 { if( --counter < 0 ) control.stop(); return type1(); } ) & tbb::make_filter<type1, type2>(filter_type[1], []( type1 /*my_storage*/ ) -> type2 { return type2(); } ) & tbb::make_filter<type2, void>(filter_type[2], [] ( type2 ) -> void { output_counter++; } ) ); checkCounters(); #endif } ASSERT(!filter_node_count, "filter_node objects leaked"); }
/** @param fileName the file to open @param continueOnErrors whether to continue or immediately bail upon an error @param noFileNotFoundMessage whether or not to log if we find a file (we normally want to but for robot param files that'd be too annoying since we test for a lot of files) @param errorBuffer buffer to put errors into if not NULL. Only the first error is saved, and as soon as this function is called it immediately empties the errorBuffer @param errorBufferLen the length of @a errorBuffer */ AREXPORT bool ArFileParser::parseFile(const char *fileName, bool continueOnErrors, bool noFileNotFoundMessage, char *errorBuffer, size_t errorBufferLen) { FILE *file; char line[10000]; bool ret = true; if (errorBuffer) errorBuffer[0] = '\0'; std::string realFileName; if (fileName[0] == '/' || fileName[0] == '\\') { realFileName = fileName; } else { realFileName = myBaseDir; realFileName += fileName; } ArLog::log(ArLog::Verbose, "Opening file %s from fileName given %s and base directory %s", realFileName.c_str(), fileName, myBaseDir.c_str()); //char *buf = new char[4096]; if ((file = ArUtil::fopen(realFileName.c_str(), "r")) == NULL) { if (errorBuffer != NULL) snprintf(errorBuffer, errorBufferLen, "cannot open file %s", fileName); if (!noFileNotFoundMessage) ArLog::log(ArLog::Terse, "ArFileParser::parseFile: Could not open file %s to parse file.", realFileName.c_str()); return false; } /** if( setvbuf( file, buf, _IOFBF, sizeof( buf ) ) != 0 ) printf( "Incorrect type or size of buffer for file\n" ); //else // printf( "'file' now has a buffer of 1024 bytes\n" ); **/ resetCounters(); // read until the end of the file while (fgets(line, sizeof(line), file) != NULL) { if (!parseLine(line, errorBuffer, errorBufferLen)) { ArLog::log(ArLog::Terse, "## Last error on line %d of file '%s'", myLineNumber, realFileName.c_str()); ret = false; if (!continueOnErrors) break; } } fclose(file); return ret; }