void MB12XX::cycle() { /* collection phase? */ if (_collect_phase) { /* perform collection */ if (OK != collect()) { log("collection error"); /* restart the measurement state machine */ start(); return; } /* next phase is measurement */ _collect_phase = false; /* * Is there a collect->measure gap? */ if (_measure_ticks > USEC2TICK(MB12XX_CONVERSION_INTERVAL)) { /* schedule a fresh cycle call when we are ready to measure again */ work_queue(HPWORK, &_work, (worker_t)&MB12XX::cycle_trampoline, this, _measure_ticks - USEC2TICK(MB12XX_CONVERSION_INTERVAL)); return; } } /* measurement phase */ if (OK != measure()) log("measure error"); /* next phase is collection */ _collect_phase = true; /* schedule a fresh cycle call when the measurement is done */ work_queue(HPWORK, &_work, (worker_t)&MB12XX::cycle_trampoline, this, USEC2TICK(MB12XX_CONVERSION_INTERVAL)); }
static int get_ifconfig_info(struct net_desc *devs) { char *buf_in; char *buf_tmp; const char **ignore; char *buf; char *tmp; int textsize; int i; /* Get ifconfig information */ textsize = collect(T_OUTPUT, &buf_in, "/sbin/ifconfig -l 2>/dev/null"); if (textsize < 0) { if (logfp) (void)fprintf(logfp, "Aborting: Could not run ifconfig.\n"); (void)fprintf(stderr, "Could not run ifconfig."); exit(1); } buf = malloc (STRSIZE * sizeof(char)); for (i = 0, buf_tmp = buf_in; strlen(buf_tmp) > 0 && buf_tmp < buf_in + strlen(buf_in);) { tmp = stpncpy(buf, buf_tmp, strcspn(buf_tmp," \n")); *tmp='\0'; buf_tmp += (strcspn(buf_tmp, " \n") + 1) * sizeof(char); /* Skip ignored interfaces */ for (ignore = ignored_if_names; *ignore != NULL; ignore++) { size_t len = strlen(*ignore); if (strncmp(buf, *ignore, len) == 0 && isdigit((unsigned char)buf[len])) break; } if (*ignore != NULL) continue; strlcpy (devs[i].if_dev, buf, STRSIZE); i++; } strcpy(devs[i].if_dev, "\0"); free(buf); free(buf_in); return i; }
void ResourceConverter::convert() { for (auto file : listResources(m_resourceRoot , textureDir , textureExtension)) { load(textureDir, file, textureExtension); } for (auto file : listResources(m_resourceRoot , mmlDir , mmlExtension)) { load(mmlDir, file, mmlExtension); } collect(); compress(); encrypt(); write(); }
static long collect_generations(void) { int i; long n = 0; /* Find the oldest generation (higest numbered) where the count * exceeds the threshold. Objects in the that generation and * generations younger than it will be collected. */ for (i = NUM_GENERATIONS-1; i >= 0; i--) { if (generations[i].count > generations[i].threshold) { n = collect(i); break; } } return n; }
static void collect(int *psize) { move_t m; uint32 hm; if(*psize >= MAXPLY) return; hm = tt_get_hashmove(pos->hash); if(hm) { m.p = hm; if(make_if_legal(m)) { pv_backup[*psize].p = hm; *psize += 1; collect(psize); move_unmake(); } } }
void collect(vector<vector<int>> mark, vector<string>& res, string s, int start, string tmp){ for(auto stop : mark[start]){ string sstr = s.substr(start, stop - start); string newtmp = start == 0 ? sstr : tmp + " "+ sstr; if(stop == s.length()) res.push_back(newtmp); else collect(mark, res, s, stop, newtmp); } }
Array* LookupTable::filtered_keys(STATE, ObjectMatcher& matcher) { class filtered_keys : public CollectAction { ObjectMatcher& m_; public: filtered_keys(ObjectMatcher& m) : m_(m) {} virtual Object* call(STATE, LookupTableBucket* bucket) { if(m_.match_p(state, bucket->key())) return bucket->key(); return 0; } } match(matcher); return collect(state, this, match); }
void ReachingDefinitionBase:: collect_refs ( AstInterface& fa, const AstNodePtr& h, FunctionSideEffectInterface* a, AstInterface::AstNodeList* in) { for (AstInterface::AstNodeList::iterator p = in->begin(); p != in->end(); ++p) { AstNodePtr cur = *p; std::string varname; AstNodePtr scope; if (fa.IsVarRef( cur, 0, &varname, &scope)) add_ref(varname, scope, std::pair<AstNodePtr, AstNodePtr>(cur, AST_NULL) ); } ConstructReachingDefinitionBase collect(fa, *this); StmtSideEffectCollect op(a); op(fa, h, &collect); }
void MemoryManager::sweep() { assert(!sweeping()); if (debug) checkHeap(); collect("MM::sweep"); m_sweeping = true; SCOPE_EXIT { m_sweeping = false; }; DEBUG_ONLY size_t num_sweepables = 0, num_natives = 0; // iterate until both sweep lists are empty. Entries can be added or // removed from either list during sweeping. do { while (!m_sweepables.empty()) { num_sweepables++; auto obj = m_sweepables.next(); obj->unregister(); obj->sweep(); } while (!m_natives.empty()) { num_natives++; assert(m_natives.back()->sweep_index == m_natives.size() - 1); auto node = m_natives.back(); m_natives.pop_back(); auto obj = Native::obj(node); auto ndi = obj->getVMClass()->getNativeDataInfo(); ndi->sweep(obj); // trash the native data but leave the header and object parsable assert(memset(node+1, kSmallFreeFill, node->obj_offset - sizeof(*node))); } } while (!m_sweepables.empty()); DEBUG_ONLY auto napcs = m_apc_arrays.size(); FTRACE(1, "sweep: sweepable {} native {} apc array {}\n", num_sweepables, num_natives, napcs); if (debug) checkHeap(); // decref apc arrays referenced by this request. This must happen here // (instead of in resetAllocator), because the sweep routine may use // g_context. while (!m_apc_arrays.empty()) { auto a = m_apc_arrays.back(); m_apc_arrays.pop_back(); a->sweep(); } }
void Heap::reportExtraMemoryCostSlowCase(size_t cost) { // Our frequency of garbage collection tries to balance memory use against speed // by collecting based on the number of newly created values. However, for values // that hold on to a great deal of memory that's not in the form of other JS values, // that is not good enough - in some cases a lot of those objects can pile up and // use crazy amounts of memory without a GC happening. So we track these extra // memory costs. Only unusually large objects are noted, and we only keep track // of this extra cost until the next GC. In garbage collected languages, most values // are either very short lived temporaries, or have extremely long lifetimes. So // if a large value survives one garbage collection, there is not much point to // collecting more frequently as long as it stays alive. didAllocate(cost); if (shouldCollect()) collect(DoNotSweep); }
//排序函数 void sort(int numbers[]){ int bucket[10][SIZE] = {0}; // 定义10个桶 //每个桶第0号记录桶内数字个数 int maxDigit; // 最长几位 int i = 0; //获得最多位数,确定排序次数 maxDigit = getMaxDigit(numbers); //printf("maxDigit = %d\n", maxDigit); for(i = 0; i < maxDigit; i++){ //进行第i位排序 distribute(i, bucket, numbers); //按序归位 collect(bucket, numbers); //debug(numbers); } }
void PODModel::collect(){ if ( _color.a < 1 ){ return; } if ( _nodeIndex == (unsigned char)-1 ){ AlphaMode am; for ( unsigned int i = 0; i < _pRes->_pod.nNumMeshNode; ++i ){ if ( _color.a < 255 ){ am = ALPHA_BLEND; }else{ am = _pRes->getAlphaMode(i); } PODModelCollector::collect(this, i, am); } }else{ collect(_nodeIndex); } }
int main(int argc, char * argv[]) { if (argc != 2) {printf("Please provide a matrix");} int ierr = MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); //sets rank MPI_Comm_size(MPI_COMM_WORLD, &size); //gets number of processes current_pivot = 0; if (rank == 0) { //master process get_number_of_rows(argv[1], &numrows); numcols = numrows + 1; //specified by assignment int i; for (i = 1; i < size; i++) { //sending out information to slaves about what rows they are reading. MPI_Isend(&numrows, 1, MPI_INT, i, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD, &request); } } else { MPI_Recv(&numrows, 1, MPI_INT, 0, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD, &status); numcols = numrows + 1; } if (rank >= numrows) { ierr = MPI_Finalize(); return 0; } else if (rank < (numrows % size)) { numrows = (numrows / size) + 1; } else { numrows = (numrows / size); } matrix = allocate_matrix(numrows, numcols); read_rows(argv[1], matrix); RREF(matrix); absolute(matrix, &numrows, &numcols); reduction(matrix, &numrows, &numcols); get_best_threshold(); collect(matrix); // print_matrix(matrix, numrows, numcols); print_matrix(final_matrix, numcols - 1, numcols); if (rank == 0) { // output_to_file(final_matrix); } free_matrix(matrix, &numrows); ierr = MPI_Finalize(); }
HitResponse Block::collision(GameObject& other, const CollisionHit& ) { auto player = dynamic_cast<Player*> (&other); if(player) { if(player->get_bbox().get_top() > bbox.get_bottom() - SHIFT_DELTA) { hit(*player); } } // only interact with other objects if... // 1) we are bouncing // 2) the object is not portable (either never or not currently) // 3) the object is being hit from below (baguys don't get killed for activating boxes) auto portable = dynamic_cast<Portable*> (&other); auto moving_object = dynamic_cast<MovingObject*> (&other); auto bomb = dynamic_cast<Bomb*> (&other); bool is_portable = ((portable != 0) && portable->is_portable()); bool is_bomb = (bomb != 0); // bombs need to explode, although they are considered portable bool hit_mo_from_below = ((moving_object == 0) || (moving_object->get_bbox().get_bottom() < (bbox.get_top() + SHIFT_DELTA))); if(bouncing && (!is_portable || is_bomb) && hit_mo_from_below) { // Badguys get killed auto badguy = dynamic_cast<BadGuy*> (&other); if(badguy) { badguy->kill_fall(); } // Coins get collected auto coin = dynamic_cast<Coin*> (&other); if(coin) { coin->collect(); } //Eggs get jumped auto growup = dynamic_cast<GrowUp*> (&other); if(growup) { growup->do_jump(); } } return FORCE_MOVE; }
/* Collect (and sort) dependencies of collected parameters */ void collect_and_normalize_dependencies(buffer<expr> & norm_params) { name_map<expr> new_types; for (unsigned i = 0; i < m_params.size(); i++) { expr x = m_params[i]; expr new_type = collect(m_ctx.instantiate_mvars(m_ctx.infer(x))); new_types.insert(mlocal_name(x), new_type); } local_context const & lctx = m_ctx.lctx(); std::sort(m_params.begin(), m_params.end(), [&](expr const & l1, expr const & l2) { return lctx.get_local_decl(l1)->get_idx() < lctx.get_local_decl(l2)->get_idx(); }); for (unsigned i = 0; i < m_params.size(); i++) { expr x = m_params[i]; expr type = *new_types.find(mlocal_name(x)); expr new_type = replace_locals(type, i, m_params.data(), norm_params.data()); expr new_param = m_ctx.push_local(local_pp_name(x), new_type, local_info(x)); norm_params.push_back(new_param); } }
void SF1XX::cycle() { /* Collect results */ if (OK != collect()) { DEVICE_DEBUG("collection error"); /* if error restart the measurement state machine */ start(); return; } /* schedule a fresh cycle call when the measurement is done */ work_queue(HPWORK, &_work, (worker_t)&SF1XX::cycle_trampoline, this, USEC2TICK(_conversion_interval)); }
void Glob::glob(const Path& pathPattern, std::set<std::string>& files, int options) { Path pattern(pathPattern); pattern.makeDirectory(); // to simplify pattern handling later on Path base(pattern); Path absBase(base); absBase.makeAbsolute(); // In case of UNC paths we must not pop the topmost directory // (which must not contain wildcards), otherwise collect() will fail // as one cannot create a DirectoryIterator with only a node name ("\\srv\"). int minDepth = base.getNode().empty() ? 0 : 1; while (base.depth() > minDepth && base[base.depth() - 1] != "..") { base.popDirectory(); absBase.popDirectory(); } if (pathPattern.isDirectory()) options |= GLOB_DIRS_ONLY; collect(pattern, absBase, base, pathPattern[base.depth()], files, options); }
void PX4FLOW::cycle() { if (OK != measure()) { DEVICE_DEBUG("measure error"); } /* perform collection */ if (OK != collect()) { DEVICE_DEBUG("collection error"); /* restart the measurement state machine */ start(); return; } work_queue(HPWORK, &_work, (worker_t)&PX4FLOW::cycle_trampoline, this, _measure_ticks); }
void Glob::collect(const Path& pathPattern, const Path& base, const Path& current, const std::string& pattern, std::set<std::string>& files, int options) { try { std::string pp = pathPattern.toString(); std::string basep = base.toString(); std::string curp = current.toString(); Glob g(pattern, options); DirectoryIterator it(base); DirectoryIterator end; while (it != end) { const std::string& name = it.name(); if (g.match(name)) { Path p(current); if (p.depth() < pathPattern.depth() - 1) { p.pushDirectory(name); collect(pathPattern, it.path(), p, pathPattern[p.depth()], files, options); } else { p.setFileName(name); if (isDirectory(p, (options & GLOB_FOLLOW_SYMLINKS) != 0)) { p.makeDirectory(); files.insert(p.toString()); } else if (!(options & GLOB_DIRS_ONLY)) { files.insert(p.toString()); } } } ++it; } } catch (Exception&) { } }
void invert_word(int ptr, int cp, struct pcp_vars *pcp) { register int *y = y_address; register int gen; register int exp; register int length = y[ptr]; for (; length > 1; --length) { gen = y[ptr + length]; if (gen < 0) collect(-gen, cp, pcp); else invert_generator(gen, 1, cp, pcp); } exp = y[ptr + 1]; if (exp != 1) calculate_power(exp, ptr, cp, pcp); }
void evaluate_list (int *queue, int *queue_length, int *list, int depth, struct pcp_vars *pcp) { register int *y = y_address; register int lastg = pcp->lastg; register int cp = pcp->lused; register int cp1 = cp + lastg; register int cp2 = cp1 + lastg; register int i, a; for (i = 1; i <= lastg; ++i) y[cp + i] = 0; while (depth > 0) { a = list[depth]; for (i = 1; i <= lastg; ++i) y[cp1 + i] = 0; y[cp1 + a] = 1; /* compute a^power_of_entry */ power (power_of_entry, cp1, pcp); vector_to_string (cp1, cp2, pcp); if (y[cp2 + 1] != 0) collect (-cp2, cp, pcp); --depth; } #ifdef DEBUG print_array (y, cp + 1, cp + lastg + 1); printf ("The result is "); print_array (y, cp + 1, cp + lastg + 1); #endif /* now compute word^exponent */ power (exponent, cp, pcp); setup_word_to_print ("result of collection", cp, cp + lastg + 1, pcp); /* if (pcp->m != 0) */ setup_echelon (queue, queue_length, cp, pcp); }
static int __collect_image(int fd_t, int obj_t, unsigned size, int (*collect)(void *obj, ProtobufCMessage *msg), void * (*alloc)(size_t size), void (*free)(void *ptr)) { int fd, ret; fd = open_image_ro(fd_t); if (fd < 0) return -1; while (1) { void *obj; ProtobufCMessage *msg; if (size) { ret = -1; obj = alloc(size); if (!obj) break; } else obj = NULL; ret = pb_read_one_eof(fd, &msg, obj_t); if (ret <= 0) { free(obj); break; } ret = collect(obj, msg); if (ret < 0) { free(obj); cr_pb_descs[obj_t].free(msg, NULL); break; } } close(fd); return ret; }
int LidarLitePWM::measure() { perf_begin(_sample_perf); if (OK != collect()) { debug("collection error"); perf_count(_read_errors); perf_end(_sample_perf); return ERROR; } _range.timestamp = hrt_absolute_time(); _range.type = distance_sensor_s::MAV_DISTANCE_SENSOR_LASER; _range.max_distance = get_maximum_distance(); _range.min_distance = get_minimum_distance(); _range.current_distance = float(_pwm.pulse_width) * 1e-3f; /* 10 usec = 1 cm distance for LIDAR-Lite */ _range.covariance = 0.0f; _range.orientation = 8; /* TODO: set proper ID */ _range.id = 0; /* Due to a bug in older versions of the LidarLite firmware, we have to reset sensor on (distance == 0) */ if (_range.current_distance <= 0.0f) { perf_count(_sensor_zero_resets); perf_end(_sample_perf); return reset_sensor(); } if (_distance_sensor_topic != nullptr) { orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &_range); } if (_reports->force(&_range)) { perf_count(_buffer_overflows); } poll_notify(POLLIN); perf_end(_sample_perf); return OK; }
void* Heap::allocate(NewSpace::SizeClass& sizeClass) { #if COLLECT_ON_EVERY_ALLOCATION collectAllGarbage(); ASSERT(m_operationInProgress == NoOperation); #endif m_operationInProgress = Allocation; void* result = m_newSpace.allocate(sizeClass); m_operationInProgress = NoOperation; if (result) return result; if (m_newSpace.waterMark() < m_newSpace.highWaterMark()) { m_newSpace.addBlock(sizeClass, allocateBlock(sizeClass.cellSize)); return allocate(sizeClass); } collect(DoNotSweep); return allocate(sizeClass); }
void Configuration::collect(ConfigNode* node, std::vector<std::string>* params, size_t offset, std::vector<ConfigNode*>* result) { std::vector<ConfigNodePtr>* children = node->getChildren(); if (offset == params->size()) { result->push_back(node); return; } for (size_t i = offset; i < params->size(); i++) { bool found = false; for (size_t j = 0; j < children->size(); j++) { if ((*children)[j]->getName().compare((*params)[i]) == 0) { collect((*children)[j].get(), params, offset + 1, result); found = true; } } if (!found) { return; } } }
TEST test_collect(void) { FILE *f = fopen("test", "w+"); static const char S[] = "a\0b\0c"; rewind(f); fwrite(S, sizeof(S[0]), ASIZE(S), f); strbuf_t *sb; strbuf_init(&sb, 16); rewind(f); collect(&sb, f); ASSERT(sb->pos == 6); ASSERT_STR_EQ(&sb->buf[0], "a"); ASSERT_STR_EQ(&sb->buf[2], "b"); ASSERT_STR_EQ(&sb->buf[4], "c"); strbuf_destroy(sb); fclose(f); PASS(); }
std::vector<std::string> Configuration::getNames(const char *path, ...) { CONSUME_PARAMS(path); // Get relevant nodes std::vector<ConfigNode *> nodes; collect(this->configRoot.get(), params.get(), 0, &nodes); // If there are no nodes, exit if (nodes.size() == 0) { throw ConfigException(pathNotFound(params.get())); } // Copy only the keys std::vector<std::string> result; for (size_t i = 0; i < nodes.size(); i++) { if (nodes[i]->getType() == ConfigNode::Leaf) { result.push_back(nodes[i]->getName()); } } return result; }
void runTest(Test* t){ //print results puts("\nStarting heap:"); puts("========================================="); printHeap(t->h); puts("\nStarting stack:"); puts("========================================="); printStack(t->s); collect(t->s,&(t->h),0); puts("\nCollected heap:"); puts("========================================="); printHeap(t->h); puts("\nCollected stack:"); puts("========================================="); printStack(t->s); puts("\nBigdata heap:"); puts("===================================="); printHeap(bigdataheap); }
void VM_GC_HeapInspection::doit() { HandleMark hm; Universe::heap()->ensure_parsability(false); // must happen, even if collection does // not happen (e.g. due to GC_locker) // or _full_gc being false if (_full_gc) { if (!collect()) { // The collection attempt was skipped because the gc locker is held. // The following dump may then be a tad misleading to someone expecting // only live objects to show up in the dump (see CR 6944195). Just issue // a suitable warning in that case and do not attempt to do a collection. // The latter is a subtle point, because even a failed attempt // to GC will, in fact, induce one in the future, which we // probably want to avoid in this case because the GC that we may // be about to attempt holds value for us only // if it happens now and not if it happens in the eventual // future. warning("GC locker is held; pre-dump GC was skipped"); } } HeapInspection inspect(_csv_format, _print_help, _print_class_stats, _columns); inspect.heap_inspection(_out); }
void Surface_collector::collect(const scene::Scene& scene, const float3& eye_position, const Frustum& frustum, bool collect_actors, bool collect_static_geometry) { surfaces_.clear(); if (collect_static_geometry) { collect(scene.aabb_tree(), eye_position, frustum); } if (collect_actors) { auto& actors = scene.actors(); for (auto a : actors) { if (Intersection_type::Outside != frustum.intersect(a->aabb())) { add(a, eye_position); } } } std::sort(surfaces_.begin(), surfaces_.end()); }