void wcache_invalidate_cache(void) { struct winbindd_domain *domain; for (domain = domain_list(); domain; domain = domain->next) { struct winbind_cache *cache = get_cache(domain); DEBUG(10, ("wcache_invalidate_cache: invalidating cache " "entries for %s\n", domain->name)); if (cache) tdb_traverse(cache->tdb, traverse_fn, NULL); } }
CacheRef< CachedTexture > get_texture(string const &filename, bool pad, bool flip) { string key = "texture:"; key += (pad?'1':'0'); key += (flip?'1':'0'); key += filename; CacheRef< CachedTexture > ret(NULL); CachedTexture *item = (CachedTexture *)get_cache().get_item(key); if (!item) { item = new CachedTexture(filename, pad, flip); if (!item->loaded) { cerr << "Texture loading failed for " << filename << "." << endl; delete item; return ret; } get_cache().add_item(key, item); } if (item->id != TEXTURE_ID) { cerr << "Item with key '" << key << "' isn't a texture." << endl; return ret; } ret.set(item); return ret; }
static void refresh_sequence_number(struct winbindd_domain *domain, BOOL force) { NTSTATUS status; unsigned time_diff; time_t t = time(NULL); unsigned cache_time = lp_winbind_cache_time(); get_cache( domain ); #if 0 /* JERRY -- disable as the default cache time is now 5 minutes */ /* trying to reconnect is expensive, don't do it too often */ if (domain->sequence_number == DOM_SEQUENCE_NONE) { cache_time *= 8; } #endif time_diff = t - domain->last_seq_check; /* see if we have to refetch the domain sequence number */ if (!force && (time_diff < cache_time)) { DEBUG(10, ("refresh_sequence_number: %s time ok\n", domain->name)); goto done; } /* try to get the sequence number from the tdb cache first */ /* this will update the timestamp as well */ status = fetch_cache_seqnum( domain, t ); if ( NT_STATUS_IS_OK(status) ) goto done; status = domain->backend->sequence_number(domain, &domain->sequence_number); if (!NT_STATUS_IS_OK(status)) { domain->sequence_number = DOM_SEQUENCE_NONE; } domain->last_status = status; domain->last_seq_check = time(NULL); /* save the new sequence number ni the cache */ store_cache_seqnum( domain ); done: DEBUG(10, ("refresh_sequence_number: %s seq number is now %d\n", domain->name, domain->sequence_number)); return; }
CacheRef< CachedFont > get_font(string name) { string key = "font:" + name; CacheRef< CachedFont > ret(NULL); CachedFont *item = (CachedFont *)get_cache().get_item(key); if (!item) { TexFont *font = txfLoadFont(name.c_str()); if (font == NULL) { cerr << "Error loading font '" << name << "'." << endl; return ret; } item = new CachedFont(font); get_cache().add_item(key, item); } if (item->id != FONT_ID) { cerr << "Item with key '" << key << "' isn't a font." << endl; return ret; } ret.set(item); return ret; }
/* enumerate trusted domains */ static NTSTATUS trusted_domains(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, uint32 *num_domains, char ***names, char ***alt_names, DOM_SID **dom_sids) { get_cache(domain); DEBUG(10,("trusted_domains: [Cached] - doing backend query for info for domain %s\n", domain->name )); /* we don't cache this call */ return domain->backend->trusted_domains(domain, mem_ctx, num_domains, names, alt_names, dom_sids); }
struct directory *init_directory(struct node *node){ struct cache *cache = get_cache(node); struct directory *dir; if (!cache->directory){ dir = NULL; return dir; } dir = malloc(sizeof(struct directory)); dir->nb_sons = get_nb_sons(node); struct cache **caches = malloc(dir->nb_sons * sizeof(struct cache *)); int current = 0; assign_sons(dir, node, caches, ¤t); dir->sons_caches = caches; return dir; }
/* * Find a entry in the specified dir with name _dname_. */ static const struct iso_dir_entry * iso_find_entry(const char *dname, struct inode *inode) { struct fs_info *fs = inode->fs; block_t dir_block = PVT(inode)->lba; int i = 0, offset = 0; const char *de_name; int de_name_len, de_len; const struct iso_dir_entry *de; const char *data = NULL; dprintf("iso_find_entry: \"%s\"\n", dname); while (1) { if (!data) { dprintf("Getting block %d from block %llu\n", i, dir_block); if (++i > inode->blocks) return NULL; /* End of directory */ data = get_cache(fs->fs_dev, dir_block++); offset = 0; } de = (const struct iso_dir_entry *)(data + offset); de_len = de->length; offset += de_len; /* Make sure we have a full directory entry */ if (de_len < 33 || offset > BLOCK_SIZE(fs)) { /* * Zero = end of sector, or corrupt directory entry * * ECMA-119:1987 6.8.1.1: "Each Directory Record shall end * in the Logical Sector in which it begins. */ data = NULL; continue; } de_name_len = de->name_len; de_name = de->name; if (iso_compare_name(de_name, de_name_len, dname)) { dprintf("Found.\n"); return de; } } }
url get_from_web (url name) { if (!is_rooted_web (name)) return url_none (); url res= get_cache (name); if (!is_none (res)) return res; #ifdef OS_WIN32 string urlString = as_string (name); url tmp = url_temp(); if (starts (urlString, "www.")) urlString = "http://" * urlString; else if (starts (urlString, "ftp.")) urlString = "ftp://" * urlString; else if (starts (urlString, "ftp://")) urlPath = NULL; else if (starts (urlString, "http://")) urlPath = NULL; else urlString = "http://" * urlString; urlString= web_encode (urlString); c_string urlPath (urlString); c_string tempFilePath (as_string (tmp)); if(!URL_Get(urlPath, tempFilePath)) return url_none(); else return set_cache (name, tmp); #else string test= var_eval_system ("which wget"); if (!ends (test, "wget")) return url_none (); url tmp= url_temp (); string tmp_s= escape_sh (concretize (tmp)); string cmd= "wget --header='User-Agent: TeXmacs-" TEXMACS_VERSION "' -q"; cmd << " -O " << tmp_s << " " << escape_sh (web_encode (as_string (name))); // cout << cmd << "\n"; system (cmd); // cout << "got " << name << " as " << tmp << "\n"; if (var_eval_system ("cat " * tmp_s * " 2> /dev/null") == "") { remove (tmp); return url_none (); } else return set_cache (name, tmp); #endif }
caddr_t get_bcache(fileid_t *fp) { /* * Search Disk Block Cache: * * This should be getting pretty monotonous by now. Aren't generalized * subroutines ("objects", if you prefer) great? */ cache_t *bcp; x_len = fp->fi_count; x_blkno = fp->fi_blocknum; x_dev = fp->fi_devp->di_dcookie; bcp = get_cache(bc_hash[BC_HASH(x_dev, x_blkno, x_len)], &bc_head); return (bcp ? (caddr_t)bcp->data : 0); }
void * get_icache(int dev, int inum) { /* * Search File Cache: * * This routine searches the file cache looking for the entry bound to * the given "dev"ice and file number ["inum"]. If said entry exists, * it returns the address of the associated file structure. Otherwise * it returns null. */ cache_t *icp; x_dev = dev; x_inode = inum; icp = get_cache(ic_hash[IC_HASH(dev, inum)], &ic_head); return (icp ? (caddr_t)icp->data : 0); }
/* create(Cache :: atom(), MaxSize :: integer(), MinQ1Size :: integer()) */ static ERL_NIF_TERM create(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { ERL_NIF_TERM atom; ErlNifUInt64 max_size, min_q1_size; struct cache *c; if (!enif_is_atom(env, argv[0])) return enif_make_badarg(env); atom = argv[0]; if (!enif_get_uint64(env, argv[1], &max_size)) return enif_make_badarg(env); if (!enif_get_uint64(env, argv[2], &min_q1_size)) return enif_make_badarg(env); if ((c = get_cache(atom))) { ERL_NIF_TERM ret = enif_make_atom(env, "already_exists"); enif_consume_timeslice(env, 5); enif_rwlock_rwlock(c->cache_lock); /* expansion is safe because we don't have to engage the background thread and won't cause sudden eviction pressure TODO: a nice way to shrink the cache without seizing it up */ if (c->max_size < max_size && c->min_q1_size < min_q1_size) { c->max_size = max_size; c->min_q1_size = min_q1_size; enif_rwlock_rwunlock(c->cache_lock); ret = enif_make_atom(env, "ok"); enif_consume_timeslice(env, 10); } else { enif_rwlock_rwunlock(c->cache_lock); } return ret; } else { c = new_cache(atom, max_size, min_q1_size); enif_consume_timeslice(env, 20); return enif_make_atom(env, "ok"); } }
static int bee_dep_conflicts(int argc, char *argv[]) { int c, opt_count, help; struct hash *graph; struct option long_options[] = { {"help", 0, &help, 1}, {0, 0, 0, 0} }; help = opt_count = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_conflicts(); return 1; default: opt_count++; } } if (help) { usage_conflicts(); return 0; } if (optind < argc) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } graph = get_cache(); if (print_conflicts(graph)) { hash_free(graph); return 1; } hash_free(graph); return 0; }
int get_dcache(int dev, char *name, int pnum) { /* * Search Directory Cache: * * This routine searches the directory cache for an entry * associated with directory number "pnum" from the given * file system that de-scribes a file of the given "name". * If we find such an entry, we return the corresponding file * number, 0 otherwise. */ dc_t *dcp; x_dev = dev; x_len = strlen(name)+1; x_pnum = pnum; x_name = name; dcp = (dc_t *)get_cache(dc_hash[DC_HASH(dev, name, x_len)], &dc_head); return (dcp ? dcp->dc_inum : 0); }
void* pref_main (void* arg) { int thread_id = *((int*)arg); free(arg); while (1) { char guess[MAX_REQUEST]; // Buffer for guessed filename int size = 0; void* item = queue_consume( &prefetch_queue ); // this happens only if queue_consume_all() was called and no items remain. if( item == (void*)-1 ) { printf( "Prefetcher exiting.\n" ); pthread_exit( (void*)NULL ); } request_t* req = (request_t*)item; if (nextguess(req->filename, guess) != 0) { fprintf(stderr, "Prefetcher failed to get next guess\n"); fprintf(stderr, " --filename: %s\n", req->filename ); fprintf(stderr, " --guess: %s\n", guess ); } else { // try to get the cache entry for the guess. if it isn't there // then put it there. char* data; if (get_cache(guess, &data) == -1) { size = get_file_data(guess, &data); put_cache(guess, data, size); } } // free request created by dispatch. free( req->filename ); free( req ); } }
static int get_lang_stemmer(term_t t, struct sb_stemmer **stemmer) { stem_cache *cache = get_cache(); atom_t lang; int i; if ( !PL_get_atom(t, &lang) ) return type_error("atom", t); for(i=0; i<CACHE_SIZE; i++) { if ( cache->stemmers[i].language == lang ) { *stemmer = cache->stemmers[i].stemmer; return TRUE; } } for(i=0; i<CACHE_SIZE; i++) { if ( !cache->stemmers[i].stemmer ) { struct sb_stemmer *st; if ( !(st= sb_stemmer_new(PL_atom_chars(lang), NULL)) ) { if ( errno == ENOMEM ) return resource_error("memory"); else return domain_error("snowball_algorithm", t); } cache->stemmers[i].language = lang; cache->stemmers[i].stemmer = st; PL_register_atom(cache->stemmers[i].language); *stemmer = cache->stemmers[i].stemmer; return TRUE; } } assert(0); /* TBD: clean cache */ return FALSE; }
void map::apply_directional_light( const tripoint &p, int direction, float luminance ) { const int x = p.x; const int y = p.y; auto &cache = get_cache( p.z ); float (&lm)[MAPSIZE*SEEX][MAPSIZE*SEEY] = cache.lm; float (&transparency_cache)[MAPSIZE*SEEX][MAPSIZE*SEEY] = cache.transparency_cache; if( direction == 90 ) { castLight<1, 0, 0, -1, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); castLight<-1, 0, 0, -1, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); } else if( direction == 0 ) { castLight<0, -1, 1, 0, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); castLight<0, -1, -1, 0, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); } else if( direction == 270 ) { castLight<1, 0, 0, 1, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); castLight<-1, 0, 0, 1, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); } else if( direction == 180 ) { castLight<0, 1, 1, 0, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); castLight<0, 1, -1, 0, light_calc, light_check>( lm, transparency_cache, x, y, 0, luminance ); } }
url get_from_server (url u) { if (!is_rooted_tmfs (u)) return url_none (); url res= get_cache (u); if (!is_none (res)) return res; string name= as_string (u); if (ends (name, "~") || ends (name, "#")) { if (!is_rooted_tmfs (name)) return url_none (); if (!as_bool (call ("tmfs-can-autosave?", unglue (u, 1)))) return url_none (); } string r= as_string (call ("tmfs-load", object (name))); if (r == "") return url_none (); url tmp= url_temp (); (void) save_string (tmp, r, true); //return set_cache (u, tmp); return tmp; // FIXME: certain files could be cached, but others not // for instance, files which are loaded in a delayed fashion // would always be cached as empty files, which is erroneous. }
static const struct ext2_inode * ext2_get_inode(struct fs_info *fs, int inr) { const struct ext2_group_desc *desc; const char *data; uint32_t inode_group, inode_offset; uint32_t block_num, block_off; inr--; inode_group = inr / EXT2_INODES_PER_GROUP(fs); inode_offset = inr % EXT2_INODES_PER_GROUP(fs); desc = ext2_get_group_desc(fs, inode_group); if (!desc) return NULL; block_num = desc->bg_inode_table + inode_offset / EXT2_INODES_PER_BLOCK(fs); block_off = inode_offset % EXT2_INODES_PER_BLOCK(fs); data = get_cache(fs->fs_dev, block_num); return (const struct ext2_inode *) (data + block_off * EXT2_SB(fs)->s_inode_size); }
/* * get the group's descriptor of group_num */ static const struct ext2_group_desc * ext2_get_group_desc(struct fs_info *fs, uint32_t group_num) { struct ext2_sb_info *sbi = EXT2_SB(fs); uint32_t desc_block, desc_index; const struct ext2_group_desc *desc_data_block; if (group_num >= sbi->s_groups_count) { printf ("ext2_get_group_desc" "block_group >= groups_count - " "block_group = %d, groups_count = %d", group_num, sbi->s_groups_count); return NULL; } desc_block = group_num / sbi->s_desc_per_block; desc_index = group_num % sbi->s_desc_per_block; desc_block += sbi->s_first_data_block + 1; desc_data_block = get_cache(fs->fs_dev, desc_block); return &desc_data_block[desc_index]; }
*/ /** * \file coherence.c * \brief Initialize SMC structure, link from SMC to C. * \author ~ahonorat * \version 1.7 * \date 16th march 2014 * */ #include "coherence.h" void coherence_up_stat(struct coherence *this, struct node *node, unsigned long entry, int stats_type){ struct cache *cache = get_cache(node); up_stat(cache, entry, stats_type); } void coherence_invalid_line(struct coherence *this, struct line *line) { line->status = I; } void coherence_modify_line(struct coherence *this, struct line *line) { line->status = M; line->dirty = 1; } void coherence_share_line(struct coherence *this, struct line *line) { line->status = S;
int vpbp_dread(SceUID fd, SceIoDirent * dir) { int result, cur_idx, ret; struct IoDirentEntry *entry; lock(); entry = dirent_search(fd); if(entry == NULL) { result = -44; goto exit; } result = sceIoDread(entry->iso_dfd, dir); if(sceKernelFindModuleByName("Game_Categories_Light") == NULL) { while(result > 0 && !is_iso(dir)) { result = sceIoDread(entry->iso_dfd, dir); } } if (result > 0 && is_iso(dir)) { VirtualPBP *vpbp; vpbp = vpbp_realloc(g_vpbps, g_vpbps_cnt+1); if(vpbp == NULL) { result = -42; goto exit; } g_vpbps = vpbp; g_vpbps_cnt++; cur_idx = g_vpbps_cnt-1; vpbp = &g_vpbps[cur_idx]; STRCPY_S(vpbp->name, entry->path); vpbp->name[4] = '\0'; STRCAT_S(vpbp->name, "/ISO"); STRCAT_S(vpbp->name, entry->path + sizeof("xxx:/PSP/GAME") - 1); STRCAT_S(vpbp->name, "/"); STRCAT_S(vpbp->name, dir->d_name); memcpy(&vpbp->ctime, &dir->d_stat.st_ctime, sizeof(vpbp->ctime)); memcpy(&vpbp->mtime, &dir->d_stat.st_mtime, sizeof(vpbp->mtime)); ret = get_cache(vpbp->name, &vpbp->mtime, vpbp); if (ret < 0) { ret = build_vpbp(vpbp); if (ret < 0) { result = -43; goto exit; } } result = add_fake_dirent(dir, cur_idx); } exit: unlock(); return result; }
static ERL_NIF_TERM put(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { ERL_NIF_TERM atom; ErlNifBinary kbin, vbin; struct cache *c; struct cache_node *n, *ng; ErlNifUInt64 lifetime = 0; if (!enif_is_atom(env, argv[0])) return enif_make_badarg(env); atom = argv[0]; if (!enif_inspect_binary(env, argv[1], &kbin)) return enif_make_badarg(env); if (!enif_inspect_binary(env, argv[2], &vbin)) return enif_make_badarg(env); if ((c = get_cache(atom))) { enif_consume_timeslice(env, 1); } else { /* if we've been asked to put() in to a cache that doesn't exist yet then we should create it! */ ErlNifUInt64 max_size, min_q1_size; if (!enif_get_uint64(env, argv[3], &max_size)) return enif_make_badarg(env); if (!enif_get_uint64(env, argv[4], &min_q1_size)) return enif_make_badarg(env); c = new_cache(atom, max_size, min_q1_size); enif_consume_timeslice(env, 20); } if (argc > 5) if (!enif_get_uint64(env, argv[5], &lifetime)) return enif_make_badarg(env); n = enif_alloc(sizeof(*n)); memset(n, 0, sizeof(*n)); n->c = c; n->vsize = vbin.size; n->ksize = kbin.size; n->size = vbin.size + kbin.size; n->key = enif_alloc(kbin.size); memcpy(n->key, kbin.data, kbin.size); n->val = enif_alloc_resource(value_type, vbin.size); memcpy(n->val, vbin.data, vbin.size); n->q = &(c->q1); if (lifetime) { clock_now(&(n->expiry)); n->expiry.tv_sec += lifetime; } enif_rwlock_rwlock(c->cache_lock); enif_rwlock_rwlock(c->lookup_lock); HASH_FIND(hh, c->lookup, kbin.data, kbin.size, ng); if (ng) { enif_mutex_lock(c->ctrl_lock); destroy_cache_node(ng); enif_mutex_unlock(c->ctrl_lock); } TAILQ_INSERT_HEAD(&(c->q1.head), n, entry); c->q1.size += n->size; HASH_ADD_KEYPTR(hh, c->lookup, n->key, n->ksize, n); if (lifetime) { struct cache_node *rn; rn = RB_INSERT(expiry_tree, &(c->expiry_head), n); /* it's possible to get two timestamps that are the same, if this happens just bump us forwards by 1 usec until we're unique */ while (rn != NULL) { ++(n->expiry.tv_nsec); rn = RB_INSERT(expiry_tree, &(c->expiry_head), n); } } enif_rwlock_rwunlock(c->lookup_lock); enif_rwlock_rwunlock(c->cache_lock); enif_cond_broadcast(c->check_cond); enif_consume_timeslice(env, 50); return enif_make_atom(env, "ok"); }
static ERL_NIF_TERM get(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { ERL_NIF_TERM atom; ErlNifBinary kbin; struct cache *c; struct cache_node *n; struct cache_incr_node *in; struct timespec now; int incrqs, hashv, bkt; ERL_NIF_TERM ret; ErlNifTid tid; if (!enif_is_atom(env, argv[0])) return enif_make_badarg(env); atom = argv[0]; if (!enif_inspect_binary(env, argv[1], &kbin)) return enif_make_badarg(env); if ((c = get_cache(atom))) { enif_rwlock_rlock(c->lookup_lock); HASH_FIND(hh, c->lookup, kbin.data, kbin.size, n); if (!n) { enif_rwlock_runlock(c->lookup_lock); __sync_add_and_fetch(&c->miss, 1); enif_consume_timeslice(env, 10); return enif_make_atom(env, "notfound"); } if (n->expiry.tv_sec != 0) { clock_now(&now); if (n->expiry.tv_sec < now.tv_sec) { enif_rwlock_runlock(c->lookup_lock); __sync_add_and_fetch(&c->miss, 1); enif_consume_timeslice(env, 10); return enif_make_atom(env, "notfound"); } } in = enif_alloc(sizeof(*in)); memset(in, 0, sizeof(*in)); in->node = n; __sync_add_and_fetch(&c->hit, 1); tid = enif_thread_self(); HASH_SFH(&tid, sizeof(ErlNifTid), N_INCR_BKT, hashv, bkt); enif_mutex_lock(c->incr_lock[bkt]); TAILQ_INSERT_TAIL(&(c->incr_head[bkt]), in, entry); enif_mutex_unlock(c->incr_lock[bkt]); incrqs = __sync_add_and_fetch(&(c->incr_count), 1); ret = enif_make_resource_binary(env, n->val, n->val, n->vsize); enif_rwlock_runlock(c->lookup_lock); if (incrqs > 1024) enif_cond_broadcast(c->check_cond); enif_consume_timeslice(env, 20); return ret; } return enif_make_atom(env, "notfound"); }
/* * Map a logical sector and load it into the cache */ static const void * ext2_get_cache(struct inode *inode, block_t lblock) { block_t pblock = ext2_bmap(inode, lblock, NULL); return get_cache(inode->fs->fs_dev, pblock); }
int AModule::import_samples(AEdit *edit, int64_t start_project, int64_t edit_startproject, int64_t edit_startsource, int direction, int sample_rate, Samples *buffer, int64_t fragment_len) { int result = 0; // start in EDL samplerate int64_t start_source = start_project - edit_startproject + edit_startsource; // fragment size adjusted for speed curve int64_t speed_fragment_len = fragment_len; // boundaries of input fragment required for speed curve double max_position = 0; double min_position = 0; double speed_position = edit_startsource; // position in source where speed curve starts reading double speed_position1 = speed_position; // position in source where speed curve finishes double speed_position2 = speed_position; // Need speed curve processing int have_speed = 0; // Temporary buffer for rendering speed curve Samples *speed_buffer = buffer; const int debug = 0; if(debug) printf("AModule::import_samples %d edit=%p nested_edl=%p\n", __LINE__, edit, nested_edl); if(nested_edl && edit->channel >= nested_edl->session->audio_channels) return 1; if(debug) printf("AModule::import_samples %d\n", __LINE__); this->channel = edit->channel; if(debug) printf("AModule::import_samples %d speed_fragment_len=%ld\n", __LINE__, speed_fragment_len); // apply speed curve to source position so the timeline agrees with the playback if(track->has_speed()) { // get speed adjusted position from start of edit. FloatAuto *previous = 0; FloatAuto *next = 0; FloatAutos *speed_autos = (FloatAutos*)track->automation->autos[AUTOMATION_SPEED]; for(int64_t i = edit_startproject; i < start_project; i++) { double speed = speed_autos->get_value(i, PLAY_FORWARD, previous, next); speed_position += speed; } speed_position1 = speed_position; // calculate boundaries of input fragment required for speed curve max_position = speed_position; min_position = speed_position; for(int64_t i = start_project; i < start_project + fragment_len; i++) { double speed = speed_autos->get_value(i, PLAY_FORWARD, previous, next); speed_position += speed; if(speed_position > max_position) max_position = speed_position; if(speed_position < min_position) min_position = speed_position; } speed_position2 = speed_position; if(speed_position2 < speed_position1) { max_position += 1.0; // min_position -= 1.0; speed_fragment_len = (int64_t)(max_position - min_position); } else { max_position += 1.0; speed_fragment_len = (int64_t)(max_position - min_position); } printf("AModule::import_samples %d %f %f %f %f\n", __LINE__, min_position, max_position, speed_position1, speed_position2); // new start of source to read from file start_source = (int64_t)min_position; have_speed = 1; // swap in the temp buffer if(speed_temp && speed_temp->get_allocated() < speed_fragment_len) { delete speed_temp; speed_temp = 0; } if(!speed_temp) { speed_temp = new Samples(speed_fragment_len); } speed_buffer = speed_temp; } if(speed_fragment_len == 0) return 1; // Source is a nested EDL if(edit->nested_edl) { int command; asset = 0; if(direction == PLAY_REVERSE) command = NORMAL_REWIND; else command = NORMAL_FWD; if(debug) printf("AModule::import_samples %d\n", __LINE__); if(!nested_edl || nested_edl->id != edit->nested_edl->id) { nested_edl = edit->nested_edl; if(nested_renderengine) { delete nested_renderengine; nested_renderengine = 0; } if(!nested_command) { nested_command = new TransportCommand; } if(!nested_renderengine) { nested_command->command = command; nested_command->get_edl()->copy_all(nested_edl); nested_command->change_type = CHANGE_ALL; nested_command->realtime = renderengine->command->realtime; nested_renderengine = new RenderEngine(0, get_preferences(), 0, renderengine ? renderengine->channeldb : 0, 1); nested_renderengine->set_acache(get_cache()); // Must use a private cache for the audio // if(!cache) // { // cache = new CICache(get_preferences()); // private_cache = 1; // } // nested_renderengine->set_acache(cache); nested_renderengine->arm_command(nested_command); } } if(debug) printf("AModule::import_samples %d speed_fragment_len=%d\n", __LINE__, (int)speed_fragment_len); // Allocate output buffers for all channels for(int i = 0; i < nested_edl->session->audio_channels; i++) { if(nested_allocation < speed_fragment_len) { delete nested_output[i]; nested_output[i] = 0; } if(!nested_output[i]) { nested_output[i] = new Samples(speed_fragment_len); } } if(debug) printf("AModule::import_samples %d\n", __LINE__); if(nested_allocation < speed_fragment_len) nested_allocation = speed_fragment_len; // Update direction command nested_renderengine->command->command = command; // Render the segment if(!nested_renderengine->arender) { bzero(speed_buffer->get_data(), speed_fragment_len * sizeof(double)); } else if(sample_rate != nested_edl->session->sample_rate) { // Read through sample rate converter. if(!resample) { resample = new AModuleResample(this); } if(debug) printf("AModule::import_samples %d %d %d\n", __LINE__, (int)sample_rate, (int)nested_edl->session->sample_rate); result = resample->resample(speed_buffer, speed_fragment_len, nested_edl->session->sample_rate, sample_rate, start_source, direction); // Resample reverses to keep it running forward. if(debug) printf("AModule::import_samples %d\n", __LINE__); } else { // Render without resampling if(debug) printf("AModule::import_samples %d\n", __LINE__); result = nested_renderengine->arender->process_buffer( nested_output, speed_fragment_len, start_source); if(debug) printf("AModule::import_samples %d\n", __LINE__); memcpy(speed_buffer->get_data(), nested_output[edit->channel]->get_data(), speed_fragment_len * sizeof(double)); if(debug) printf("AModule::import_samples %d\n", __LINE__); // Reverse fragment so ::render can apply transitions going forward. if(direction == PLAY_REVERSE) { Resample::reverse_buffer(speed_buffer->get_data(), speed_fragment_len); } } if(debug) printf("AModule::import_samples %d\n", __LINE__); } else // Source is an asset if(edit->asset) { nested_edl = 0; if(debug) printf("AModule::import_samples %d\n", __LINE__); asset = edit->asset; if(debug) printf("AModule::import_samples %d\n", __LINE__); get_cache()->age(); if(debug) printf("AModule::import_samples %d\n", __LINE__); if(nested_renderengine) { delete nested_renderengine; nested_renderengine = 0; } if(debug) printf("AModule::import_samples %d\n", __LINE__); if(!(file = get_cache()->check_out( asset, get_edl()))) { // couldn't open source file / skip the edit printf(_("AModule::import_samples Couldn't open %s.\n"), asset->path); result = 1; } else { result = 0; if(sample_rate != asset->sample_rate) { // Read through sample rate converter. if(!resample) { resample = new AModuleResample(this); } if(debug) printf("AModule::import_samples %d %d %d\n", __LINE__, sample_rate, asset->sample_rate); result = resample->resample(speed_buffer, speed_fragment_len, asset->sample_rate, sample_rate, start_source, direction); // Resample reverses to keep it running forward. } else { if(debug) printf("AModule::import_samples %d channel=%d start_source=%ld len=%d\n", __LINE__, edit->channel, start_source, (int)speed_fragment_len); file->set_audio_position(start_source); file->set_channel(edit->channel); result = file->read_samples(speed_buffer, speed_fragment_len); // Reverse fragment so ::render can apply transitions going forward. if(debug) printf("AModule::import_samples %d speed_buffer=%p data=%p speed_fragment_len=%d\n", __LINE__, (void*)speed_buffer, (void*)speed_buffer->get_data(), (int)speed_fragment_len); if(direction == PLAY_REVERSE) { Resample::reverse_buffer(speed_buffer->get_data(), speed_fragment_len); } if(debug) printf("AModule::import_samples %d\n", __LINE__); } if(debug) printf("AModule::import_samples %d\n", __LINE__); get_cache()->check_in(asset); if(debug) printf("AModule::import_samples %d\n", __LINE__); file = 0; } } else { nested_edl = 0; asset = 0; if(debug) printf("AModule::import_samples %d %p %d\n", __LINE__, speed_buffer->get_data(), (int)speed_fragment_len); if(speed_fragment_len > 0) bzero(speed_buffer->get_data(), speed_fragment_len * sizeof(double)); if(debug) printf("AModule::import_samples %d\n", __LINE__); } if(debug) printf("AModule::import_samples %d\n", __LINE__); // Stretch it to fit the speed curve // Need overlapping buffers to get the interpolation to work, but this // screws up sequential effects. if(have_speed) { FloatAuto *previous = 0; FloatAuto *next = 0; FloatAutos *speed_autos = (FloatAutos*)track->automation->autos[AUTOMATION_SPEED]; double *buffer_samples = buffer->get_data(); double *speed_samples = speed_buffer->get_data(); //printf("AModule::import_samples %d %lld\n", __LINE__, speed_fragment_len); if(speed_fragment_len == 0) { bzero(buffer_samples, fragment_len * sizeof(double)); bzero(prev_tail, SPEED_OVERLAP * sizeof(double)); bzero(prev_head, SPEED_OVERLAP * sizeof(double)); } else { // buffer is now reversed if(direction == PLAY_REVERSE) { int out_offset = 0; speed_position = speed_position2; //printf("AModule::import_samples %d %lld %lld\n", __LINE__, start_project, speed_fragment_len); for(int64_t i = start_project + fragment_len; i != start_project; i--) { // funky sample reordering, because the source is a reversed buffer int in_offset = (int64_t)(speed_fragment_len - 1 - speed_position); CLAMP(in_offset, 0, speed_fragment_len - 1); buffer_samples[out_offset++] = speed_samples[in_offset]; double speed = speed_autos->get_value(i, PLAY_REVERSE, previous, next); speed_position -= speed; } //printf("AModule::import_samples %d %f\n", __LINE__, speed_position); } else { int out_offset = 0; // position in buffer to read speed_position = speed_position1 - start_source; //printf("AModule::import_samples %d %f\n", __LINE__, speed_position); for(int64_t i = start_project; i < start_project + fragment_len; i++) { double speed = speed_autos->get_value(i, PLAY_FORWARD, previous, next); double next_speed_position = speed_position + speed; int in_offset = (int)(speed_position); if(fabs(speed) >= 1.0) { int total = abs(speed); double accum = 0; for(int j = 0; j < total; j++) { int in_offset2 = in_offset + (speed > 0 ? j : -j); CLAMP(in_offset2, 0, speed_fragment_len - 1); accum += speed_samples[in_offset2]; } buffer_samples[out_offset++] = accum / total; } else { // if(in_offset < 0 || in_offset >= speed_fragment_len) // printf("AModule::import_samples %d %d %d\n", // __LINE__, // in_offset, // speed_fragment_len); int in_offset1 = in_offset; int in_offset2 = in_offset; if(speed < 0) { in_offset1 += SPEED_OVERLAP; in_offset2 = in_offset1 - 1; } else { in_offset1 -= SPEED_OVERLAP; in_offset2 = in_offset1 + 1; } CLAMP(in_offset1, -SPEED_OVERLAP, speed_fragment_len - 1 + SPEED_OVERLAP); CLAMP(in_offset2, -SPEED_OVERLAP, speed_fragment_len - 1 + SPEED_OVERLAP); double value1 = 0; if(in_offset1 >= speed_fragment_len) { value1 = prev_head[in_offset1 - speed_fragment_len]; } else if(in_offset1 >= 0) { value1 = speed_samples[in_offset1]; } else { //printf("AModule::import_samples %d %d\n", __LINE__, in_offset1); value1 = prev_tail[SPEED_OVERLAP + in_offset1]; } #if 0 double value2 = 0; if(in_offset2 >= speed_fragment_len) { value2 = prev_head[in_offset2 - speed_fragment_len]; } else if(in_offset2 >= 0) { value2 = speed_samples()[in_offset2]; } else { value2 = prev_tail[SPEED_OVERLAP + in_offset2]; } double fraction = speed_position - floor(speed_position); buffer_samples[out_offset++] = value1 * (1.0 - fraction) + value2 * fraction; #endif buffer_samples[out_offset++] = value1; } speed_position = next_speed_position; } } for(int i = 0; i < SPEED_OVERLAP; i++) { int offset = speed_fragment_len - SPEED_OVERLAP + i; CLAMP(offset, 0, speed_fragment_len - 1); //printf("AModule::import_samples %d %d\n", __LINE__, offset, ); prev_tail[i] = speed_samples[offset]; offset = i; CLAMP(offset, 0, speed_fragment_len - 1); prev_head[i] = speed_samples[offset]; } } } return result; }
/* * Create an external variant from our internal representation */ static Variant make_variant(VariantInt vi, FunctionCallInfo fcinfo, IOFuncSelector func) { VariantCache *cache; Variant v; bool oid_overflow=OID_TOO_LARGE(vi->typid); long variant_length, data_length; /* long because we subtract */ Pointer data_ptr = 0; uint flags = 0; cache = get_cache(fcinfo, vi, func); Assert(cache->typid = vi->typid); #ifdef VARIANT_TEST_OID vi->typid += OID_MASK; oid_overflow=OID_TOO_LARGE(vi->typid); #endif if(vi->isnull) { flags |= VAR_ISNULL; data_length = 0; } else if(cache->typlen == -1) /* varlena */ { /* * Short varlena is OK, but we need to make sure it's not external. It's OK * to leave compressed varlena's alone too, but detoast_packed will * uncompress them. We'll just follow rangetype.c's lead here. */ vi->data = PointerGetDatum( PG_DETOAST_DATUM_PACKED(vi->data) ); data_ptr = DatumGetPointer(vi->data); /* * Because we don't store varlena aligned or with it's header, our * data_length is simply the varlena length. */ data_length = VARSIZE_ANY_EXHDR(vi->data); data_ptr = VARDATA_ANY(data_ptr); } else if(cache->typlen == -2) /* cstring */ { data_length = strlen(DatumGetCString(vi->data)); /* We don't store NUL terminator */ data_ptr = DatumGetPointer(vi->data); } else { Assert(cache->typlen >= 0); if(cache->typbyval) { data_length = VHDRSZ; /* Start with header size to make sure alignment is correct */ data_length = (long) VDATAPTR_ALIGN(data_length, cache->typalign); data_length += cache->typlen; data_length -= VHDRSZ; } else /* fixed length, pass by reference */ { data_length = cache->typlen; data_ptr = DatumGetPointer(vi->data); } } /* If typid is too large then we need an extra byte */ variant_length = VHDRSZ + data_length + (oid_overflow ? sizeof(char) : 0); if( variant_length < 0 ) elog(ERROR, "Negative variant_length %li", variant_length); v = palloc0(variant_length); SET_VARSIZE(v, variant_length); v->pOid = vi->typid; v->typmod = vi->typmod; if(oid_overflow) { flags |= VAR_OVERFLOW; /* Reset high pOid byte to zero */ v->pOid &= 0x00FFFFFF; /* Store high byte of OID at the end of our structure */ *((char *) v + VARSIZE(v) - 1) = vi->typid >> 24; } /* * Be careful not to overwrite the valid OID data */ v->pOid |= flags; Assert( get_oid(v, &flags) == vi->typid ); if(!vi->isnull) { if(cache->typbyval) { Pointer p = VDATAPTR_ALIGN(v, cache->typalign); store_att_byval(p, vi->data, cache->typlen); } else memcpy(VDATAPTR(v), data_ptr, data_length); } return v; }
/* * make_variant_int: Converts our external (Variant) representation to a VariantInt. */ static VariantInt make_variant_int(Variant v, FunctionCallInfo fcinfo, IOFuncSelector func) { VariantCache *cache; VariantInt vi; long data_length; /* long instead of size_t because we're subtracting */ Pointer ptr; uint flags; /* Ensure v is fully detoasted */ Assert(!VARATT_IS_EXTENDED(v)); /* May need to be careful about what context this stuff is palloc'd in */ vi = palloc0(sizeof(VariantDataInt)); vi->typid = get_oid(v, &flags); #ifdef VARIANT_TEST_OID vi->typid -= OID_MASK; #endif vi->typmod = v->typmod; vi->isnull = (flags & VAR_ISNULL ? true : false); cache = get_cache(fcinfo, vi, func); /* * by-value type. We do special things with all pass-by-reference when we * store, so we only use this for typbyval even though fetch_att supports * pass-by-reference. * * Note that fetch_att sanity-checks typlen for us (because we're only passing typbyval). */ if(cache->typbyval) { if(!vi->isnull) { Pointer p = VDATAPTR_ALIGN(v, cache->typalign); vi->data = fetch_att(p, cache->typbyval, cache->typlen); } return vi; } /* we don't store a varlena header for varlena data; instead we compute * it's size based on ours: * * Our size - our header size - overflow byte (if present) * * For cstring, we don't store the trailing NUL */ data_length = VARSIZE(v) - VHDRSZ - (flags & VAR_OVERFLOW ? 1 : 0); if( data_length < 0 ) elog(ERROR, "Negative data_length %li", data_length); if (cache->typlen == -1) /* varlena */ { ptr = palloc0(data_length + VARHDRSZ); SET_VARSIZE(ptr, data_length + VARHDRSZ); memcpy(VARDATA(ptr), VDATAPTR(v), data_length); } else if(cache->typlen == -2) /* cstring */ { ptr = palloc(data_length + 1); /* Need space for NUL terminator */ memcpy(ptr, VDATAPTR(v), data_length); *(ptr + data_length + 1) = '\0'; } else /* Fixed size, pass by reference */ { if(vi->isnull) { vi->data = (Datum) 0; return vi; } Assert(data_length == cache->typlen); ptr = palloc0(data_length); Assert(ptr == (char *) att_align_nominal(ptr, cache->typalign)); memcpy(ptr, VDATAPTR(v), data_length); } vi->data = PointerGetDatum(ptr); return vi; }
void component_synchronizer<false, F>::rebuild_density(const size_t index) const { for (auto f : get_cache().fixtures_per_collider[index]) f->SetDensity(component.colliders[index].density * component.colliders[index].density_multiplier); get_cache().fixtures_per_collider[0][0]->GetBody()->ResetMassData(); }
static int bee_dep_list(int argc, char *argv[]) { int c, i, opt_count, help, files, packages, count, depending_on, required_by, removable, provider_of, not_cached, broken; struct hash *graph; char *name; struct option long_options[] = { {"help", 0, &help, 1}, {"files", 0, &files, 1}, {"packages", 0, &packages, 1}, {"count", 0, &count, 1}, {"depending-on", 0, &depending_on, 1}, {"required-by", 0, &required_by, 1}, {"removable", 0, &removable, 1}, {"provider-of", 0, &provider_of, 1}, {"not-cached", 0, ¬_cached, 1}, {"broken", 0, &broken, 1}, {0, 0, 0, 0} }; opt_count = help = files = packages = provider_of = count = depending_on = required_by = removable = not_cached = broken = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_list(); return 1; default: opt_count++; } } if (help) { usage_list(); return 0; } if (!opt_count && optind != argc) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } if (!opt_count) packages = 1; if (opt_count > 1 && !count) { fprintf(stderr, "bee-dep: too many options specified\n"); return 1; } if (packages) { graph = get_cache(); if (count) printf("%d\n", count_packages(graph)); else list_packages(graph); hash_free(graph); return 0; } if (broken && optind < argc) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } if (optind == argc && !broken) { fprintf(stderr, "bee-dep: arguments needed\n"); return 1; } if (count && (depending_on || required_by)) fprintf(stderr, "bee-dep: ignoring option --count\n"); graph = get_cache(); for (i = optind; i < argc; i++) { name = argv[i]; if (optind < argc - 1) printf("%s:\n", name); if (files) { if (count) { c = count_files(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (list_files(graph, name)) { hash_free(graph); return 1; } } if (removable) { if (count) { c = count_removable(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (print_removable(graph, name)) { hash_free(graph); return 1; } } if (depending_on && print_neededby(graph, name)) { hash_free(graph); return 1; } if (required_by && print_needs(graph, name)) { hash_free(graph); return 1; } if (provider_of) { if (count) { c = count_providers(graph, name); if (c < 0) { hash_free(graph); return 1; } printf("%d\n", c); } else if (print_providers(graph, name)) { hash_free(graph); return 1; } } if (not_cached) { c = print_not_cached(graph, name, !count); if (c < 0) { hash_free(graph); return 1; } if (count) printf("%d\n", c); } } if (broken) { c = print_broken(graph, !count); if (c < 0) { hash_free(graph); return 1; } if (count) printf("%d\n", c); } hash_free(graph); return 0; }
static int bee_dep_update(int argc, char *argv[]) { int c, help; char *pkg; char path[PATH_MAX + 1]; struct hash *graph; struct stat st; struct option long_options[] = { {"help", 0, &help, 1}, {0, 0, 0, 0} }; help = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_update(); return 1; } } if (help) { usage_update(); return 0; } if (argc == 1) { graph = get_cache(); if (update_cache(graph) || save_cache(graph, cache_filename())) { hash_free(graph); return 1; } hash_free(graph); return 0; } if (argc < 2) { fprintf(stderr, "bee-dep: pkgname needed\n"); return 1; } if (argc > 2) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } pkg = argv[1]; if (sprintf(path, "%s/%s/DEPENDENCIES", bee_metadir(), pkg) < 0) { perror("bee-dep: sprintf"); return 1; } graph = get_cache(); if (stat(path, &st) != -1) { if (hash_search(graph, pkg)) { hash_free(graph); return 0; } if (graph_insert_nodes(graph, path)) { hash_free(graph); return 1; } } else { if (remove_package(graph, pkg)) { hash_free(graph); return 1; } } if (save_cache(graph, cache_filename())) { hash_free(graph); return 1; } hash_free(graph); return 0; }