예제 #1
0
파일: frame.c 프로젝트: chutchUCD/OS
/**
 * An (internal, private) method --
 * Deallocates a frame or page (internal procedure)
 * MUST BE CALLED with 'frame_lock' held.
 */
void
vm_frame_do_free (void *kpage, bool free_page)
{
  ASSERT (lock_held_by_current_thread(&frame_lock) == true);
  ASSERT (is_kernel_vaddr(kpage));
  ASSERT (pg_ofs (kpage) == 0); // should be aligned

  // hash lookup : a temporary entry
  struct frame_table_entry f_tmp;
  f_tmp.kpage = kpage;

  struct hash_elem *h = hash_find (&frame_map, &(f_tmp.helem));
  if (h == NULL) {
    PANIC ("The page to be freed is not stored in the table");
  }

  struct frame_table_entry *f;
  f = hash_entry(h, struct frame_table_entry, helem);

  hash_delete (&frame_map, &f->helem);
  list_remove (&f->lelem);

  // Free resources
  if(free_page) palloc_free_page(kpage);
  free(f);
}
예제 #2
0
파일: mminode.c 프로젝트: Dennisbonke/DB-OS
void fs_inode_pcache_invalidate(struct inode *node, size_t offset, size_t length)
{
	if(!(node->flags & INODE_PCACHE))
		return;
	mutex_acquire(&node->mappings_lock);
	offset = offset & PAGE_MASK;
	int page_number = offset / PAGE_SIZE;
	int npages = ((length-1) / PAGE_SIZE) + 1;
	for(int i = page_number; i < (page_number + npages); i++)
	{
		struct physical_page *entry;
		if((entry = hash_lookup(&node->physicals, &i, sizeof(i))) != NULL) {
			mutex_acquire(&entry->lock);
			if(entry->count == 0) {
				if(entry->page) {
					mm_physical_decrement_count(entry->page);
				}
				entry->page = 0;
				hash_delete(&node->physicals, &i, sizeof(i));
				mutex_destroy(&entry->lock);
				kfree(entry);
				atomic_fetch_sub(&node->mapped_entries_count, 1);
			} else {
				mutex_release(&entry->lock);
			}
		}
	}
	mutex_release(&node->mappings_lock);
}
예제 #3
0
static void
sbus_signal_name_owner_changed(struct sbus_incoming_signal *a_signal,
                               void *handler_data)
{
    hash_table_t *table = a_signal->conn->clients;
    hash_key_t *keys;
    unsigned long count;
    unsigned long i;
    int hret;

    DEBUG(SSSDBG_TRACE_FUNC, "Clearing UIDs cache\n");

    hret = hash_keys(table, &count, &keys);
    if (hret != HASH_SUCCESS) {
        DEBUG(SSSDBG_OP_FAILURE, "Unable to get hash keys\n");
        return;
    }

    for (i = 0; i < count; i++) {
        hret = hash_delete(table, &keys[i]);
        if (hret != HASH_SUCCESS) {
            DEBUG(SSSDBG_MINOR_FAILURE, "Could not delete key from hash\n");
            return;
        }
    }

    return;
}
예제 #4
0
void
js_vm_object_delete_property (JSVirtualMachine *vm, JSObject *obj,
			      JSSymbol prop)
{
  unsigned int ui;

  /* Check if we already know this property. */
  for (ui = 0; ui < obj->num_props; ui++)
    if (obj->props[ui].name == prop)
      {
	/* Found, remove it from our list of properties. */
	obj->props[ui].name = JS_SYMBOL_NULL;
	obj->props[ui].value.type = JS_UNDEFINED;

	/* Remove its name from the hash (if present). */
	if (obj->hash)
	  {
	    const char *name = js_vm_symname (vm, prop);
	    hash_delete (vm, obj, name, strlen (name));
	  }

	/* All done here. */
	return;
      }
}
예제 #5
0
static void bce_delete(struct bcentry *bce, int flush)
{
    pthread_rwlock_wrlock(&bce->lock);
    if (bce->type != BCE_DAD) {
        del_task(&bce->tqe);
        if (bce->type != BCE_NONCE_BLOCK)
            xfrm_del_bce(&bce->our_addr, &bce->peer_addr);
    }
    if (bce->cleanup)
        bce->cleanup(bce);
    if (!flush &&
            (bce->type == BCE_CACHED || bce->type == BCE_CACHE_DYING)) {
        struct timespec minlft;
        if (!rr_cn_nonce_lft(bce->nonce_hoa, &minlft)) {
            bce->type = BCE_NONCE_BLOCK;
            add_task_abs(&minlft, &bce->tqe, _expire);
            pthread_rwlock_unlock(&bce->lock);
            return;
        }
    }
    bcache_count--;
    hash_delete(&bc_hash, &bce->our_addr, &bce->peer_addr);
    pthread_rwlock_unlock(&bce->lock);
    bcache_free(bce);
}
int main()
{
	int k = 0;
	int array[] = {4371, 1323, 6173, 4199, 4344, 9679, 1989};
	hash_table_ptr tbl = hash_init_table(SIZE, hashfunc, cmp_int);
	for (; k < 7; k++) {
		hash_insert(tbl, array[k]);
	}
	position p = hash_find(tbl, 6173);
	position q = hash_find(tbl, 1323);
	assert(p != -1);
	assert(p != q);
	assert(tbl->cells[p].element == 6173);
	hash_delete(tbl, 6173);
	p = hash_find(tbl, 6173);
	assert(p == -1);
	for (k = 0; k < SIZE; k++) {
		if (tbl->cells[k].info == legitimate) {
			printf("%d ", tbl->cells[k].element);
		}
	}
	puts("\n");
	hash_destroy_table(&tbl);
	assert(tbl == NULL);
	return 0;
}
int update_server_record_in_cache(FOREIGN_SERVER *existing,
                                  FOREIGN_SERVER *altered)
{
  int error= 0;
  DBUG_ENTER("update_server_record_in_cache");

  /*
    update the members that haven't been change in the altered server struct
    with the values of the existing server struct
  */
  merge_server_struct(existing, altered);

  /*
    delete the existing server struct from the server cache
  */
  VOID(hash_delete(&servers_cache, (uchar*)existing));

  /*
    Insert the altered server struct into the server cache
  */
  if (my_hash_insert(&servers_cache, (uchar*)altered))
  {
    DBUG_PRINT("info", ("had a problem inserting server %s at %lx",
                        altered->server_name, (long unsigned int) altered));
    error= ER_OUT_OF_RESOURCES;
  }

  DBUG_RETURN(error);
}
예제 #8
0
errno_t
autofs_orphan_maps(struct autofs_ctx *actx)
{
    int hret;
    unsigned long mcount;
    unsigned long i;
    hash_key_t *maps;

    if (!actx || !actx->maps) {
        return EINVAL;
    }

    hret = hash_keys(actx->maps, &mcount, &maps);
    if (hret != HASH_SUCCESS) {
        return EIO;
    }

    for (i = 0; i < mcount; i++) {
        hret = hash_delete(actx->maps, &maps[i]);
        if (hret != HASH_SUCCESS) {
            DEBUG(SSSDBG_MINOR_FAILURE, "Could not delete key from hash\n");
            continue;
        }
    }

    return EOK;
}
예제 #9
0
파일: pppoed.c 프로젝트: marctmiller/bitrig
/* it called when the PPPoE session was closed */
void
pppoed_pppoe_session_close_notify(pppoed *_this, pppoe_session *session)
{
	slist_add(&_this->session_free_list,
	    (void *)(intptr_t)session->session_id);

	if (_this->acookie_hash != NULL)
		hash_delete(_this->acookie_hash,
		    (void *)(intptr_t)session->acookie, 0);
	if (_this->session_hash != NULL)
		hash_delete(_this->session_hash,
		    (void *)(intptr_t)session->session_id, 0);

	pppoe_session_fini(session);
	free(session);
}
예제 #10
0
파일: test_hash.c 프로젝트: etosha/fslib
static void test_hash_delete_1() {
    char token[64];

    struct _hash * hash = hash_create(
                        fnv32,
                        str_cmp,
                        sizeof(token),
                        sizeof(int),
                        100);
    int i;

    for (i=0; i < 100; i++) {
        sprintf(token, "%d", i);
        hash_add(hash, token, &i);
    }

    assert ( hash->n_items == 100 );

    for (i=0; i < 100; i++) {
        sprintf(token, "%d", i);
        hash_delete(hash, token, &i);
    }

    assert ( hash->n_items == 0 );

    for (i=0; i < 100; i++) {
        sprintf(token, "%d", i);
        assert ( hash_get(hash, token, &i) == NULL);
    }
   
    hash_remove(hash);
}
예제 #11
0
void
autofs_release_fh(autofs_fh_t *fh)
{
  if (fh) {
    hash_delete(fh->fd);
    /*
     * if a mount succeeded, the kernel fd was closed on
     * the amd side, so it might have been reused.
     * we set it to -1 after closing it, to avoid the problem.
     */
    if (fh->kernelfd >= 0)
      close(fh->kernelfd);

    if (fh->ioctlfd >= 0) {
      /*
       * Tell the kernel we're catatonic
       */
      ioctl(fh->ioctlfd, AUTOFS_IOC_CATATONIC, 0);
      close(fh->ioctlfd);
    }

    if (fh->fd >= 0)
      close(fh->fd);

    XFREE(fh);
  }
}
예제 #12
0
파일: hash.c 프로젝트: alphaKAI/kaios
int main(int argc, char* argv[])
{
    HashTable *ht;
    char      *val;

    ht = hash_init_table();

    hash_put(ht, "apple", "red");
    hash_put(ht, "lemon", "yellow");
    hash_put(ht, "orange", "orange");
    
    print_table(ht);

    hash_put(ht, "orange", "green");

    print_table(ht);

    hash_delete(ht, "orange");

    print_table(ht);

    val = hash_get(ht, "apple");
    val = hash_get(ht, "lemon");
    val = hash_get(ht, "orange");

    hash_uninit_table(ht);
    return 0;
}
예제 #13
0
/* resize the hash, returns the pointer to the new hash or NULL on
 * error. removes the old hash on success. */
struct hashtable_t *hash_resize(struct hashtable_t *hash, int size)
{
	struct hashtable_t *new_hash;
	struct element_t *bucket;
	int i;

	/* initialize a new hash with the new size */
	new_hash = hash_new(size, hash->compare, hash->choose);

	if (new_hash == NULL)
		return NULL;

	/* copy the elements */
	for (i = 0; i < hash->size; i++) {
		bucket = hash->table[i];

		while (bucket != NULL) {
			hash_add(new_hash, bucket->data);
			bucket = bucket->next;
		}
	}

	/* remove hash and eventual overflow buckets but not the content
	 * itself. */
	hash_delete(hash, NULL);

	return new_hash;
}
예제 #14
0
void history_rotate() {
    hash_node_type* n = NULL;
    history_pos = (history_pos + 1) % HISTORY_LENGTH;
    hash_next_item(history, &n);
    while(n != NULL) {
        hash_node_type* next = n;
        history_type* d = (history_type*)n->rec;
        hash_next_item(history, &next);

        if(d->last_write == history_pos) {
            addr_pair key = *(addr_pair*)(n->key);
            hash_delete(history, &key);
            free(d);
        }
        else {
            d->recv[history_pos] = 0;
            d->sent[history_pos] = 0;
        }
        n = next; 
    }

    history_totals.sent[history_pos] = 0;
    history_totals.recv[history_pos] = 0;

    if(history_len < HISTORY_LENGTH) {
        history_len++;
    }
}
예제 #15
0
int
run_delete_event (const char *cmd, size_t argc, char *argv[])
{
  if (argc != 1) {
    fprintf (stderr,
             _("use 'delete-event <name>' to delete an event handler\n"));
    return -1;
  }

  const struct entry key = { .name = argv[0] };
  struct entry *entry, *p;

  entry = hash_delete (event_handlers, &key);
  if (!entry) {
    fprintf (stderr, _("delete-event: %s: no such event handler\n"), argv[0]);
    return -1;
  }

  /* Delete them from the handle. */
  p = entry;
  while (p) {
    guestfs_delete_event_callback (g, p->eh);
    p = p->next;
  }

  /* Free the structures. */
  entry_free (entry);

  return 0;
}
예제 #16
0
파일: main.c 프로젝트: JamesLinus/vsta
/*
 * dead_client()
 *	Someone has gone away.  Free their info.
 */
static void
dead_client(struct msg *m, struct file *f)
{
	(void)hash_delete(filehash, m->m_sender);
	tmpfs_close(f);
	free(f);
}
예제 #17
0
void
js_vm_object_delete_array (JSVirtualMachine *vm, JSObject *obj, JSNode *sel)
{
  if (sel->type == JS_INTEGER)
    {
      if (0 <= sel->u.vinteger && sel->u.vinteger < obj->num_props)
	{
	  JSSymbol sym;

	  sym = obj->props[sel->u.vinteger].name;
	  obj->props[sel->u.vinteger].name = JS_SYMBOL_NULL;
	  obj->props[sel->u.vinteger].value.type = JS_UNDEFINED;

	  /* Remove its name from the hash (if present and it is not NULL). */
	  if (sym != JS_SYMBOL_NULL && obj->hash)
	    {
	      const char *name = js_vm_symname (vm, sym);
	      hash_delete (vm, obj, name, strlen (name));
	    }
	}
    }
  else if (sel->type == JS_STRING)
    {
      int pos;

      if (obj->hash == NULL)
	hash_create (vm, obj);

      pos = hash_lookup (obj, (char *) sel->u.vstring->data,
			 sel->u.vstring->len);
      if (pos >= 0)
	{
	  /* Found it. */
	  obj->props[pos].name = JS_SYMBOL_NULL;
	  obj->props[pos].value.type = JS_UNDEFINED;

	  /* And, delete its name from the hash. */
	  hash_delete (vm, obj, (char *) sel->u.vstring->data,
		       sel->u.vstring->len);
	}
    }
  else
    {
      sprintf (vm->error, "delete_array: illegal array index");
      js_vm_error (vm);
    }
}
예제 #18
0
void hna_global_free(struct bat_priv *bat_priv)
{
	if (!bat_priv->hna_global_hash)
		return;

	hash_delete(bat_priv->hna_global_hash, hna_global_del, NULL);
	bat_priv->hna_global_hash = NULL;
}
예제 #19
0
파일: testhash.c 프로젝트: ChowZenki/lua-db
int
main() {
	struct hash * h = hash_new();
	test(h);
	search(h);
	hash_delete(h);
	return 0;
}
예제 #20
0
void
pptpd_release_call(pptpd *_this, pptp_call *call)
{
	if (call->id != 0)
		slist_add(&_this->call_free_list, (void *)call->id);
	hash_delete(_this->call_id_map, CALL_MAP_KEY(call), 0);
	call->id = 0;
}
void hna_global_free(void)
{
	if (!hna_global_hash)
		return;

	hash_delete(hna_global_hash, hna_global_del);
	hna_global_hash = NULL;
}
예제 #22
0
END_TEST

START_TEST(test_hash_delete_2)
{
    hash_t hash = {0};
    hash_init(&hash, 10);
    ck_assert_int_eq(hash_delete(&hash, "foo"), 0);
}
예제 #23
0
파일: test.cpp 프로젝트: Ingwar/amuse
int main(int argc, const char* argv[])
{
    struct simple_hash ht;
    init_hash(&ht,128);
    for (;;)
    {
        char buf[256];
        if (fgets(buf, 256, stdin) == NULL)
            break;
        char *command = strtok(buf, whitespace);
        unsigned int key;
        unsigned int value;
        if (strcmp(command, "insert") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            sscanf(strtok(NULL, whitespace), "%u", &value);
            hash_insert(&ht,key,value);
        }
        else if (strcmp(command, "lookup") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            size_t value;
            int result;
            result=hash_lookup(&ht,key, &value);
            if (result==0)
                printf("%u\n", (unsigned int) value);
            else
                printf("None\n");
        }
        else if (strcmp(command, "increment") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            hash_cell_insert(&ht,key)->value++;
        }
        else if (strcmp(command, "delete") == 0)
        {
            sscanf(strtok(NULL, whitespace), "%u", &key);
            hash_delete(&ht,key);
        }
        else if (strcmp(command, "clear") == 0)
        {
            clear_hash(&ht);
        }
        else if (strcmp(command, "compact") == 0)
        {
            compact_hash(&ht);
        }
        fflush(stdout);
    }

    // Dump entire table
    printf("{\n");
    if(ht.m_zeroUsed) printf("    %u: %u,\n", ht.m_zeroCell.key, ht.m_zeroCell.value);
    for(size_t i=0;i<ht.m_arraySize;i++) if(ht.m_cells[i].key) printf("    %u: %u,\n", ht.m_cells[i].key, ht.m_cells[i].value);
    printf("}\n");
    end_hash(&ht);
    return 0;
}
예제 #24
0
파일: tasks.c 프로젝트: eqmcc/zeppoo
void viewTasksMemory(void){
	pTable *tasksmemory;
	tasksmemory = hash_new((void *)free_task);

	getTasksMemory(tasksmemory);
	simpleViewTasks(tasksmemory);	
	
	hash_delete(tasksmemory);
}
void hna_local_free(void)
{
	if (!hna_local_hash)
		return;

	cancel_delayed_work_sync(&hna_local_purge_wq);
	hash_delete(hna_local_hash, _hna_local_del);
	hna_local_hash = NULL;
}
예제 #26
0
/* Remove directory entry for the given CANAME */
void
remove_directory (const char *caname)
{
  struct directory *dir = make_directory (caname, xstrdup (caname));
  struct directory *ret = hash_delete (directory_table, dir);
  if (ret)
    free_directory (ret);
  free_directory (dir);
}
예제 #27
0
void hna_local_free(struct bat_priv *bat_priv)
{
	if (!bat_priv->hna_local_hash)
		return;

	cancel_delayed_work_sync(&bat_priv->hna_work);
	hash_delete(bat_priv->hna_local_hash, _hna_local_del, bat_priv);
	bat_priv->hna_local_hash = NULL;
}
예제 #28
0
파일: event.c 프로젝트: billpage/open-axiom
static void
kill_page(HyperDocPage * page)
{
    page->scroll_off = 0;
    if (page->type == SpadGen) {
        hash_delete(gWindow->fPageHashTable, page->name);
        killAxiomPage(page);
        free_page(page);
    }
}
예제 #29
0
void
frame_remove_by_upage (void *upage)
{
  struct frame *f = frame_find_upage (upage);
  if (f != NULL)
    {
      hash_delete (&frame_table, &f->hash_elem);
      free (f);
    }
}
 inline bool remove(char *name, uint namelen)
 {
   sp_head *sp= lookup(name, namelen);
   if (sp)
   {
     hash_delete(&m_hashtable, (uchar *)sp);
     return TRUE;
   }
   return FALSE;
 }