Exemple #1
0
void renderer_render(renderer *renderer, world *world, cache *cache) {
	// Clear surface
	SDL_RenderClear(renderer->sdl_renderer);

	// RenderCopy legit surfaces
	for(int i = 0; i < MAX_ENTITY; i++) {
		int mask = world->mask[i];
		if ((mask & GRAPHIC) == GRAPHIC) {
			(void)printf("Rendering entity %d with image %s\n", i, world->graphics[i].image_file);
			// Get image size and position info, if present.  Else,
			// image fills up entire screen.
			if(((mask & POSITION) == POSITION) && ((mask & SIZE) == SIZE)) {
				SDL_Rect rect;
				rect.x = world->positions[i].x;
				rect.y = world->positions[i].y;
				rect.w = world->sizes[i].x;
				rect.h = world->sizes[i].y;
				SDL_RenderCopy(renderer->sdl_renderer, cache_get(&cache, renderer->sdl_renderer, world->graphics[i].image_file), NULL, &rect);
			} else {
				SDL_RenderCopy(renderer->sdl_renderer, cache_get(&cache, renderer->sdl_renderer, world->graphics[i].image_file), NULL, NULL);
			}
		}
	}

	// Update screen surface
	SDL_RenderPresent(renderer->sdl_renderer);
}
Exemple #2
0
void test_basics()
{
    cache_t cache = create_cache(65536, NULL);
    uint32_t val_size = 0;

    const uint8_t
        *key1 = (uint8_t*)"One key",
        *key2 = (uint8_t*)"Two key",
        *key3 = (uint8_t*)"Red key";

    uint8_t *value1 = (uint8_t*) "First value";
    uint64_t value2 = 20039;
    int32_t value3 = -12;

    cache_set(cache, key1, value1, strlen((char *)value1) + 1);
    cache_set(cache, key2, &value2, sizeof(value2));
    cache_set(cache, key3, &value3, sizeof(value3));

    uint8_t *result1 = (uint8_t *)cache_get(cache, key1, &val_size);
    uint64_t *result2 = (uint64_t *)cache_get(cache, key2, &val_size);
    int32_t *result3 = (int32_t *)cache_get(cache, key3, &val_size);

    bool results_not_null = result1 != NULL && result2 != NULL && result3 != NULL;
    bool string_result_correct = strcmp((const char*)value1, (const char*)result1) == 0;
    bool uint64_result_correct = *result2 == value2;
    bool int32_result_correct = *result3 == value3;
        
    test(results_not_null, "Get returns non null pointers when retrieving valid entries.");
    test(string_result_correct, "Cache can store and retrieve strings");
    test(uint64_result_correct, "Cache can store and retrieve uint64_t integers correctly.");
    test(int32_result_correct, "Cache can store and retrieve int32_t integers correctly.");
    test(val_size == sizeof(value3), "cache_get sets val_size pointer to value size.");

    destroy_cache(cache);
}
void ExistsFeatures::get(const IntermediateExample& e, FeatureIDs& l, item_predicate_ty predicate, item_group_ty group) const {
	ItemTokens items;

	unsigned values_size = max_predicate_value(predicate)+1;
	vector<bool> exists_features(values_size, false);
	deque<unsigned> value_list;

	unsigned v;
	GroupIterator item(group, e);
	int size = item.size();
	for (; !item.end(); item++) {
		v = get_predicate_value(predicate, *item);
		if (is_binary_predicate(predicate) && v == (unsigned)false && !parameter::binary_predicates_can_have_false_value()) continue;
		exists_features.at(v) = true;
		if (size*2 < (int)values_size)
			value_list.push_back(v);
	}

	if (size*2 < (int)values_size) {
		deque<unsigned>::const_iterator i;
		for (i = value_list.begin(); i != value_list.end(); i++)
			if (exists_features.at(*i)) {
				l.push_back(cache_get(group, predicate, *i)->id());
				exists_features.at(*i) = false;
			}
	} else {
		unsigned i;
		for (i = 0; i < exists_features.size(); i++)
			if (exists_features.at(i))
				l.push_back(cache_get(group, predicate, i)->id());
	}
}
Exemple #4
0
char *mime_types_get(char *ext, int len, cache *c) {
	if (len > 1) {
		if (cache_exists(c, ext, len) == 0) {
			return cache_get(c, ext, len);
		} else {
			return cache_get(c, ".default", 8);
		}
	} else {
		return cache_get(c, ".default", 8);
	}
}
Exemple #5
0
void * bg_db_get_thumbnail(bg_db_t * db, int64_t id,
                           int max_width, int max_height,
                           const char * mimetype)
  {
  browse_t b;
  int64_t thumb_id;

  if((thumb_id = cache_get(&db->th_cache,
               id, max_width, max_height,
               mimetype)) > 0)
    return bg_db_object_query(db, thumb_id);
  
  memset(&b, 0, sizeof(b));
  b.max_width = max_width;
  b.max_height = max_height;
  b.mimetype = mimetype;

  bg_db_browse_thumbnails(db, id, browse_callback, &b);
  
  if(!b.ret)
    {
    bg_db_object_t * img = bg_db_object_query(db, id);
    b.ret = make_thumbnail(db,
                           img, max_width, max_height, mimetype);
    bg_db_object_unref(img);
    }
  cache_put(&db->th_cache,
            id,
            max_width, max_height,
            mimetype, bg_db_object_get_id(b.ret));
  return b.ret;
  }
Exemple #6
0
static int idx_get_page(IDX *idx, const long number)
{
  idx -> page_dirty = 0;
  idx -> page_number = number;

  return cache_get(idx -> cache, idx -> page_number, &idx -> page);
}
Exemple #7
0
void test_LRU(){
    cache_t cache = create_cache_fake(16*DATASIZE);

    data_t data1 = create_data(1,(DATATYPE)"123456789012345678901234567890123",8*DATASIZE); 
    data_t data2 = create_data(2,(DATATYPE)"223456789012345678901234567890123",8*DATASIZE); 
    data_t data3 = create_data(3,(DATATYPE)"111",DATASIZE); 
    
    cache_set(cache,data1->key,data1->value,data1->value_size);
    cache_set(cache,data2->key,data2->value,data2->value_size);

    //Get key1 to put it to the front of the linked_list
    cache_get(cache,data1->key,data1->value_size_ptr);

    //Set key3 to evict key2
    cache_set(cache,data3->key,data3->value,data3->value_size);
    data_existence_test(cache,data3);
    
    //key1 is supposed to be kept
    data_existence_test(cache,data1);

    
    //key2 is supposed to be evicted already
    data_nonexistence_test(cache, data2);

    test_destroy_cache(cache);
    destroy_data(data1);
    destroy_data(data2);
    destroy_data(data3);

}
Exemple #8
0
static bool_t
svcudp_recv(
	register SVCXPRT *xprt,
	struct rpc_msg *msg)
{
	register struct svcudp_data *su = su_data(xprt);
	register XDR *xdrs = &(su->su_xdrs);
	register ssize_t rlen;
	char *reply;
	unsigned long replylen;
	socklen_t len;

    again:
	len = xprt->xp_addrlen = sizeof(struct sockaddr_in);
	rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
	    0, (struct sockaddr *)&(xprt->xp_raddr), &len);
	if (rlen == -1 && errno == EINTR)
		goto again;
	if (rlen < 4*sizeof(uint32_t))
		return (FALSE);
	xprt->xp_addrlen = len;
	xdrs->x_op = XDR_DECODE;
	XDR_SETPOS(xdrs, 0);
	if (! xdr_callmsg(xdrs, msg))
		return (FALSE);
	su->su_xid = msg->rm_xid;
	if (su->su_cache != NULL) {
		if (cache_get(xprt, msg, &reply, &replylen)) {
			(void) sendto(xprt->xp_sock, reply, replylen, 0,
			  (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen);
			return (TRUE);
		}
	}
	return (TRUE);
}
Exemple #9
0
static int
_dict_read_dzip(struct _dict_stream *str, char *buf, size_t size, size_t *pret)
{
    int chunk_num = str->offset / str->chunk_size;
    size_t chunk_off = str->offset - chunk_num * str->chunk_size;
    size_t rdbytes = 0;
    int rc;
    
    while (size) {
	struct _dict_chunk_cache *cp;
	size_t n;
	
	rc = cache_get(str, chunk_num, &cp);
	if (rc)
	    break;
	n = cp->size - chunk_off; /* FIXME = str->chunk[chunk_num].length;? */
	if (n > size)
	    n = size;
	memcpy(buf, cp->buffer + chunk_off, n);
	size -= n;
	buf += n;
	rdbytes += n;
	str->offset += n;
	chunk_num++;
	chunk_off = 0;
    }
    *pret = rdbytes;
    return rc;
}
Exemple #10
0
// gadget cache copy (both cache must have the same size)
struct cache_t *cache_copy (struct cache_t *dest, struct cache_t *src)
{
    int idx_cache;
    int dest_capacity, src_capacity;
    void *copied, *cached;

    // check parameters
    if ((!dest || !src) || (src == dest)) {
        fprintf(stderr, "error: cache_copy(): Bad parameters\n");
        return NULL;
    }

    // cache must be of same sizes
    dest_capacity = cache_get_capacity(dest);
    src_capacity = cache_get_capacity(src);
    if (dest_capacity != src_capacity) {
        fprintf(stderr, "error: cache_copy(): dest and src are not of the same size\n");
        return NULL;
    }

    // copy cache
    for (idx_cache = 0; idx_cache < cache_get_size(src); idx_cache++) {
        // copying
        cached = cache_get (src, idx_cache);
        cache_set (dest, idx_cache, copied);
    }
    dest->used = src->used;

    return dest;
}
Exemple #11
0
int main(int argc,char **argv)
{
  int i;
  char *x;
  char *y;
  unsigned int u;
  uint32 ttl;

  if (!cache_init(200)) _exit(111);

  if (*argv) ++argv;

  while (x = *argv++) {
    i = str_chr(x,':');
    if (x[i])
      cache_set(x,i,x + i + 1,str_len(x) - i - 1,86400,0);
    else {
      y = cache_get(x,i,&u,&ttl,0);
      if (y)
        buffer_put(buffer_1,y,u);
      buffer_puts(buffer_1,"\n");
    }
  }

  buffer_flush(buffer_1);
  _exit(0);
}
Exemple #12
0
void op_indfun(mval *v, mint code, mval *dst)
{
	bool		rval;
	mstr		*obj, object;
	oprtype		x;
	unsigned char	argcode;

	error_def(ERR_INDMAXNEST);

	argcode = (unsigned char)code;
	assert(UCHAR_MAX >= code); /* if not, the assignment to argcode is lossy */
	assert(indir_opcode[argcode]);
	MV_FORCE_STR(v);
	if (!(obj = cache_get(argcode, &v->str)))
	{
		comp_init(&v->str);
		rval = (*indir_fcn[argcode])(&x, indir_opcode[argcode]);
		if (!comp_fini(rval, &object, OC_IRETMVAL, &x, v->str.len))
			return;
		cache_put(argcode, &v->str, &object);
		*ind_result_sp++ = dst;
		if (ind_result_sp >= ind_result_top)
			rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
		comp_indr(&object);
		return;
	}
	*ind_result_sp++ = dst;
	if (ind_result_sp >= ind_result_top)
		rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
	comp_indr(obj);
	return;
}
Exemple #13
0
url
resolve_tex (url name) {
  string s= as_string (name);
  if (is_cached ("font_cache.scm", s)) {
    url u= url_system (cache_get ("font_cache.scm", s) -> label);
    if (exists (u)) return u;
    cache_reset ("font_cache.scm", s);
  }

  bench_start ("resolve tex");
  url u= url_none ();
  if (ends (s, "mf" )) {
    u= resolve_tfm (name);
#ifdef OS_WIN32
    if (is_none (u))
      u= resolve_tfm (replace (s, ".mf", ".tfm"));
#endif
  }
  if (ends (s, "tfm")) u= resolve_tfm (name);
  if (ends (s, "pk" )) u= resolve_pk  (name);
  if (ends (s, "pfb")) u= resolve_pfb (name);
  bench_cumul ("resolve tex");

  if (!is_none (u)) cache_set ("font_cache.scm", s, as_string (u));
  //cout << "Resolve " << name << " -> " << u << "\n";
  return u;
}
Exemple #14
0
/*
 * Asks the paxos master for the metric value
 * name: find_replicated
 * @param name metric name
 * @param hostname 
 * @param timestamp
 * @return value
 */
char * find_replicated(char *hostname, char *name, time_t *timestamp) {
    FILE *stream;
    char *value, * tstp, *resp, * cookie;
    char *host, *ret;

    if (_PAXOS_DEBUG) pax_log(LOG_DEBUG, "Find replicated\n");
    net_proto(NPROTO_AUTO);
    host = get_host(&node); /*Find the master*/
    if (host == NULL) return NULL;
    stream = cache_connect_net(host, PBS_CACHE_PORT);
    free(host);
    if (stream != NULL) {
        resp = cache_get(stream, hostname, name);
        if ((tstp = strtok_r(resp, "\t", &cookie)) == NULL) {
            pax_log(LOG_ERR, "Incomplete metric message\n");
            cache_close(stream);
            return NULL;
        }

        if ((value = strtok_r(cookie, "\n", &cookie)) == NULL) {
            pax_log(LOG_ERR, "Incomplete metric message\n");
            cache_close(stream);
            return NULL;
        }
        *timestamp = atol(tstp);
        cache_close(stream);
    } else {
        pax_log(LOG_ERR, "cache_connect failed\n");
        return NULL;
    }
    ret = strdup(value);
    free(resp);
    return ret;
}
Exemple #15
0
void	op_indpat(mval *v, mval *dst)
{
	bool		rval;
	mstr		*obj, object;
	oprtype		x;
	error_def(ERR_INDMAXNEST);

	MV_FORCE_STR(v);
	if (!(obj = cache_get(indir_pattern, &v->str)))
	{
		comp_init(&v->str);
		source_column = 1;	/* to coordinate with scanner redirection*/
		rval = compile_pattern(&x,window_token == TK_ATSIGN);
		if (comp_fini(rval, &object, OC_IRETMVAL, &x, v->str.len))
		{
			cache_put(indir_pattern, &v->str, &object);
			*ind_result_sp++ = dst;
			if (ind_result_sp >= ind_result_top)
				rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
			comp_indr(&object);
		}
	}
	else
	{
		*ind_result_sp++ = dst;
		if (ind_result_sp >= ind_result_top)
			rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
		comp_indr(obj);
	}
}
Exemple #16
0
void test_gets(uint8_t* keys, uint32_t* values, uint64_t numpairs)
{
  cache_t cache = create_cache(numpairs*10);

  char **keystrings = calloc(numpairs,sizeof(char*));
  char **valstrings = calloc(numpairs,sizeof(char*));

  for(int i = 0; i < numpairs; ++i)
    {
      keystrings[i] = calloc(keys[i],1);
      valstrings[i] = calloc(values[i],1);
      memset(keystrings[i],'K',keys[i]);
      memset(valstrings[i],'V',values[i]);
      keystrings[i][keys[i] - 1] = '\0';
      valstrings[i][values[i] - 1] = '\0';
      cache_set(cache,keystrings[i],valstrings[i],values[i]);
      free(valstrings[i]);
    }
  free(valstrings);

  uint32_t val_size = 0;

  // Get the timebase info
  // mach_timebase_info_data_t info;
  // mach_timebase_info(&info);

  uint64_t errors = 0;
  const uint64_t requests = numpairs;
  const double nsToSec = 1000000000;
  const uint32_t nsToms = 1000000;
  // uint64_t start = mach_absolute_time();
  struct timespec start, end;
  clock_gettime(CLOCK_MONOTONIC,&start);
  for(int i = 0; i < requests; ++i)
    {
      if( cache_get(cache,keystrings[i],&val_size) == -1) ++errors;
      //if( val_size == 0) ++errors;
      //val_size = 0;
    }
  // uint64_t end = mach_absolute_time();
  clock_gettime(CLOCK_MONOTONIC,&end);
  // uint64_t duration = end - start;
  uint64_t duration = (end.tv_sec * nsToSec + end.tv_nsec) - (start.tv_sec * nsToSec + start.tv_nsec);

  // Convert to nanoseconds
  // duration *= info.numer;
  // duration /= info.denom;

  uint64_t ns = duration;
  double time_elapsed_sec = (double) duration / nsToSec;

  double requests_per_second = (double) requests / time_elapsed_sec;
  double ms = (double) ns / (requests * nsToms);

  printf("Time per Get: %f milliseconds\n",ms);
  printf("Requests per second: %f requests\n",requests_per_second);
  printf("Percent of Requests that failed: %f,%d,%d\n",((double)errors/requests),errors,requests);

  destroy_cache(cache);
}
Exemple #17
0
static int
stormfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
  int result;
  struct stat st;
  struct file *f;

  DEBUG("create: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  cache_invalidate_dir(path);

  f = cache_get(path);
  fi->fh = cache_create_file(f);

  st.st_gid = getgid();
  st.st_uid = getuid();
  st.st_mode = mode;
  st.st_ctime = time(NULL);
  st.st_mtime = time(NULL);

  if((result = proxy_create(path, &st)) != 0)
    return result;

  pthread_mutex_lock(&f->lock);
  if(f->st == NULL)
    f->st = g_new0(struct stat, 1);
  memcpy(f->st, &st, sizeof(struct stat));
  cache_touch(f);
  pthread_mutex_unlock(&f->lock);

  return result;
}
Exemple #18
0
static int
stormfs_chmod(const char *path, mode_t mode)
{
  int result;
  struct file *f;
  struct stat st;

  DEBUG("chmod: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if((result = stormfs_getattr(path, &st)) != 0)
    return result;

  st.st_mode = mode;
  st.st_ctime = time(NULL);
  st.st_mtime = time(NULL);

  if((result = proxy_chmod(path, &st)) != 0)
    return result;

  f = cache_get(path);
  if(cache_valid(f) && f->st != NULL) {
    pthread_mutex_lock(&f->lock);
    f->st->st_mode = mode;
    f->st->st_ctime = st.st_ctime;
    f->st->st_mtime = st.st_mtime;
    cache_touch(f);
    pthread_mutex_unlock(&f->lock);
  }

  return result;
}
Exemple #19
0
static int
stormfs_utimens(const char *path, const struct timespec ts[2])
{
  int result;
  struct file *f;
  struct stat st;

  DEBUG("utimens: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if((result = stormfs_getattr(path, &st)) != 0)
    return result;

  st.st_mtime = ts[1].tv_sec;

  if((result = proxy_utimens(path, &st)) != 0)
    return result;

  f = cache_get(path);
  if(cache_valid(f) && f->st != NULL) {
    pthread_mutex_lock(&f->lock);
    f->st->st_mtime = st.st_mtime;
    cache_touch(f);
    pthread_mutex_unlock(&f->lock);
  }

  return result;
}
Exemple #20
0
static int
stormfs_truncate(const char *path, off_t size)
{
  int fd;
  int result;
  struct stat st;
  struct file *f;

  DEBUG("truncate: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if((result = stormfs_getattr(path, &st)) != 0)
    return -result;

  f = cache_get(path);
  if(cache_file_valid(f)) {
    char *cp = cache_path(f);
    if((result = truncate(cp, size)) != 0)
      perror("truncate");
    free(cp);
  } else {
    fd = cache_create_file(f);
    close(fd);
  }

  pthread_mutex_lock(&f->lock);
  f->st->st_size = get_blocks(size);
  cache_touch(f);
  pthread_mutex_unlock(&f->lock);

  return 0;
}
void	op_indpat(mval *v, mval *dst)
{
	int		rval;
	icode_str	indir_src;
	mstr		*obj, object;
	oprtype		x, getdst;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	MV_FORCE_STR(v);
	indir_src.str = v->str;
	indir_src.code = indir_pattern;
	if (NULL == (obj = cache_get(&indir_src)))
	{
		obj = &object;
		comp_init(&v->str, &getdst);
		source_column = 1;	/* to coordinate with scanner redirection*/
		rval = compile_pattern(&x, (TK_ATSIGN == TREF(window_token)));
		if (EXPR_FAIL == comp_fini(rval, obj, OC_IRETMVAL, &x, &getdst, v->str.len))
			return;
		indir_src.str.addr = v->str.addr;
		cache_put(&indir_src, obj);
		/* Fall into code activation below */
	}
	TREF(ind_result) = dst;					/* Where to store return value */
	comp_indr(obj);
	return;
}
Exemple #22
0
/* Perform various actions on a cache and check it's statistics. */
int main() {
  cache_t cache = CACHE_INIT;
  char *data;
  char *data1 = "data1";
  size_t dlen;
  uint8_t i;
  char *key1 = "key1";
  uint32_t ttl;
  
  if (!cache_init(&cache, 512))
    return 1;
    
  for (i = 1; i < UINT8_MAX; i++) {
    cache_set(&cache, key1, strlen(key1), data1, strlen(data1), CACHE_MAX_TTL);
  }
  
  cache_get(&cache, key1, strlen(key1), &dlen, &ttl);
  
  if (cache.stats.get != 1)
    return 2;
  if (cache.stats.set != 254)
    return 3;
  if (cache.stats.motion != (CACHE_HEADER_SIZE + 9) * cache.stats.set)
    return 4;
    
  cache_free(&cache);
  
  return 0;
}
Exemple #23
0
bool
is_up_to_date (url dir) {
  string name_dir= concretize (dir);
  if (cache_valid->contains (name_dir)) return cache_valid [name_dir];
  int l= last_modified (dir, false);
  if (is_cached ("validate_cache.scm", name_dir)) {
    int r= as_int (cache_get ("validate_cache.scm", name_dir) -> label);
    if (l == r) {
      cache_valid (name_dir)= true;
      return true;
    }
    //cout << name_dir << " no longer up to date " << r << " -> " << l << "\n";
  }
  //else cout << name_dir << " not up to date " << l << "\n";
  cache_set ("validate_cache.scm", name_dir, as_string (l));
  cache_valid (name_dir)= false;
  // FIXME: we should explicitly remove all data concerning files in 'dir'
  // from the various caches.  Indeed, at a next run of TeXmacs, the directory
  // will be regarded as up to date, but the other caches may still contain
  // outdated data.  Careful: invalidating the cache lines should not
  // give rise to a performance penaly (e.g. go through all entries of
  // 'cache_data', or reloading unchanged files many times).
  // See also 'declare_out_of_date'.
  return false;
}
Exemple #24
0
/*
 * Look for the desired credentials in the cache, if possible.  If we find
 * them, put them in ctx->reply_creds and advance the state to STATE_COMPLETE.
 * Return successfully even if creds are not found, unless the caller only
 * wanted cached creds.
 */
static krb5_error_code
check_cache(krb5_context context, krb5_tkt_creds_context ctx)
{
    krb5_error_code code;
    krb5_creds mcreds;
    krb5_flags fields;

    /* For constrained delegation, the expected result is in second_ticket, so
     * we can't really do a cache check here. */
    if (ctx->req_options & KRB5_GC_CONSTRAINED_DELEGATION)
        return (ctx->req_options & KRB5_GC_CACHED) ? KRB5_CC_NOTFOUND : 0;

    /* Perform the cache lookup. */
    code = krb5int_construct_matching_creds(context, ctx->req_options,
                                            ctx->in_creds, &mcreds, &fields);
    if (code)
        return code;
    code = cache_get(context, ctx->ccache, fields, &mcreds, &ctx->reply_creds);
    if (code == 0) {
        ctx->state = STATE_COMPLETE;
        return 0;
    }

    /* Stop on unexpected cache errors. */
    if (code != KRB5_CC_NOTFOUND && code != KRB5_CC_NOT_KTYPE)
        return code;

    /* Stop if the caller only wanted cached creds. */
    if (ctx->req_options & KRB5_GC_CACHED)
        return code;

    /* Remember whether the cache lookup failed due to enctypes or not. */
    ctx->cache_code = code;
    return 0;
}
Exemple #25
0
void	op_indglvn(mval *v,mval *dst)
{
	bool		rval;
	mstr		*obj, object;
	oprtype		x;
	lv_val 		*a;
	icode_str	indir_src;
	lv_val		*lv;
	var_tabent	targ_key;
	ht_ent_mname	*tabent;

	error_def(ERR_INDMAXNEST);
	error_def(ERR_UNDEF);

	MV_FORCE_STR(v);
	indir_src.str = v->str;
	indir_src.code = indir_glvn;
	if (NULL == (obj = cache_get(&indir_src)))
	{
		if (valid_mname(&v->str))
		{
			targ_key.var_name = v->str;
			COMPUTE_HASH_MNAME(&targ_key);
			tabent = lookup_hashtab_mname(&curr_symval->h_symtab, &targ_key);
			assert(NULL == tabent ||  NULL != tabent->value);
			if (!tabent || !MV_DEFINED(&((lv_val *)tabent->value)->v))
			{
				if (undef_inhibit)
				{
					*dst = literal_null;
					return;
				}
				else
					rts_error(VARLSTCNT(4) ERR_UNDEF, 2, v->str.len, v->str.addr);
			}
			a = (lv_val *)tabent->value;
			*dst = a->v;
			return;
		}
		comp_init(&v->str);
		rval = glvn(&x);
		if (comp_fini(rval, &object, OC_IRETMVAL, &x, v->str.len))
		{
			indir_src.str.addr = v->str.addr;
			cache_put(&indir_src, &object);
			*ind_result_sp++ = dst;
			if (ind_result_sp >= ind_result_top)
				rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
			comp_indr(&object);
		}
	}
	else
	{
		*ind_result_sp++ = dst;
		if (ind_result_sp >= ind_result_top)
			rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
		comp_indr(obj);
	}
}
Exemple #26
0
static void test_sunrpc_cache(void){
	struct cache_head head;
	struct cache_detail detail;

	cache_get(&head);
	cache_put(&head, &detail);
	printk("finished cache test\n");
}
Exemple #27
0
static bool
oid2name_get_name(uint32 oid, char *buf, size_t buflen, const char *query)
{
	if (cache_get(oid))
	{
		snprintf(buf, buflen, "%s", cache_get(oid));
		return true;
	}

	if ( oid2name_query(buf, buflen, query) )
	{
		cache_put(oid, buf);
		return true;
	}

	snprintf(buf, buflen, "%u", oid);
	return false;
}
Exemple #28
0
		T *cache_swap(T *next){
			if(!next){
				GLCacheEntry *e=cache_pop(next);
				return static_cast<T*>(e);
			}
			GLCacheEntry *&e=cache_get(typeid(T)), *old=e;
			e=next;
			return static_cast<T*>(old);
		}
Exemple #29
0
/**
 * @param selidx filelist中的文件位置
 * @param where 文件位置类型
 *
 */
static int cache_add_by_selidx(dword selidx, int where)
{
	t_fs_filetype type;
	cache_image_t img;
	const char *archname;
	const char *filename;
	dword filesize;

	archname = config.shortpath;

	if (where == scene_in_dir) {
		filename = filelist[selidx].shortname->ptr;
	} else {
		filename = filelist[selidx].compname->ptr;
	}

	filesize = filelist[selidx].data3;

	type = fs_file_get_type(filename);

	if (!fs_is_image(type)) {
		return -1;
	}

	if (cache_get(archname, filename) != NULL) {
		dbg_printf(d, "SERVER: %s: Image %s duplicate load, FIXME", __func__,
				   filename);

		return -1;
	}

	cache_lock();

	memset(&img, 0, sizeof(img));
	img.archname = archname;
	img.filename = filename;
	img.where = where;
	img.status = CACHE_INIT;
	img.selidx = selidx;
	img.filesize = filesize;

	if (ccacher.caches_size < ccacher.caches_cap) {
		ccacher.caches[ccacher.caches_size] = img;
		ccacher.caches_size++;
		cacher_cleared = false;
	} else {
		dbg_printf(d, "SERVER: cannot add cache any more: size %u cap %u",
				   ccacher.caches_size, ccacher.caches_cap);
		cache_unlock();

		return -1;
	}
	cache_unlock();

	return 0;
}
Exemple #30
0
void	op_indlvarg(mval *v, mval *dst)
{
	bool		rval;
	mstr		*obj, object;
	oprtype		x;
	triple		*ref;
	icode_str	indir_src;

	error_def(ERR_INDMAXNEST);
	error_def(ERR_VAREXPECTED);

	MV_FORCE_STR(v);
	if (v->str.len < 1)
		rts_error(VARLSTCNT(1) ERR_VAREXPECTED);
	if (valid_mname(&v->str))
	{
		*dst = *v;
		dst->mvtype &= ~MV_ALIASCONT;	/* Make sure alias container property does not pass */
		return;
	}
	if (*v->str.addr == '@')
	{
		indir_src.str = v->str;
		indir_src.code = indir_lvarg;
		if (NULL == (obj = cache_get(&indir_src)))
		{
			object.addr = v->str.addr;
			object.len  = v->str.len;
			comp_init(&object);
			if (rval = indirection(&x))
			{
				ref = newtriple(OC_INDLVARG);
				ref->operand[0] = x;
				x = put_tref(ref);
			}
			if (comp_fini(rval, &object, OC_IRETMVAL, &x, object.len))
			{
				indir_src.str.addr = v->str.addr;
				cache_put(&indir_src, &object);
				*ind_result_sp++ = dst;
				if (ind_result_sp >= ind_result_top)
					rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
				comp_indr(&object);
				return;
			}
		} else
		{
			*ind_result_sp++ = dst;
			if (ind_result_sp >= ind_result_top)
				rts_error(VARLSTCNT(1) ERR_INDMAXNEST);
			comp_indr(obj);
			return;
		}
	}
	rts_error(VARLSTCNT(1) ERR_VAREXPECTED);
}