/* * hash-driver - Run with a big file as stdin to insert each line into the * hash table, then prints the whole hash table, then deletes a random item, * and prints the table again... */ int main(void) { hash_table *hid; int i; LOCAL_ARRAY(char, buf, BUFSIZ); LOCAL_ARRAY(char, todelete, BUFSIZ); hash_link *walker = NULL; todelete[0] = '\0'; printf("init\n"); printf("creating hash table\n"); if ((hid = hash_create((HASHCMP *) strcmp, 229, hash4)) < 0) { printf("hash_create error.\n"); exit(1); } printf("done creating hash table: %d\n", hid); while (fgets(buf, BUFSIZ, stdin)) { buf[strlen(buf) - 1] = '\0'; printf("Inserting '%s' for item %p to hash table: %d\n", buf, buf, hid); hash_insert(hid, xstrdup(buf), (void *) 0x12345678); if (random() % 17 == 0) strcpy(todelete, buf); } printf("walking hash table...\n"); for (i = 0, walker = hash_first(hid); walker; walker = hash_next(hid)) { printf("item %5d: key: '%s' item: %p\n", i++, walker->key, walker->item); } printf("done walking hash table...\n"); if (todelete[0]) { printf("deleting %s from %d\n", todelete, hid); if (hash_delete(hid, todelete)) printf("hash_delete error\n"); } printf("walking hash table...\n"); for (i = 0, walker = hash_first(hid); walker; walker = hash_next(hid)) { printf("item %5d: key: '%s' item: %p\n", i++, walker->key, walker->item); } printf("done walking hash table...\n"); printf("driver finished.\n"); exit(0); }
static void netdbPurgeLRU(void) { netdbEntry *n; netdbEntry **list; int k = 0; int list_count = 0; int removed = 0; list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *)); hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { assert(list_count < memInUse(MEM_NETDBENTRY)); *(list + list_count) = n; list_count++; } qsort((char *) list, list_count, sizeof(netdbEntry *), netdbLRU); for (k = 0; k < list_count; k++) { if (memInUse(MEM_NETDBENTRY) < Config.Netdb.low) break; netdbRelease(*(list + k)); removed++; } xfree(list); }
static void cacheIndexCmp(CacheIndex * idx1, CacheIndex * idx2) { int shared_count = 0; int hashed_count = 0; hash_link *hashr = NULL; CacheIndex *small_idx = idx1; CacheIndex *large_idx = idx2; assert(idx1 && idx2); /* check our guess */ if (idx1->count > idx2->count) { small_idx = idx2; large_idx = idx1; } /* find shared_count */ hash_first(small_idx->hash); for (hashr = hash_next(small_idx->hash)) { hashed_count++; if (hash_lookup(large_idx->hash, hashr->key)) shared_count++; } assert(hashed_count == small_idx->count); cacheIndexCmpReport(idx1, shared_count); cacheIndexCmpReport(idx2, shared_count); }
void authenticateProxyUserCacheCleanup(void *datanotused) { /* * We walk the hash by username as that is the unique key we use. * For big hashs we could consider stepping through the cache, 100/200 * entries at a time. Lets see how it flys first. */ auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; char *username = NULL; debug(29, 3) ("authenticateProxyUserCacheCleanup: Cleaning the user cache now\n"); debug(29, 3) ("authenticateProxyUserCacheCleanup: Current time: %ld\n", (long int) current_time.tv_sec); hash_first(proxy_auth_username_cache); while ((usernamehash = ((auth_user_hash_pointer *) hash_next(proxy_auth_username_cache)))) { auth_user = usernamehash->auth_user; username = authenticateUserUsername(auth_user); /* if we need to have inpedendent expiry clauses, insert a module call * here */ debug(29, 4) ("authenticateProxyUserCacheCleanup: Cache entry:\n\tType: %d\n\tUsername: %s\n\texpires: %ld\n\treferences: %ld\n", auth_user->auth_type, username, (long int) (auth_user->expiretime + Config.authenticateTTL), (long int) auth_user->references); if (auth_user->expiretime + Config.authenticateTTL <= current_time.tv_sec) { debug(29, 5) ("authenticateProxyUserCacheCleanup: Removing user %s from cache due to timeout.\n", username); /* the minus 1 accounts for the cache lock */ if ((authenticateAuthUserInuse(auth_user) - 1)) debug(29, 4) ("authenticateProxyUserCacheCleanup: this cache entry has expired AND has a non-zero ref count.\n"); else authenticateAuthUserUnlock(auth_user); } } debug(29, 3) ("authenticateProxyUserCacheCleanup: Finished cleaning the user cache.\n"); eventAdd("User Cache Maintenance", authenticateProxyUserCacheCleanup, NULL, Config.authenticateGCInterval, 1); }
/* stop PPPoE daemon */ void pppoed_stop(pppoed *_this) { pppoed_listener *plistener; hash_link *hl; pppoe_session *session; if (!pppoed_is_running(_this)) return; _this->state = PPPOED_STATE_STOPPED; if (_this->session_hash != NULL) { for (hl = hash_first(_this->session_hash); hl != NULL; hl = hash_next(_this->session_hash)) { session = (pppoe_session *)hl->item; pppoe_session_disconnect(session); pppoe_session_stop(session); } } for (slist_itr_first(&_this->listener); slist_itr_has_next(&_this->listener);) { plistener = slist_itr_next(&_this->listener); pppoed_listener_stop(plistener); free(plistener); slist_itr_remove(&_this->listener); } PPPOED_DBG((_this, LOG_DEBUG, "Stopped")); }
void *fm_allocate (enum palloc_flags flags, bool lock) { lock_acquire(&frame_table_lock); void *kaddr = palloc_get_page(PAL_USER | flags); struct frame *fm; if (kaddr == NULL){ fm = select_fm(); fm->isPinned = true; fm->locked = lock; kaddr = fm->k_addr; struct hash *ht_thread_uaddr = &fm->ht_thread_uaddr; hash_first(&fm->iter_htu, ht_thread_uaddr); struct thread_uaddr *thread_uaddr; while (hash_next(&fm->iter_htu)){ thread_uaddr = hash_entry(hash_cur(&fm->iter_htu), struct thread_uaddr, elem); struct page* p = find_page(thread_uaddr->uaddr, thread_uaddr->t); p->isLoaded = false; pagedir_clear_page(thread_uaddr->t->pagedir, p->vaddr); if (p->type == STACK){ page_to_swap(p); } else if (p->type == SEGMENT){ if (p->writable && (if_fm_dirty(fm) || p->isDirty)){ p->isDirty = true; page_to_swap(p); } } else { write_mmap_page_to_file(p); } } hash_clear(&fm->ht_thread_uaddr, remove_thread_uaddr); } else {
static void authenticateDigestNonceCacheCleanup(void *data) { /* * We walk the hash by nonceb64 as that is the unique key we * use. For big hash tables we could consider stepping through * the cache, 100/200 entries at a time. Lets see how it flies * first. */ digest_nonce_h *nonce; debug(29, 3) ("authenticateDigestNonceCacheCleanup: Cleaning the nonce cache now\n"); debug(29, 3) ("authenticateDigestNonceCacheCleanup: Current time: %ld\n", (long int) current_time.tv_sec); hash_first(digest_nonce_cache); while ((nonce = ((digest_nonce_h *) hash_next(digest_nonce_cache)))) { debug(29, 3) ("authenticateDigestNonceCacheCleanup: nonce entry : %p '%s'\n", nonce, (char *) nonce->hash.key); debug(29, 4) ("authenticateDigestNonceCacheCleanup: Creation time: %ld\n", (long int) nonce->noncedata.creationtime); if (authDigestNonceIsStale(nonce)) { debug(29, 4) ("authenticateDigestNonceCacheCleanup: Removing nonce %s from cache due to timeout.\n", (char *) nonce->hash.key); assert(nonce->flags.incache); /* invalidate nonce so future requests fail */ nonce->flags.valid = 0; /* if it is tied to a auth_user, remove the tie */ authDigestNonceUserUnlink(nonce); authDigestNoncePurge(nonce); } } debug(29, 3) ("authenticateDigestNonceCacheCleanup: Finished cleaning the nonce cache.\n"); if (authenticateDigestActive()) eventAdd("Digest none cache maintenance", authenticateDigestNonceCacheCleanup, NULL, digestConfig->nonceGCInterval, 1); }
void netdbBinaryExchange(StoreEntry * s) { http_reply *reply = s->mem_obj->reply; #if USE_ICMP netdbEntry *n; int i; int j; int rec_sz; char *buf; struct in_addr addr; storeBuffer(s); httpReplyReset(reply); httpReplySetHeaders(reply, HTTP_OK, "OK", NULL, -1, squid_curtime, -1); httpReplySwapOut(reply, s); rec_sz = 0; rec_sz += 1 + sizeof(addr.s_addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); buf = memAllocate(MEM_4K_BUF); i = 0; hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { if (0.0 == n->rtt) continue; if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */ continue; if (!safe_inet_addr(n->network, &addr)) continue; buf[i++] = (char) NETDB_EX_NETWORK; xmemcpy(&buf[i], &addr.s_addr, sizeof(addr.s_addr)); i += sizeof(addr.s_addr); buf[i++] = (char) NETDB_EX_RTT; j = htonl((int) (n->rtt * 1000)); xmemcpy(&buf[i], &j, sizeof(int)); i += sizeof(int); buf[i++] = (char) NETDB_EX_HOPS; j = htonl((int) (n->hops * 1000)); xmemcpy(&buf[i], &j, sizeof(int)); i += sizeof(int); if (i + rec_sz > 4096) { storeAppend(s, buf, i); i = 0; } } if (i > 0) { storeAppend(s, buf, i); i = 0; } assert(0 == i); storeBufferFlush(s); memFree(buf, MEM_4K_BUF); #else httpReplyReset(reply); httpReplySetHeaders(reply, HTTP_BAD_REQUEST, "Bad Request", NULL, -1, -1, -1); httpReplySwapOut(reply, s); storeAppendPrintf(s, "NETDB support not compiled into this Squid cache.\n"); #endif storeComplete(s); }
int main(void) { hash_t *hash = hash_make(); char *key = NULL; int n = 100,*val; unsigned int count; hash_index_t *hi; unsigned int sum = 0; int i; for(i = 0;i<100000;++i) { key = malloc(sizeof(char) * 256); memset(key,0,256); val = malloc(sizeof(int)); *val = i; sprintf(key,"char%10d",i); hash_set(hash,key,HASH_KEY_STRING,val); void *entry_key; val = hash_get(hash,key,HASH_KEY_STRING,&entry_key); if(entry_key) { printf("key:%s\n",(char*)entry_key); } // if(val) // printf("val:%d\n",*val); } for (hi = hash_first(hash); hi ; hi = hash_next(hi)){ hash_this(hi,(const void **)&key,NULL,(void **)&val); hash_set(hash,key,HASH_KEY_STRING,NULL); printf("val:%d\n",*(int *)val); sum += *(int *)val; free(key); free(val); } printf("sum:%d\n",sum); count = hash_count(hash); printf("count:%u\n",count); hash_clear(hash); count = hash_count(hash); printf("count after clear:%u\n",count); hash_destroy(hash); return 0; }
/* * this function will be called when {@link ::_l2tp_ctrl control} * is terminated. */ void l2tpd_ctrl_finished_notify(l2tpd *_this) { if (_this->state != L2TPD_STATE_SHUTTING_DOWN) return; if (hash_first(_this->ctrl_map) != NULL) return; l2tpd_stop_immediatly(_this); }
void dump_hosts() { HostData *it; unsigned i; const void *key; for (it = hash_first(hosttable, &i, &key); it; it = hash_next(hosttable, &i, &key)) { print_host(it); } }
void clientdbDump(StoreEntry * sentry) { ClientInfo *c; log_type l; int icp_total = 0; int icp_hits = 0; int http_total = 0; int http_hits = 0; storeAppendPrintf(sentry, "Cache Clients:\n"); hash_first(client_table); while ((c = (ClientInfo *) hash_next(client_table))) { storeAppendPrintf(sentry, "Address: %s\n", hashKeyStr(&c->hash)); storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(c->addr)); storeAppendPrintf(sentry, "Currently established connections: %d\n", c->n_established); storeAppendPrintf(sentry, " ICP Requests %d\n", c->Icp.n_requests); for (l = LOG_TAG_NONE; l < LOG_TYPE_MAX; l++) { if (c->Icp.result_hist[l] == 0) continue; icp_total += c->Icp.result_hist[l]; if (LOG_UDP_HIT == l) icp_hits += c->Icp.result_hist[l]; storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n", log_tags[l], c->Icp.result_hist[l], percent(c->Icp.result_hist[l], c->Icp.n_requests)); } storeAppendPrintf(sentry, " HTTP Requests %d\n", c->Http.n_requests); for (l = LOG_TAG_NONE; l < LOG_TYPE_MAX; l++) { if (c->Http.result_hist[l] == 0) continue; http_total += c->Http.result_hist[l]; if (isTcpHit(l)) http_hits += c->Http.result_hist[l]; storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n", log_tags[l], c->Http.result_hist[l], percent(c->Http.result_hist[l], c->Http.n_requests)); } storeAppendPrintf(sentry, "\n"); } storeAppendPrintf(sentry, "TOTALS\n"); storeAppendPrintf(sentry, "ICP : %d Queries, %d Hits (%3d%%)\n", icp_total, icp_hits, percent(icp_hits, icp_total)); storeAppendPrintf(sentry, "HTTP: %d Requests, %d Hits (%3d%%)\n", http_total, http_hits, percent(http_hits, http_total)); }
static void ptrDump(StoreEntry * sentry) { hash_link *hptr; ptr *c; storeAppendPrintf(sentry, "Tracking %d pointers\n", leakCount); hash_first(htable); while ((hptr = hash_next(htable))) { c = (ptr *) hptr; storeAppendPrintf(sentry, "%20p last used %9d seconds ago by %s:%d\n", c->key, squid_curtime - c->when, c->file, c->line); } }
/* re-digests currently hashed entries */ static void cacheResetDigest(Cache * cache) { CacheEntry *e = NULL; hash_table *hash; struct timeval t_start, t_end; assert(cache); fprintf(stderr, "%s: init-ing digest with %d entries\n", cache->name, cache->count); if (cache->digest) cacheDigestDestroy(cache->digest); hash = cache->hash; cache->digest = cacheDigestCreate(cache->count + 1, 6); if (!cache->count) return; gettimeofday(&t_start, NULL); hash_first(hash); while (e = hash_next(hash)) { cacheDigestAdd(cache->digest, e->key); } gettimeofday(&t_end, NULL); assert(cache->digest->count == cache->count); fprintf(stderr, "%s: init-ed digest with %d entries\n", cache->name, cache->digest->count); fprintf(stderr, "%s: init took: %f sec, %f sec/M\n", cache->name, tvSubDsec(t_start, t_end), (double) 1e6 * tvSubDsec(t_start, t_end) / cache->count); /* check how long it takes to traverse the hash */ gettimeofday(&t_start, NULL); for (e = hash_first(hash); e; e = hash_next(hash)) { } gettimeofday(&t_end, NULL); fprintf(stderr, "%s: hash scan took: %f sec, %f sec/M\n", cache->name, tvSubDsec(t_start, t_end), (double) 1e6 * tvSubDsec(t_start, t_end) / cache->count); }
void netdbDump(StoreEntry * sentry) { netdbEntry *n; netdbEntry **list; net_db_name *x; int k; int i; int j; net_db_peer *p; storeAppendPrintf(sentry, "Network DB Statistics:\n"); storeAppendPrintf(sentry, "%-16.16s %9s %7s %5s %s\n", "Network", "recv/sent", "RTT", "Hops", "Hostnames"); list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *)); i = 0; hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) *(list + i++) = n; if (i != memInUse(MEM_NETDBENTRY)) debug(38, 0) ("WARNING: netdb_addrs count off, found %d, expected %d\n", i, memInUse(MEM_NETDBENTRY)); qsort((char *) list, i, sizeof(netdbEntry *), sortByRtt); for (k = 0; k < i; k++) { n = *(list + k); storeAppendPrintf(sentry, "%-16.16s %4d/%4d %7.1f %5.1f", n->network, n->pings_recv, n->pings_sent, n->rtt, n->hops); for (x = n->hosts; x; x = x->next) storeAppendPrintf(sentry, " %s", hashKeyStr(&x->hash)); storeAppendPrintf(sentry, "\n"); p = n->peers; for (j = 0; j < n->n_peers; j++, p++) { storeAppendPrintf(sentry, " %-22.22s %7.1f %5.1f\n", p->peername, p->rtt, p->hops); } } xfree(list); }
static void netdbSaveState(void *foo) { Logfile *lf; netdbEntry *n; net_db_name *x; struct timeval start = current_time; int count = 0; if (strcmp(Config.netdbFilename, "none") == 0) return; /* * This was nicer when we were using stdio, but thanks to * Solaris bugs, its a bad idea. fopen can fail if more than * 256 FDs are open. */ /* * unlink() is here because there is currently no way to make * logfileOpen() use O_TRUNC. */ unlink(Config.netdbFilename); lf = logfileOpen(Config.netdbFilename, 4096, 0); if (NULL == lf) { debug(50, 1) ("netdbSaveState: %s: %s\n", Config.netdbFilename, xstrerror()); return; } hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { if (n->pings_recv == 0) continue; logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d", n->network, n->pings_sent, n->pings_recv, n->hops, n->rtt, (int) n->next_ping_time, (int) n->last_use_time); for (x = n->hosts; x; x = x->next) logfilePrintf(lf, " %s", hashKeyStr(&x->hash)); logfilePrintf(lf, "\n"); count++; #undef RBUF_SZ } logfileClose(lf); getCurrentTime(); debug(38, 1) ("NETDB state saved; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1); }
struct in_addr * client_entry(struct in_addr *current) { ClientInfo *c = NULL; const char *key; if (current) { key = xinet_ntoa(*current); hash_first(client_table); while ((c = (ClientInfo *) hash_next(client_table))) { if (!strcmp(key, hashKeyStr(&c->hash))) break; } c = (ClientInfo *) hash_next(client_table); } else { hash_first(client_table); c = (ClientInfo *) hash_next(client_table); } hash_last(client_table); if (c) return (&c->addr); else return (NULL); }
static void l2tpd_stop_timeout(int fd, short evtype, void *ctx) { hash_link *hl; l2tp_ctrl *ctrl; l2tpd *_this; _this = ctx; l2tpd_log(_this, LOG_INFO, "Shutdown timeout"); for (hl = hash_first(_this->ctrl_map); hl != NULL; hl = hash_next(_this->ctrl_map)) { ctrl = hl->item; l2tp_ctrl_stop(ctrl, 0); } l2tpd_stop_immediatly(_this); }
void authenticateUserCacheRestart(void) { auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; char *username = NULL; debug(29, 3) ("authenticateUserCacheRestart: Clearing config dependent cache data.\n"); hash_first(proxy_auth_username_cache); while ((usernamehash = ((auth_user_hash_pointer *) hash_next(proxy_auth_username_cache)))) { auth_user = usernamehash->auth_user; username = authenticateUserUsername(auth_user); debug(29, 5) ("authenticateUserCacheRestat: Clearing cache ACL results for user: %s\n", username); aclCacheMatchFlush(&auth_user->proxy_match_cache); } }
static void cacheIndexDestroy(CacheIndex * idx) { hash_link *hashr = NULL; if (idx) { /* destroy hash list contents */ hash_first(idx->hash); while (hashr = hash_next(idx->hash)) { hash_remove_link(idx->hash, hashr); cacheEntryDestroy((CacheEntry *) hashr); } /* destroy the hash table itself */ hashFreeMemory(idx->hash); xfree(idx); } }
void hashFreeItems(hash_table * hid, HASHFREE * free_func) { hash_link *l; hash_link **list; int i = 0; int j; list = xcalloc(hid->count, sizeof(hash_link *)); hash_first(hid); while ((l = hash_next(hid)) && i < hid->count) { *(list + i) = l; i++; } for (j = 0; j < i; j++) free_func(*(list + j)); xfree(list); }
void host_table_finalize( ) { assert(hosttable); HostData *it; unsigned i; const void *key; tmq_destroy(timeout_queue); timeout_queue = NULL; for (it = hash_first(hosttable, &i, &key); it; it = hash_next(hosttable, &i, &key)) host_remove((HostKey*)key); hash_destroy(hosttable); }
static void cacheDestroy(Cache * cache) { CacheEntry *e = NULL; hash_table *hash; assert(cache); hash = cache->hash; /* destroy hash table contents */ hash_first(hash); while (e = hash_next(hash)) { hash_remove_link(hash, (hash_link *) e); cacheEntryDestroy(e); } /* destroy the hash table itself */ hashFreeMemory(hash); if (cache->digest) cacheDigestDestroy(cache->digest); xfree(cache); }
/* Randomly sellects a page to evict. */ struct frame *get_frame_for_eviction() { struct hash_iterator hi; struct hash_elem e; ASSERT(lock_held_by_current_thread(&ft_lock)); // lock_acquire(&ft_lock); do { long index = random_ulong() % hash_size(&frame_table); hash_first(&hi, &frame_table); for(int i = 0; i < index; i++) hash_next(&hi); } while(!lock_try_acquire(&get_frame(hash_cur(&hi))->evicting)); struct frame *f = get_frame(hash_cur(&hi)); ASSERT(!f->page->deleting); // lock_release(&ft_lock); return f; }
static void authDigestUserShutdown(void) { /* * Future work: the auth framework could flush it's cache */ auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; hash_first(proxy_auth_username_cache); while ((usernamehash = ((auth_user_hash_pointer *) hash_next(proxy_auth_username_cache)))) { auth_user = usernamehash->auth_user; if (authscheme_list[auth_user->auth_module - 1].typestr && strcmp(authscheme_list[auth_user->auth_module - 1].typestr, "digest") == 0) /* it's digest */ authenticateAuthUserUnlock(auth_user); } if (digest_user_pool) { assert(memPoolInUseCount(digest_user_pool) == 0); memPoolDestroy(digest_user_pool); digest_user_pool = NULL; } }
static void authenticateDigestNonceShutdown(void) { /* * We empty the cache of any nonces left in there. */ digest_nonce_h *nonce; if (digest_nonce_cache) { debug(29, 2) ("authenticateDigestNonceShutdown: Shutting down nonce cache \n"); hash_first(digest_nonce_cache); while ((nonce = ((digest_nonce_h *) hash_next(digest_nonce_cache)))) { assert(nonce->flags.incache); authDigestNoncePurge(nonce); } } if (digest_nonce_pool) { assert(memPoolInUseCount(digest_nonce_pool) == 0); memPoolDestroy(digest_nonce_pool); digest_nonce_pool = NULL; } debug(29, 2) ("authenticateDigestNonceShutdown: Nonce cache shutdown\n"); }
/* Destroy Frag Table * * Will destroy the entire tree, and destory each of the fragment lists + * fragments in the tree. * * @return -1 on failure * 0 on success */ int frag_table_finalize() { struct frag_list *it; unsigned i; const void *key; if(!fragtable) return -1; #ifdef ENABLE_PTHREADS tmq_stop(timeout_queue); #endif tmq_destroy(timeout_queue); for(it = hash_first(fragtable, &i, &key); it; it = hash_next(fragtable, &i, &key)) frag_table_remove((struct frag_key *) key, it); hash_destroy(fragtable); return 0; }
static void cbdataDump(StoreEntry * sentry) { hash_link *hptr; cbdata *c; storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount); hash_first(htable); while ((hptr = hash_next(htable))) { c = (cbdata *) hptr; #if CBDATA_DEBUG storeAppendPrintf(sentry, "%20p %10s %d locks %s:%d\n", c->key, c->valid ? "VALID" : "NOT VALID", c->locks, c->file, c->line); #else storeAppendPrintf(sentry, "%20p %10s %d locks\n", c->key, c->valid ? "VALID" : "NOT VALID", c->locks); #endif } }
struct frame *select_fm (void) { void *end = clock_point_max; if (clock_point != clock_point_init) end = clock_point - PGSIZE; struct frame *fm; for (;clock_point != end; clock_point += PGSIZE){ if (clock_point >= clock_point_max) clock_point = clock_point_init; fm = find_fm(clock_point); if (!fm){ continue; } else if (fm->locked || fm->isPinned){ if (if_fm_accessed(fm)){ hash_apply(&fm->ht_thread_uaddr, set_page_unaccessed); } continue; } else { if (if_fm_accessed(fm)){ hash_apply(&fm->ht_thread_uaddr, set_page_unaccessed); } else { return fm; } } } fm = NULL; while(!fm){ hash_first(&fmt_iter, &frames_table); while(hash_next(&fmt_iter)){ fm = hash_entry(hash_cur(&fmt_iter), struct frame, elem); if (!fm->locked && !fm->isPinned){ return fm; } } cond_wait(&frame_table_cond, &frame_table_lock); } }
/* stop L2TP daemon */ void l2tpd_stop(l2tpd *_this) { int nctrls = 0; hash_link *hl; l2tp_ctrl *ctrl; nctrls = 0; event_del(&_this->ev_timeout); if (l2tpd_is_stopped(_this)) return; if (l2tpd_is_shutting_down(_this)) { /* terminate immediately, when 2nd call */ l2tpd_stop_immediatly(_this); return; } for (hl = hash_first(_this->ctrl_map); hl != NULL; hl = hash_next(_this->ctrl_map)) { ctrl = hl->item; l2tp_ctrl_stop(ctrl, L2TP_STOP_CCN_RCODE_SHUTTING_DOWN); nctrls++; } _this->state = L2TPD_STATE_SHUTTING_DOWN; if (nctrls > 0) { struct timeval tv0; tv0.tv_usec = 0; tv0.tv_sec = L2TPD_SHUTDOWN_TIMEOUT; evtimer_set(&_this->ev_timeout, l2tpd_stop_timeout, _this); evtimer_add(&_this->ev_timeout, &tv0); return; } l2tpd_stop_immediatly(_this); }