当前位置: 首页>>代码示例>>C++>>正文


C++ cache_insert函数代码示例

本文整理汇总了C++中cache_insert函数的典型用法代码示例。如果您正苦于以下问题:C++ cache_insert函数的具体用法?C++ cache_insert怎么用?C++ cache_insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cache_insert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: do_server_request

static void
do_server_request(struct server *sv, int connfd)
{
	int ret;
	struct request *rq;
	struct file_data *data;
	data = file_data_init();	
	rq = request_init(connfd, data);
	
	if (!rq) {
		file_data_free(data);
		return;
	}
	
	if(cache_active ==1){
		pthread_mutex_lock( &conditionMutex); 
		struct hash_node *cache_stored; 
		cache_stored= cache_lookup(data->file_name);
		
		if(cache_stored!=NULL){  // check if it populated in the cache{
			data->file_buf = Malloc(cache_stored->data->file_size);
			strncpy(data->file_buf, cache_stored->data->file_buf, cache_stored->data->file_size);
			data->file_size =cache_stored->data->file_size;
		}
		else{
		/* reads file, 
	 	* fills data->file_buf with the file contents,
	 	* data->file_size with file size. */
	 	pthread_mutex_unlock( &conditionMutex ); 
		ret = request_readfile(rq);
		pthread_mutex_lock( &conditionMutex ); 
		// need to renew the cache
			if(data->file_size<max_cache){
				if(data->file_size <=(max_cache-cache_current_size) ){
					cache_insert(data);
				}
				else{
					cache_evict(data->file_size);
					cache_insert(data);
				}
			}
		}
		pthread_mutex_unlock( &conditionMutex ); 


	}	
	else{
		ret = request_readfile(rq);
		if (!ret)
		goto out;
	}
	/* sends file to client */
	request_sendfile(rq);
out:
	request_destroy(rq);
	file_data_free(data);
}
开发者ID:miki2112,项目名称:multi_threaded_web_server,代码行数:57,代码来源:server_thread.c

示例2: update_block_list

int
update_block_list(char *addr, int err_level)
{
    size_t addr_len = strlen(addr);

    if (cache_key_exist(block_list, addr, addr_len)) {
        int *count = NULL;
        cache_lookup(block_list, addr, addr_len, &count);
        if (count != NULL) {
            if (*count > MAX_TRIES)
                return 1;
            (*count) += err_level;
        }
    } else if (err_level > 0) {
        int *count = (int *)ss_malloc(sizeof(int));
        *count = 1;
        cache_insert(block_list, addr, addr_len, count);
#ifdef __linux__
        if (mode != NO_FIREWALL_MODE)
            set_firewall_rule(addr, 1);
#endif
    }

    return 0;
}
开发者ID:ss-plus,项目名称:shadowsocksR-libev,代码行数:25,代码来源:acl.c

示例3: cache_insert

void memory_c::fill_queue() 
{

	/* For Lab #2, you need to fill out this function */ 
	/* CAUTION!: This function is not completed. Please complete this function */ 

	if (dram_out_queue.empty()) 
		return; 
	
	dram_out_queue.sort();
	mem_req_s *req = dram_out_queue.front(); 
	dram_out_queue.pop_front(); 

	/* insert into cache */
	cache_insert(data_cache,req->m_addr);

	/* search for matching mshr entry */ 
	m_mshr_entry_s *entry = search_matching_mshr(req->m_addr); 


	while(entry->req_ops.size())
	{
		Op *w_op = entry->req_ops.front();
		broadcast_rdy_op(w_op); 
		entry->req_ops.pop_front(); 
	}

	/* The following code will free mshr entry */ 
	list<m_mshr_entry_s *>::iterator mii = search_matching_mshr_itr(req->m_addr); 
	m_mshr.erase(mii); 

	free_mshr_entry(entry); 
  
}
开发者ID:rvbelapure,项目名称:comparch,代码行数:34,代码来源:memory.cpp

示例4: l2_cache_fill

void l2_cache_fill(int cpu_num, unsigned long long int addr, int set, int way, int prefetch, unsigned long long int evicted_addr)
{
  // uncomment this line to see the information available to you when there is a cache fill event
  //printf("0x%llx %d %d %d 0x%llx\n", addr, set, way, prefetch, evicted_addr);

  cache_insert(addr, prefetch);
  if (prefetch==1) {
    prefetch_tot_num++;


    // Insert Evicted address into pollution filter
    // only if it is not prefetch
    int found = cache_search(evicted_addr);
    if (found == -1) {
      if (evicted_addr != 0) {
      printf("ERROR: evicted address not in the cache - %llx \n", evicted_addr);
      exit(1);
      }
    }
    else 
      if (cache[found].pf != 1)
        poll_insert(evicted_addr);

    poll_remove(addr);
    
  }

  cache_remove(evicted_addr);
  
}
开发者ID:ramyadhadidi,项目名称:DPC2,代码行数:30,代码来源:ampmE__prefetcher.c

示例5: gss_OID_loc_to_sap

/*
 * When the local GSS-API library returns a single OID to the caller,
 * this gss_OID is assumed to be a pointer to stable storage, and need
 * not be freed by the caller.  We cannot return this structure directly
 * to the caller, since it is in the incorrect ABI.  (Neither can we
 * modify that stable storage directly, as it would break internal users
 * of the OID, violate the hosts alignment expectations, attempt a write
 * to immutable storage, or other bad things.)  We must return a translated
 * copy instead.  However, to retain the "caller does not free" property,
 * we must cache the values we hand out, and only ever allocate one OID
 * structure in the SAP ABI for any given OID.
 *
 * Returns 0 on success, and errno on failure.
 */
static int
gss_OID_loc_to_sap(gss_OID loc, sapgss_OID *sap)
{
    sapgss_OID s;
    int code;

    if (sap == NULL)
	return 0;
    if (loc == NULL) {
	*sap = NULL;
	return 0;
    }
    /* Try to find a cached copy to use. */
    s = cache_lookup(loc);

    if (s != NULL) {
	*sap = s;
	return 0;
    } /* else */

    /* Try to insert it into the cache.  Success here means that the next
     * lookup will succeed. */
    code = cache_insert(loc);
    if (code != 0) {
	*sap = NULL;
	return code;
    }
    *sap = cache_lookup(loc);
    return 0;
}
开发者ID:Aribaaa,项目名称:osxsnc,代码行数:44,代码来源:sncgss.c

示例6: dri_getdata

/*
 * load dri data
 *   type: data type
 *   no  : file no ( >= 0 )
 *   return: loaded dridata object
*/
dridata *ald_getdata(DRIFILETYPE type, int no) {
	dridata *ddata;
	
	/* check wrong request number */
	if (no < 0) return NULL;
	
	/* check wrong type */
	if (type >= DRIFILETYPEMAX) return NULL;
	
	/* check uninitilized data */
	if (dri[type] == NULL) return NULL;
	
	/* if mmapped */
	if (dri[type]->mmapped) return dri_getdata(dri[type], no);
	
	/* not mmapped */
	if (NULL == (ddata = (dridata *)cache_foreach(cacheid, (type << 16) + no))) {
		ddata = dri_getdata(dri[type], no);
		if (ddata != NULL) {
			cache_insert(cacheid, (type << 16) + no, (void *)ddata, ddata->size, &(ddata->in_use));
			ddata->in_use = TRUE;
		}
	}
	
	return ddata;
}
开发者ID:avan06,项目名称:ONScripter-CN,代码行数:32,代码来源:ald_manager.c

示例7: save_xbzrle_page

static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data,
                            ram_addr_t current_addr, RAMBlock *block,
                            ram_addr_t offset, int cont, bool last_stage)
{
    int encoded_len = 0, bytes_sent = -1;
    uint8_t *prev_cached_page;

    if (!cache_is_cached(XBZRLE.cache, current_addr)) {
        acct_info.xbzrle_cache_miss++;
        if (!last_stage) {
            if (cache_insert(XBZRLE.cache, current_addr, *current_data) == -1) {
                return -1;
            } else {
                /* update *current_data when the page has been
                   inserted into cache */
                *current_data = get_cached_data(XBZRLE.cache, current_addr);
            }
        }
        return -1;
    }

    prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);

    /* save current buffer into memory */
    memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE);

    /* XBZRLE encoding (if there is no overflow) */
    encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,
                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
                                       TARGET_PAGE_SIZE);
    if (encoded_len == 0) {
        DPRINTF("Skipping unmodified page\n");
        return 0;
    } else if (encoded_len == -1) {
        DPRINTF("Overflow\n");
        acct_info.xbzrle_overflows++;
        /* update data in the cache */
        if (!last_stage) {
            memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE);
            *current_data = prev_cached_page;
        }
        return -1;
    }

    /* we need to update the data in the cache, in order to get the same data */
    if (!last_stage) {
        memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);
    }

    /* Send XBZRLE based compressed page */
    bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
    qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
    qemu_put_be16(f, encoded_len);
    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
    bytes_sent += encoded_len + 1 + 2;
    acct_info.xbzrle_pages++;
    acct_info.xbzrle_bytes += bytes_sent;

    return bytes_sent;
}
开发者ID:DrCheadar,项目名称:orp,代码行数:60,代码来源:arch_init.c

示例8: client_recv_cb

static void
client_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) {
    struct server_context *server = container_of(handle, struct server_context, udp);
    if (nread > 0) {
        char key[KEY_BYTES + 1] = {0};
        crypto_generickey((uint8_t *)key, sizeof(key) -1, (uint8_t*)addr, sizeof(*addr), NULL, 0);

        struct client_context *client = NULL;
        uv_mutex_lock(&mutex);
        cache_lookup(cache, key, (void *)&client);
        uv_mutex_unlock(&mutex);

        if (client == NULL) {
            client = new_client();
            client->addr = *addr;
            client->local_handle = handle;
            memcpy(client->key, key, sizeof(key));
            uv_timer_init(handle->loop, client->timer);
            uv_udp_init(handle->loop, &client->server_handle);
            client->server_handle.data = client;
            uv_udp_recv_start(&client->server_handle, server_alloc_cb, server_recv_cb);
            uv_mutex_lock(&mutex);
            cache_insert(cache, client->key, (void *)client);
            uv_mutex_unlock(&mutex);
        }

        int clen = nread + PRIMITIVE_BYTES + addrlen;
        int mlen = nread + addrlen;
        uint8_t *c = (uint8_t *)buf->base - PRIMITIVE_BYTES - addrlen;
        uint8_t *m = (uint8_t *)buf->base - addrlen;

        if (server->dest_addr->sa_family == AF_INET) {
            struct sockaddr_in *addr = (struct sockaddr_in *)server->dest_addr;
            m[0] = 1;
            memcpy(m + 1, &addr->sin_addr, 4);
            memcpy(m + 1 + 4, &addr->sin_port, 2);
        } else {
            struct sockaddr_in6 *addr = (struct sockaddr_in6 *)server->dest_addr;
            m[0] = 4;
            memcpy(m + 1, &addr->sin6_addr, 16);
            memcpy(m + 1 + 16, &addr->sin6_port, 2);
        }

        int rc = crypto_encrypt(c, m, mlen);
        if (!rc) {
            reset_timer(client);
            forward_to_server(server->server_addr, client, c, clen);
        }

    } else {
        goto error;
    }

    return;

error:
    free(buf->base - addrlen - PRIMITIVE_BYTES);
}
开发者ID:sinme,项目名称:xsocks-1,代码行数:58,代码来源:xforwarder_udprelay.c

示例9: cache_write

void cache_write(cache_m *scheduler, cache_n *node) 
{
    web_P(&scheduler->w);
    while (scheduler->total_size + node->size > MAX_CACHE_SIZE) {
	cache_remove(scheduler, scheduler->head.prev);
    }
    cache_insert(scheduler, node);
    web_V(&scheduler->w);
}
开发者ID:doublequan,项目名称:CSAPP,代码行数:9,代码来源:cache.c

示例10: cache_resize

int64_t cache_resize(PageCache *cache, int64_t new_num_pages)
{
    PageCache *new_cache;
    int64_t i;

    CacheItem *old_it, *new_it;

    g_assert(cache);

    /* cache was not inited */
    if (cache->page_cache == NULL) {
        return -1;
    }

    /* same size */
    if (pow2floor(new_num_pages) == cache->max_num_items) {
        return cache->max_num_items;
    }

    new_cache = cache_init(new_num_pages, cache->page_size);
    if (!(new_cache)) {
        DPRINTF("Error creating new cache\n");
        return -1;
    }

    /* move all data from old cache */
    for (i = 0; i < cache->max_num_items; i++) {
        old_it = &cache->page_cache[i];
        if (old_it->it_addr != -1) {
            /* check for collision, if there is, keep MRU page */
            new_it = cache_get_by_addr(new_cache, old_it->it_addr);
            if (new_it->it_data) {
                /* keep the MRU page */
                if (new_it->it_age >= old_it->it_age) {
                    g_free(old_it->it_data);
                } else {
                    g_free(new_it->it_data);
                    new_it->it_data = old_it->it_data;
                    new_it->it_age = old_it->it_age;
                    new_it->it_addr = old_it->it_addr;
                }
            } else {
                cache_insert(new_cache, old_it->it_addr, old_it->it_data);
            }
        }
    }

    g_free(cache->page_cache);
    cache->page_cache = new_cache->page_cache;
    cache->max_num_items = new_cache->max_num_items;
    cache->num_items = new_cache->num_items;

    g_free(new_cache);

    return cache->max_num_items;
}
开发者ID:sartakov,项目名称:nv-qemu,代码行数:56,代码来源:page_cache.c

示例11: xbzrle_cache_zero_page

/* Update the xbzrle cache to reflect a page that's been sent as all 0.
 * The important thing is that a stale (not-yet-0'd) page be replaced
 * by the new data.
 * As a bonus, if the page wasn't in the cache it gets added so that
 * when a small write is made into the 0'd page it gets XBZRLE sent
 */
static void xbzrle_cache_zero_page(ram_addr_t current_addr)
{
    if (ram_bulk_stage || !migrate_use_xbzrle()) {
        return;
    }

    /* We don't care if this fails to allocate a new cache page
     * as long as it updated an old one */
    cache_insert(XBZRLE.cache, current_addr, ZERO_TARGET_PAGE);
}
开发者ID:Annovae,项目名称:qemu,代码行数:16,代码来源:arch_init.c

示例12: idmap_lookup_group

static int idmap_lookup_group(
    struct idmap_context *context,
    const struct idmap_lookup *lookup,
    struct idmap_group *group)
{
    PCHAR* values[NUM_ATTRIBUTES] = { NULL };
    const unsigned attributes = ATTR_FLAG(ATTR_GROUP_NAME)
        | ATTR_FLAG(ATTR_GID);
    int i, status;

    /* check the group cache for an existing entry */
    status = cache_lookup(&context->groups, lookup, &group->entry);
    if (status == NO_ERROR) {
        /* don't return expired entries; query new attributes
         * and overwrite the entry with cache_insert() */
        if (time(NULL) - group->last_updated < context->config.cache_ttl)
            goto out;
    }

    /* send the query to the ldap server */
    status = idmap_query_attrs(context, lookup,
        attributes, 0, values, NUM_ATTRIBUTES);
    if (status)
        goto out_free_values;

    /* parse attributes */
    if (FAILED(StringCchCopyA(group->name, VAL_LEN,
            *values[ATTR_GROUP_NAME]))) {
        eprintf("ldap attribute %s='%s' longer than %u characters\n",
            context->config.attributes[ATTR_GROUP_NAME],
            *values[ATTR_GROUP_NAME], VAL_LEN);
        status = ERROR_BUFFER_OVERFLOW;
        goto out_free_values;
    }
    if (!parse_uint(*values[ATTR_GID], &group->gid)) {
        eprintf("failed to parse ldap attribute %s='%s'\n",
            context->config.attributes[ATTR_GID], *values[ATTR_GID]);
        status = ERROR_INVALID_PARAMETER;
        goto out_free_values;
    }
    group->last_updated = time(NULL);

    if (context->config.cache_ttl) {
        /* insert the entry into the cache */
        cache_insert(&context->groups, lookup, &group->entry);
    }
out_free_values:
    for (i = 0; i < NUM_ATTRIBUTES; i++)
        ldap_value_free(values[i]);
out:
    return status;
}
开发者ID:AchillesA,项目名称:ms-nfs41-client,代码行数:52,代码来源:idmap.c

示例13: cache_get

static struct file *
cache_get(const char *path)
{
  struct file *f = NULL;

  pthread_mutex_lock(&cache.lock);
  cache_clean();
  f = g_hash_table_lookup(cache.files, path);
  if(f == NULL)
    f = cache_insert(path);
  pthread_mutex_unlock(&cache.lock);

  return f;
}
开发者ID:JeremyOT,项目名称:stormfs,代码行数:14,代码来源:stormfs.c

示例14: client_recv_cb

/*
 *
 * SOCKS5 UDP Request
 * +----+------+------+----------+----------+----------+
 * |RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
 * +----+------+------+----------+----------+----------+
 * | 2  |  1   |  1   | Variable |    2     | Variable |
 * +----+------+------+----------+----------+----------+
 *
 */
static void
client_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) {
    struct server_context *server = container_of(handle, struct server_context, udp);
    if (nread > 0) {
        uint8_t frag = buf->base[2];
        if (frag) {
            logger_log(LOG_ERR, "don't support udp dgram frag");
            goto err;
        }

        char key[KEY_BYTES + 1] = {0};
        crypto_generickey((uint8_t *)key, sizeof(key) -1, (uint8_t*)addr, sizeof(*addr), NULL, 0);

        struct client_context *client = NULL;
        uv_mutex_lock(&mutex);
        cache_lookup(cache, key, (void *)&client);
        uv_mutex_unlock(&mutex);

        if (client == NULL) {
            client = new_client();
            client->addr = *addr;
            client->local_handle = handle;
            memcpy(client->key, key, sizeof(key));
            uv_timer_init(handle->loop, client->timer);
            uv_udp_init(handle->loop, &client->server_handle);
            client->server_handle.data = client;
            uv_udp_recv_start(&client->server_handle, server_alloc_cb, server_recv_cb);
            uv_mutex_lock(&mutex);
            cache_insert(cache, client->key, (void *)client);
            uv_mutex_unlock(&mutex);
        }

        int clen = nread - 3 + PRIMITIVE_BYTES;
        uint8_t *c = (uint8_t *)buf->base - PRIMITIVE_BYTES;
        int rc = crypto_encrypt(c, (uint8_t*)buf->base + 3, nread - 3);
        if (!rc) {
            reset_timer(client);
            forward_to_server(server->server_addr, client, c, clen);
        }

    } else {
        goto err;
    }

    return;

err:
    free(buf->base - PRIMITIVE_BYTES);
}
开发者ID:nsdown,项目名称:xsocks-1,代码行数:59,代码来源:xsocks_udprelay.c

示例15: check_block_list

int
check_block_list(char *addr, int err_level)
{
    size_t addr_len = strlen(addr);

    if (cache_key_exist(block_list, addr, addr_len)) {
        int *count = NULL;
        cache_lookup(block_list, addr, addr_len, &count);
        if (count != NULL) {
            if (*count > MAX_TRIES)
                return 1;
            (*count) += err_level;
        }
    } else {
        int *count = (int *)ss_malloc(sizeof(int));
        *count = 1;
        cache_insert(block_list, addr, addr_len, count);
    }

    return 0;
}
开发者ID:kdrx,项目名称:shadowsocks-libev,代码行数:21,代码来源:acl.c


注:本文中的cache_insert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。