2 * Copyright (c) 2009, 2011, ETH Zurich.
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
14 #include <barrelfish/barrelfish.h>
15 #include <collections/hash_table.h>
20 #define HASH_INDEX_BUCKETS 6151
21 static collections_hash_table* ps_table = NULL;
23 static struct ps_entry *entries[MAX_DOMAINS];
25 errval_t ps_allocate(struct ps_entry *entry, domainid_t *domainid)
27 for(domainid_t i = 1; i < MAX_DOMAINS; i++) {
28 if(entries[i] == NULL) {
36 return SPAWN_ERR_DOMAIN_ALLOCATE;
39 void ps_remove(domainid_t domain_id)
41 assert(domain_id < MAX_DOMAINS);
42 entries[domain_id] = NULL;
45 bool ps_exists(domainid_t domain_id)
47 assert(domain_id < MAX_DOMAINS);
48 return entries[domain_id] != NULL ? true : false;
51 struct ps_entry *ps_get(domainid_t domain_id)
53 if(domain_id >= MAX_DOMAINS) {
57 return entries[domain_id];
60 errval_t ps_hash_domain(struct ps_entry *entry, struct capref domain_cap)
62 entry->domain_cap = domain_cap;
64 if (ps_table == NULL) {
65 collections_hash_create_with_buckets(&ps_table, HASH_INDEX_BUCKETS,
67 if (ps_table == NULL) {
68 return SPAWN_ERR_CREATE_DOMAIN_TABLE;
73 errval_t err = domain_cap_hash(entry->domain_cap, &key);
74 if (err_is_fail(err)) {
78 collections_hash_insert(ps_table, key, entry);
83 errval_t ps_get_domain(struct capref domain_cap, struct ps_entry **ret_entry,
84 uint64_t *ret_hash_key)
86 assert(ret_entry != NULL);
89 errval_t err = domain_cap_hash(domain_cap, &key);
90 if (err_is_fail(err)) {
94 void *table_entry = collections_hash_find(ps_table, key);
95 if (table_entry == NULL) {
96 return SPAWN_ERR_DOMAIN_TABLE_FIND;
98 *ret_entry = (struct ps_entry*) table_entry;
100 if (ret_hash_key != NULL) {
107 errval_t ps_release_domain(struct capref domain_cap,
108 struct ps_entry **ret_entry)
110 assert(ret_entry != NULL);
113 errval_t err = ps_get_domain(domain_cap, ret_entry, &key);
114 if (err_is_fail(err)) {
118 collections_hash_delete(ps_table, key);