Changeset 82cbf8c6 in mainline for kernel/generic/include
- Timestamp:
- 2017-10-08T19:37:24Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2fd26bb
- Parents:
- 81b9d3e
- Location:
- kernel/generic/include
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/hash.h
r81b9d3e r82cbf8c6 45 45 * Public domain. 46 46 */ 47 hash = ~hash + (hash << 15); 47 hash = ~hash + (hash << 15); 48 48 hash = hash ^ (hash >> 12); 49 49 hash = hash + (hash << 2); 50 50 hash = hash ^ (hash >> 4); 51 hash = hash * 2057; 51 hash = hash * 2057; 52 52 hash = hash ^ (hash >> 16); 53 return hash; 53 return hash; 54 54 } 55 55 … … 65 65 hash = hash ^ (hash >> 4); 66 66 hash = hash * 0x27d4eb2d; 67 hash = hash ^ (hash >> 15); 68 /* 67 hash = hash ^ (hash >> 15); 68 /* 69 69 * Lower order bits are mixed more thoroughly. Swap them with 70 70 * the higher order bits and make the resulting higher order bits … … 105 105 * http://burtleburtle.net/bob/c/lookup3.c 106 106 */ 107 seed ^= hash + 0x9e3779b9 107 seed ^= hash + 0x9e3779b9 108 108 + ((seed << 5) | (seed >> (sizeof(size_t) * 8 - 5))); 109 return seed; 109 return seed; 110 110 } 111 111 -
kernel/generic/include/adt/hash_table.h
r81b9d3e r82cbf8c6 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2012 Adam Hraska 4 * 3 5 * All rights reserved. 4 6 * … … 27 29 */ 28 30 29 /** @addtogroup genericadt31 /** @addtogroup libc 30 32 * @{ 31 33 */ … … 33 35 */ 34 36 35 #ifndef KERN_HASH_TABLE_H_36 #define KERN_HASH_TABLE_H_37 #ifndef LIBC_HASH_TABLE_H_ 38 #define LIBC_HASH_TABLE_H_ 37 39 38 40 #include <adt/list.h> 39 #include <typedefs.h> 41 #include <stdbool.h> 42 #include <macros.h> 43 44 /** Opaque hash table link type. */ 45 typedef struct ht_link { 46 link_t link; 47 } ht_link_t; 40 48 41 49 /** Set of operations for hash table. */ 42 50 typedef struct { 43 /** Hash function. 44 * 45 * @param key Array of keys needed to compute hash index. All keys must 46 * be passed. 47 * 48 * @return Index into hash table. 49 */ 50 size_t (* hash)(sysarg_t key[]); 51 /** Returns the hash of the key stored in the item (ie its lookup key). */ 52 size_t (*hash)(const ht_link_t *item); 51 53 52 /** Hash table item comparison function.53 *54 * @param key Array of keys that will be compared with item. It is not55 * necessary to pass all keys.56 *57 * @return true if the keys match, false otherwise. 58 */59 bool (* compare)(sysarg_t key[], size_t keys,link_t *item);54 /** Returns the hash of the key. */ 55 size_t (*key_hash)(void *key); 56 57 /** True if the items are equal (have the same lookup keys). */ 58 bool (*equal)(const ht_link_t *item1, const ht_link_t *item2); 59 60 /** Returns true if the key is equal to the item's lookup key. */ 61 bool (*key_equal)(void *key, const ht_link_t *item); 60 62 61 63 /** Hash table item removal callback. 64 * 65 * Must not invoke any mutating functions of the hash table. 62 66 * 63 67 * @param item Item that was removed from the hash table. 64 68 */ 65 void (*remove_callback)( link_t *item);66 } hash_table_op erations_t;69 void (*remove_callback)(ht_link_t *item); 70 } hash_table_ops_t; 67 71 68 72 /** Hash table structure. */ 69 73 typedef struct { 70 list_t *entry; 71 size_t entries; 72 size_t max_keys; 73 hash_table_operations_t *op; 74 hash_table_ops_t *op; 75 list_t *bucket; 76 size_t bucket_cnt; 77 size_t full_item_cnt; 78 size_t item_cnt; 79 size_t max_load; 80 bool apply_ongoing; 74 81 } hash_table_t; 75 82 76 #define hash_table_get_inst ance(item, type, member) \77 list_get_instance((item), type, member)83 #define hash_table_get_inst(item, type, member) \ 84 member_to_inst((item), type, member) 78 85 79 extern void hash_table_create(hash_table_t *h, size_t m, size_t max_keys, 80 hash_table_operations_t *op); 81 extern void hash_table_insert(hash_table_t *h, sysarg_t key[], link_t *item); 82 extern link_t *hash_table_find(hash_table_t *h, sysarg_t key[]); 83 extern void hash_table_remove(hash_table_t *h, sysarg_t key[], size_t keys); 84 extern void hash_table_remove_item(hash_table_t *h, link_t *item); 86 extern bool hash_table_create(hash_table_t *, size_t, size_t, 87 hash_table_ops_t *); 88 extern void hash_table_destroy(hash_table_t *); 89 90 extern bool hash_table_empty(hash_table_t *); 91 extern size_t hash_table_size(hash_table_t *); 92 93 extern void hash_table_clear(hash_table_t *); 94 extern void hash_table_insert(hash_table_t *, ht_link_t *); 95 extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *); 96 extern ht_link_t *hash_table_find(const hash_table_t *, void *); 97 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *); 98 extern size_t hash_table_remove(hash_table_t *, void *); 99 extern void hash_table_remove_item(hash_table_t *, ht_link_t *); 100 extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 101 void *); 102 85 103 86 104 #endif -
kernel/generic/include/ddi/irq.h
r81b9d3e r82cbf8c6 102 102 typedef struct irq { 103 103 /** Hash table link. */ 104 link_t link;104 ht_link_t link; 105 105 106 106 /** Lock protecting everything in this structure -
kernel/generic/include/lib/ra.h
r81b9d3e r82cbf8c6 71 71 typedef struct { 72 72 link_t segment_link; /**< Span's segment list link. */ 73 link_t fu_link; /**< Span's free list or used hash link. */ 73 74 /* 75 * A segment cannot be both on the free list and in the used hash. 76 * Their respective links can therefore occupy the same space. 77 */ 78 union { 79 link_t fl_link; /**< Span's free list link. */ 80 ht_link_t uh_link; /**< Span's used hash link. */ 81 }; 74 82 75 83 uintptr_t base; /**< Segment base. */ -
kernel/generic/include/synch/futex.h
r81b9d3e r82cbf8c6 38 38 #include <typedefs.h> 39 39 #include <synch/waitq.h> 40 #include <adt/hash_table.h> 40 41 41 42 /** Kernel-side futex structure. */ … … 46 47 waitq_t wq; 47 48 /** Futex hash table link. */ 48 link_t ht_link;49 ht_link_t ht_link; 49 50 /** Number of tasks that reference this futex. */ 50 51 size_t refcount;
Note:
See TracChangeset
for help on using the changeset viewer.